PR c++/91360 - Implement C++20 P1143R2: constinit.
authorMarek Polacek <polacek@redhat.com>
Wed, 28 Aug 2019 20:31:31 +0000 (20:31 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Wed, 28 Aug 2019 20:31:31 +0000 (20:31 +0000)
commit4742dbe71804b3db099eb0eb8620dff2c79a71cf
tree7af31fa4ebcc89ec48d8f163d2d2f3aeecb4ee11
parent6e12721acde2080202889b3839acca52646b0d28
PR c++/91360 - Implement C++20 P1143R2: constinit.

* c-common.c (c_common_reswords): Add constinit and __constinit.
(keyword_is_decl_specifier): Handle RID_CONSTINIT.
* c-common.h (enum rid): Add RID_CONSTINIT, RID_FIRST_CXX20, and
RID_LAST_CXX20.
(D_CXX20): Define.
* c-cppbuiltin.c (c_cpp_builtins): Define __cpp_constinit.
* c-format.c (cxx_keywords): Add "constinit".
* c.opt (Wc++2a-compat, Wc++20-compat): New options.

* cp-tree.h (TINFO_VAR_DECLARED_CONSTINIT): Define.
(LOOKUP_CONSTINIT): Define.
(enum cp_decl_spec): Add ds_constinit.
* decl.c (check_tag_decl): Give an error for constinit in type
declarations.
(check_initializer): Also check LOOKUP_CONSTINIT.
(cp_finish_decl): Add checking for a constinit declaration.  Set
TINFO_VAR_DECLARED_CONSTINIT.
(grokdeclarator): Add checking for a declaration with the constinit
specifier.
* lex.c (init_reswords): Handle D_CXX20.
* parser.c (cp_lexer_get_preprocessor_token): Pass a better location
to warning_at.  Warn about C++20 keywords.
(cp_keyword_starts_decl_specifier_p): Handle RID_CONSTINIT.
(cp_parser_diagnose_invalid_type_name): Add an inform about constinit.
(cp_parser_decomposition_declaration): Maybe pass LOOKUP_CONSTINIT to
cp_finish_decl.
(cp_parser_decl_specifier_seq): Handle RID_CONSTINIT.
(cp_parser_init_declarator): Maybe pass LOOKUP_CONSTINIT to
cp_finish_decl.
(set_and_check_decl_spec_loc): Add "constinit".
* pt.c (tsubst_decl): Set TINFO_VAR_DECLARED_CONSTINIT.
(instantiate_decl): Maybe pass LOOKUP_CONSTINIT to cp_finish_decl.
* typeck2.c (store_init_value): If a constinit variable wasn't
initialized using a constant initializer, give an error.

* doc/invoke.texi: Document -Wc++20-compat.

* g++.dg/cpp2a/constinit1.C: New test.
* g++.dg/cpp2a/constinit2.C: New test.
* g++.dg/cpp2a/constinit3.C: New test.
* g++.dg/cpp2a/constinit4.C: New test.
* g++.dg/cpp2a/constinit5.C: New test.
* g++.dg/cpp2a/constinit6.C: New test.
* g++.dg/cpp2a/constinit7.C: New test.
* g++.dg/cpp2a/constinit8.C: New test.
* g++.dg/cpp2a/constinit9.C: New test.
* g++.dg/cpp2a/constinit10.C: New test.
* g++.dg/cpp2a/constinit11.C: New test.
* g++.dg/cpp2a/constinit12.C: New test.

From-SVN: r275008
28 files changed:
gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/c-family/c-common.h
gcc/c-family/c-cppbuiltin.c
gcc/c-family/c-format.c
gcc/c-family/c.opt
gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/lex.c
gcc/cp/parser.c
gcc/cp/pt.c
gcc/cp/typeck2.c
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp2a/constinit1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constinit10.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constinit11.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constinit12.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constinit2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constinit3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constinit4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constinit5.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constinit6.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constinit7.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constinit8.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constinit9.C [new file with mode: 0644]