c: C2x storage class specifiers in compound literals
authorJoseph Myers <joseph@codesourcery.com>
Fri, 14 Oct 2022 02:18:45 +0000 (02:18 +0000)
committerJoseph Myers <joseph@codesourcery.com>
Fri, 14 Oct 2022 02:18:45 +0000 (02:18 +0000)
commit18981635127c6701733dc052aa054e569271b733
treeb4195c597f07b1ad29a276cfdc7edaa60fb21972
parent621a911d336279d21e1e857cfead09af1c61df39
c: C2x storage class specifiers in compound literals

Implement the C2x feature of storage class specifiers in compound
literals.  Such storage class specifiers (static, register or
thread_local; also constexpr, but we don't yet have C2x constexpr
support implemented) can be used before the type name (not mixed with
type specifiers, unlike in declarations) and have the same semantics
and constraints as for declarations of named objects.  Also allow GNU
__thread to be used, given that thread_local can be.

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

gcc/c/
* c-decl.cc (build_compound_literal): Add parameter scspecs.
Handle storage class specifiers.
* c-parser.cc (c_token_starts_compound_literal)
(c_parser_compound_literal_scspecs): New.
(c_parser_postfix_expression_after_paren_type): Add parameter
scspecs.  Call pedwarn_c11 for use of storage class specifiers.
Update call to build_compound_literal.
(c_parser_cast_expression, c_parser_sizeof_expression)
(c_parser_alignof_expression): Handle storage class specifiers for
compound literals.  Update calls to
c_parser_postfix_expression_after_paren_type.
(c_parser_postfix_expression): Update syntax comment.
* c-tree.h (build_compound_literal): Update prototype.
* c-typeck.cc (c_mark_addressable): Diagnose taking address of
register compound literal.

gcc/testsuite/
* gcc.dg/c11-complit-1.c, gcc.dg/c11-complit-2.c,
gcc.dg/c11-complit-3.c, gcc.dg/c2x-complit-2.c,
gcc.dg/c2x-complit-3.c, gcc.dg/c2x-complit-4.c,
gcc.dg/c2x-complit-5.c, gcc.dg/c2x-complit-6.c,
gcc.dg/c2x-complit-7.c, gcc.dg/c90-complit-2.c,
gcc.dg/gnu2x-complit-1.c, gcc.dg/gnu2x-complit-2.c: New tests.
16 files changed:
gcc/c/c-decl.cc
gcc/c/c-parser.cc
gcc/c/c-tree.h
gcc/c/c-typeck.cc
gcc/testsuite/gcc.dg/c11-complit-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c11-complit-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c11-complit-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c2x-complit-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c2x-complit-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c2x-complit-4.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c2x-complit-5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c2x-complit-6.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c2x-complit-7.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c90-complit-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/gnu2x-complit-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/gnu2x-complit-2.c [new file with mode: 0644]