This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C PATCH] Warn for _Alignas in an array declarator (PR c/58267)
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Marek Polacek <polacek at redhat dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 16 Oct 2013 12:28:32 +0000
- Subject: Re: [C PATCH] Warn for _Alignas in an array declarator (PR c/58267)
- Authentication-results: sourceware.org; auth=none
- References: <20131016113405 dot GC10967 at redhat dot com>
On Wed, 16 Oct 2013, Marek Polacek wrote:
> This PR is about _Alignas in contexts like
> char x[_Alignas (int) 20];
> C grammar does not allow _Alignas to be in an array declarator, yet we
> don't issue any warning or an error. This patch implements a pedwarn
> for this. I'm however highly unsure whether we want pedwarn, error, or
> normal warning for this - currently we just DTRT and ignore the
> _Alignas altogether.
I think this should be an error.
I see this as a problem with how the parsing of array declarators uses
c_parser_declspecs to parse a sequence of qualifiers and attributes, with
scspec_ok=false and typespec_ok=false to ensure those kinds of specifiers
can't occur in the list, but without any measure to exclude alignment
specifiers. That is, I think c_parser_declspecs should gain an argument
specifying whether alignment specifiers are OK, and the relevant calls
from c_parser_direct_declarator_inner would pass false for that argument,
and uses of alignment specifiers here would result in parse errors.
(Incidentally, the comments in c-parser.c that are supposed to give the
grammar accepted are missing the syntax of array-declarator.)
> --- gcc/testsuite/gcc.dg/c1x-align-5.c.mp 2013-10-16 11:11:16.432690963 +0200
> +++ gcc/testsuite/gcc.dg/c1x-align-5.c 2013-10-16 11:15:09.269514593 +0200
> @@ -0,0 +1,17 @@
> +/* Test C1X alignment support. Test invalid code. */
> +/* { dg-do compile } */
> +/* { dg-options "-std=c1x -pedantic-errors" } */
> +
> +static int
> +foo (int a[_Alignas (0) 10]) /* { dg-error "meaningless in array declarator" } */
> +{
> + return a[0];
> +}
> +
> +int
> +main ()
> +{
> + int a[_Alignas (int) 10]; /* { dg-error "meaningless in array declarator" } */
> + foo (a);
> + return 0;
> +}
I think this should also be tested after "static" (given that there are
two separate calls to c_parser_declspecs involved), as well as in an
abstract declarator.
--
Joseph S. Myers
joseph@codesourcery.com