From d54faccc041ce5841206b5ec1ac835196f203a75 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Wed, 30 Oct 2019 18:49:59 +0000 Subject: [PATCH] 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 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/decl2.c | 3 +++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp2a/constinit14.C | 13 +++++++++++++ 4 files changed, 26 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp2a/constinit14.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 55c3f0babe7..3a5e4a5e3e7 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2019-10-30 Marek Polacek + + PR c++/92134 - constinit malfunction in static data member. + * decl2.c (grokfield): Set LOOKUP_CONSTINIT. + 2019-10-30 Jakub Jelinek * cp-tree.h (omp_declare_variant_finalize, build_local_temp): Declare. diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index cff11baef46..b9f3b87b60b 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 889e33bbc65..ec613497bbc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-10-30 Marek Polacek + + PR c++/92134 - constinit malfunction in static data member. + * g++.dg/cpp2a/constinit14.C: New test. + 2019-10-30 Jozef Lawrynowicz * 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 00000000000..72bfab667b8 --- /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; } -- 2.30.2