PR c++/91353 - P1331R2: Allow trivial default init in constexpr contexts.
authorMarek Polacek <polacek@redhat.com>
Thu, 5 Dec 2019 20:13:03 +0000 (20:13 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Thu, 5 Dec 2019 20:13:03 +0000 (20:13 +0000)
commit7906797ebec6881d7d90165340f51efcf447d716
treeed7a31a3d6aa39957a07685ac63429cd13bede4a
parent5c04da88731961636d08c0fd06f2aa291410d5b9
PR c++/91353 - P1331R2: Allow trivial default init in constexpr contexts.

This patch implements C++20 P1331, allowing trivial default initialization in
constexpr contexts.

* c-cppbuiltin.c (c_cpp_builtins): Adjust the value of __cpp_constexpr.

* class.c (trivial_default_constructor_is_constexpr): Return true in
C++20.
* constexpr.c (cx_check_missing_mem_inits): Allow missing field
initializers in C++20.
(cxx_eval_call_expression): Don't clear CONSTRUCTOR_NO_CLEARING for
constexpr constructors in C++20.
(reduced_constant_expression_p): Don't set FIELD for union and array
types.  Skip empty class fields without initializers.
* decl.c (check_for_uninitialized_const_var): Permit trivial default
initialization in constexpr.
(next_initializable_field): Don't skip vptr fields.
* method.c (walk_field_subobs): Still consider a constructor that
doesn't initialize all the members constexpr.

* g++.dg/cpp0x/constexpr-array6.C: Adjust dg-error.
* g++.dg/cpp0x/constexpr-ctor.C: Likewise.
* g++.dg/cpp0x/constexpr-diag3.C: Likewise.
* g++.dg/cpp0x/constexpr-diag4.C: Likewise.
* g++.dg/cpp0x/constexpr-ex3.C: Likewise.
* g++.dg/cpp0x/constexpr-template2.C: Likewise.
* g++.dg/cpp0x/constexpr-union2.C: Likewise.
* g++.dg/cpp0x/lambda/lambda-mangle.C: Rip out a piece of code ...
* g++.dg/cpp0x/lambda/lambda-mangle6.C: ... and put it here.
* g++.dg/cpp0x/pr79118.C: Adjust dg-error.
* g++.dg/cpp1y/constexpr-83921-3.C: Likewise.
* g++.dg/cpp1y/constexpr-neg1.C: Likewise.
* g++.dg/cpp1z/constexpr-lambda12.C: Likewise.
* g++.dg/cpp1z/feat-cxx1z.C: Use -std=c++17.
* g++.dg/cpp2a/constexpr-init1.C: New test.
* g++.dg/cpp2a/constexpr-init2.C: New test.
* g++.dg/cpp2a/constexpr-init3.C: New test.
* g++.dg/cpp2a/constexpr-init4.C: New test.
* g++.dg/cpp2a/constexpr-init5.C: New test.
* g++.dg/cpp2a/constexpr-init6.C: New test.
* g++.dg/cpp2a/constexpr-init7.C: New test.
* g++.dg/cpp2a/constexpr-init8.C: New test.
* g++.dg/cpp2a/constexpr-init9.C: New test.
* g++.dg/cpp2a/constexpr-init10.C: New test.
* g++.dg/cpp2a/constexpr-init11.C: New test.
* g++.dg/cpp2a/constexpr-init12.C: New test.
* g++.dg/cpp2a/constexpr-init13.C: New test.
* g++.dg/cpp2a/constexpr-init14.C: New test.
* g++.dg/cpp2a/constexpr-init15.C: New test.
* g++.dg/cpp2a/constexpr-try5.C: Adjust dg-error.
* g++.dg/cpp2a/feat-cxx2a.C: Test __cpp_constexpr.
* g++.dg/cpp2a/lambda-mangle.C: New test.
* g++.dg/debug/dwarf2/pr44641.C: Skip for c++2a.
* g++.dg/ext/stmtexpr21.C: Adjust dg-error.

Co-Authored-By: Jakub Jelinek <jakub@redhat.com>
From-SVN: r279019
41 files changed:
gcc/c-family/ChangeLog
gcc/c-family/c-cppbuiltin.c
gcc/cp/ChangeLog
gcc/cp/class.c
gcc/cp/constexpr.c
gcc/cp/decl.c
gcc/cp/method.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/constexpr-array6.C
gcc/testsuite/g++.dg/cpp0x/constexpr-ctor.C
gcc/testsuite/g++.dg/cpp0x/constexpr-diag3.C
gcc/testsuite/g++.dg/cpp0x/constexpr-diag4.C
gcc/testsuite/g++.dg/cpp0x/constexpr-ex3.C
gcc/testsuite/g++.dg/cpp0x/constexpr-template2.C
gcc/testsuite/g++.dg/cpp0x/constexpr-union2.C
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mangle.C
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-mangle6.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/pr79118.C
gcc/testsuite/g++.dg/cpp1y/constexpr-83921-3.C
gcc/testsuite/g++.dg/cpp1y/constexpr-neg1.C
gcc/testsuite/g++.dg/cpp1z/constexpr-lambda12.C
gcc/testsuite/g++.dg/cpp2a/constexpr-init1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constexpr-init10.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constexpr-init11.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constexpr-init12.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constexpr-init13.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constexpr-init14.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constexpr-init15.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constexpr-init2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constexpr-init3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constexpr-init4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constexpr-init5.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constexpr-init6.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constexpr-init7.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constexpr-init8.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constexpr-init9.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constexpr-try5.C
gcc/testsuite/g++.dg/cpp2a/feat-cxx2a.C
gcc/testsuite/g++.dg/cpp2a/lambda-mangle.C [new file with mode: 0644]
gcc/testsuite/g++.dg/debug/dwarf2/pr44641.C
gcc/testsuite/g++.dg/ext/stmtexpr21.C