From patchwork Thu Jan 28 23:16:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 60769 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp778792lbb; Thu, 28 Jan 2016 15:17:13 -0800 (PST) X-Received: by 10.67.6.168 with SMTP id cv8mr8615132pad.47.1454023033725; Thu, 28 Jan 2016 15:17:13 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id t13si19710311pas.21.2016.01.28.15.17.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jan 2016 15:17:13 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-420336-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-return-420336-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-420336-patch=linaro.org@gcc.gnu.org; dkim=pass header.i=@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=TXfHBf9+dv6lWEHdrAwDBBTGqdBZdA/aP71ELGjmkmAR87 //PyEcX7BIIK72TSub877T7gYkM/H9cUJytJKiajGjCflN6jVcVSiMSkzMF6PUM9 qcAFq9AoPfWAsXD4enWYN5b7+lJu+I3Y8btvfyNm92evhZIwb7JG8//RCMUfQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=xm50UIEtKMCuJFkpQho/xa/Uh7g=; b=wojmYPvJCNl2clm6P83o xMpyHuC0sLTe1q8WL/IUXgUx5vLKaMResZV9bmN17GplO3I54zQ+K59IMvs4k0M9 DFvRhyDrhJyy9Rlu2hx3ToxjXnReujiQUrjndJDbfjkrboAKARu05RXbZIVb7C26 Sb0wYaU24mCWhz0wLjo9XmM= Received: (qmail 6966 invoked by alias); 28 Jan 2016 23:17:00 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 6384 invoked by uid 89); 28 Jan 2016 23:16:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=sk:static, peek X-HELO: mail-ig0-f172.google.com Received: from mail-ig0-f172.google.com (HELO mail-ig0-f172.google.com) (209.85.213.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 28 Jan 2016 23:16:58 +0000 Received: by mail-ig0-f172.google.com with SMTP id ik10so24910888igb.1 for ; Thu, 28 Jan 2016 15:16:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=TrH+rsoaIN2n4r9NX3B0qdBkOquvfQP7vf4/yZCUV2g=; b=V62jmSXBU6HVEYD0pIIX1h/corLbBA8E6XwLx8QP8a48um6+/W7h4aFukqelELfNlI Lo8e7Yc8rKMwbRhcfWp9aokSq6IapdFp+6N+xS1gLZUd1+sZfnSPPgJBRP2tBaZwZ2Q0 QMq+1v2ceKBzTVAQoOs05nId2UCwsegSzJ5XMcIGiyHva1bm1Tqu9UCJ0M8a+PZU2YEf +67yoWzBS07CiiuJS3nYmmz81BKsryLzxFVTihCrkCFlJwPhXoPg0bqzzC3N6vIq+LtS 6tjbHPJOH1WEQnJ+4b5WV1AYpY1xiYV7ezixjdISvPgyvURWckUovAdtAav0WKTT7LRf BiVg== X-Gm-Message-State: AG10YOSRkuzQxwAqHf9pOyaKW99+3kVb5aRloNzTaQ6oHHV9e2vrICOjtnKfC6PbYUAC8nWiaM5/iurVEMZTvpbh MIME-Version: 1.0 X-Received: by 10.50.102.101 with SMTP id fn5mr6354537igb.62.1454023016260; Thu, 28 Jan 2016 15:16:56 -0800 (PST) Received: by 10.36.199.66 with HTTP; Thu, 28 Jan 2016 15:16:56 -0800 (PST) Date: Fri, 29 Jan 2016 04:46:56 +0530 Message-ID: Subject: [C++ patch] report better diagnostic for static following '[' in parameter declaration From: Prathamesh Kulkarni To: gcc Patches X-IsSubscribed: yes Hi, For the test-case, void f(int a[static 10]); g++ gives following errors: test-foo.cpp:1:14: error: expected primary-expression before ‘static’ void f(int a[static 10]); ^ test-foo.cpp:1:14: error: expected ‘]’ before ‘static’ test-foo.cpp:1:14: error: expected ‘)’ before ‘static’ test-foo.cpp:1:14: error: expected initializer before ‘static’ and clang++ gives: test-foo.cpp:1:13: error: static array size is a C99 feature, not permitted in C++ void f(int a[static 10]); ^ I have attached patch that attempts to report the same diagnostic. With patch, g++ reports: test-foo.cpp:1:14: error: static array size is a C99 feature,not permitted in C++ void f(int a[static 10]) ^~~~~~ test-foo.cpp:1:14: error: expected ‘]’ before ‘static’ test-foo.cpp:1:14: error: expected ‘)’ before ‘static’ test-foo.cpp:1:14: error: expected initializer before ‘static’ I tried to remove the 3 errors that follow it (expected X before static) but without luck :/ Bootstrap and tested on x86_64-unknown-linux-gnu. OK for trunk ? Thanks, Prathamesh diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index d03b0c9..4d3e38a 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -19016,10 +19017,22 @@ cp_parser_direct_declarator (cp_parser* parser, cp_lexer_consume_token (parser->lexer); /* Peek at the next token. */ token = cp_lexer_peek_token (parser->lexer); + + /* If static keyword immediately follows [, report error. */ + if (cp_lexer_next_token_is_keyword (parser->lexer, RID_STATIC) + && current_binding_level->kind == sk_function_parms) + { + error_at (token->location, + "static array size is a C99 feature," + "not permitted in C++"); + bounds = error_mark_node; + } + /* If the next token is `]', then there is no constant-expression. */ - if (token->type != CPP_CLOSE_SQUARE) + else if (token->type != CPP_CLOSE_SQUARE) { + bool non_constant_p; bounds = cp_parser_constant_expression (parser, diff --git a/gcc/testsuite/g++.dg/parse/static-array-error.C b/gcc/testsuite/g++.dg/parse/static-array-error.C new file mode 100644 index 0000000..8b58588 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/static-array-error.C @@ -0,0 +1,6 @@ +// { dg-do compile } + +void f(int a[static 10]); /* { dg-error "static array size is a C99 feature" } */ +/* { dg-error "expected ']' before 'static'" "" { target *-*-* } 3 } */ +/* { dg-error "expected ')' before 'static'" "" { target *-*-* } 3 } */ +/* { dg-error "expected initializer before 'static'" "" { target *-*-* } 3 } */