Allow _Alignas in compound literals (C11 DR#444).
C11 DR#444 dealt with how C11 intended to allow alignment specifiers on struct and union members, but failed to include that in the syntax. The final resolution of that DR also allows alignment specifiers in type names in compound literals (in order to apply an increased alignment to the unnamed object created by the compound literal), but not other cases of type names. This patch implements allowing alignment specifiers in compound literals and adds tests for the resolution of the DR (including that they are allowed on struct and union members, which GCC already implemented). Because the parser has to parse the parenthesized type name of a compound literal before it can tell that it's a compound literal (rather than, depending on the context, a cast expression or sizeof (type-name) or _Alignof (type-name)), this means _Alignas specifiers are allowed syntactically in those contexts and then an error is given once it's known to be an invalid use (whereas _Alignas specifiers are disallowed syntactically in other contexts where type names can occur and a compound literal is not possible). Bootstrapped with no regressions on x86_64-pc-linux-gnu. gcc/c: * c-decl.c (build_compound_literal): Add parameter alignas_align and set alignment of decl if nonzero. * c-parser.c (c_keyword_starts_typename): Allow RID_ALIGNAS. (c_parser_declspecs): Allow RID_ALIGNAS to follow a type, like a qualifier. (c_parser_struct_declaration): Update syntax comment. (c_parser_type_name): Add alignas_ok argument and pass it to c_parser_declspecs. (c_parser_cast_expression): Pass true to c_parser_type_name and give error if a cast used an _Alignas specifier. (c_parser_sizeof_expression): Pass true to c_parser_type_name and give error if sizeof (type-name) used an _Alignas specifier. (c_parser_alignof_expression): Pass true to c_parser_type_name and give error if _Alignof (type-name) used an _Alignas specifier. (c_parser_postfix_expression_after_paren_type): Check specified alignment for a compound literal and pass it to build_compound_literal. * c-parser.h (c_parser_type_name): Update prototype. * c-tree.h (build_compound_literal): Update prototype. gcc/testsuite: * gcc.dg/c11-align-7.c, gcc.dg/c11-align-8.c, gcc.dg/c11-align-9.c, gcc.dg/gnu11-align-1.c: New tests. * gcc.dg/c11-align-5.c (test): Update expected error for sizeof case. From-SVN: r255482
Showing
gcc/testsuite/gcc.dg/c11-align-7.c
0 → 100644
gcc/testsuite/gcc.dg/c11-align-8.c
0 → 100644
gcc/testsuite/gcc.dg/c11-align-9.c
0 → 100644
gcc/testsuite/gcc.dg/gnu11-align-1.c
0 → 100644
Please
register
or
sign in
to comment