diff options
author | Marek Polacek <polacek@redhat.com> | 2019-10-30 18:49:59 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2019-10-30 18:49:59 +0000 |
commit | d54faccc041ce5841206b5ec1ac835196f203a75 (patch) | |
tree | 9230d1fb68a43e33269aa87b630df9e56de9ee05 | |
parent | ce001b300fc7bd22cbb2712b6d06e5043fe6354f (diff) | |
download | gcc-d54faccc041ce5841206b5ec1ac835196f203a75.zip gcc-d54faccc041ce5841206b5ec1ac835196f203a75.tar.gz gcc-d54faccc041ce5841206b5ec1ac835196f203a75.tar.bz2 |
PR c++/92134 - constinit malfunction in static data member.
I wasn't properly setting LOOKUP_CONSTINIT in grokfield and so we didn't
detect a non-const initializer.
* decl2.c (grokfield): Set LOOKUP_CONSTINIT.
* g++.dg/cpp2a/constinit14.C: New test.
From-SVN: r277636
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/decl2.c | 3 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp2a/constinit14.C | 13 |
4 files changed, 26 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 55c3f0b..3a5e4a5 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2019-10-30 Marek Polacek <polacek@redhat.com> + + PR c++/92134 - constinit malfunction in static data member. + * decl2.c (grokfield): Set LOOKUP_CONSTINIT. + 2019-10-30 Jakub Jelinek <jakub@redhat.com> * cp-tree.h (omp_declare_variant_finalize, build_local_temp): Declare. diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index cff11ba..b9f3b87 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -990,6 +990,9 @@ grokfield (const cp_declarator *declarator, else flags = LOOKUP_IMPLICIT; + if (decl_spec_seq_has_spec_p (declspecs, ds_constinit)) + flags |= LOOKUP_CONSTINIT; + switch (TREE_CODE (value)) { case VAR_DECL: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 889e33b..ec61349 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-10-30 Marek Polacek <polacek@redhat.com> + + PR c++/92134 - constinit malfunction in static data member. + * g++.dg/cpp2a/constinit14.C: New test. + 2019-10-30 Jozef Lawrynowicz <jozef.l@mittosystems.com> * gcc.target/msp430/mlarge-use-430-insn.c: New test. diff --git a/gcc/testsuite/g++.dg/cpp2a/constinit14.C b/gcc/testsuite/g++.dg/cpp2a/constinit14.C new file mode 100644 index 0000000..72bfab6 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/constinit14.C @@ -0,0 +1,13 @@ +// PR c++/92134 - constinit malfunction in static data member. +// { dg-do compile { target c++2a } } + +struct Value { + Value() : v{new int{42}} {} + int* v; +}; + +struct S { + static constinit inline Value v{}; // { dg-error "variable .S::v. does not have a constant initializer|call to non-.constexpr. function" } +}; + +int main() { return *S::v.v; } |