PR c++/92134 - constinit malfunction in static data member.
authorMarek Polacek <polacek@redhat.com>
Wed, 30 Oct 2019 18:49:59 +0000 (18:49 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Wed, 30 Oct 2019 18:49:59 +0000 (18:49 +0000)
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
gcc/cp/decl2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp2a/constinit14.C [new file with mode: 0644]

index 55c3f0babe7709b54f7000a564ed8ca3fc53548a..3a5e4a5e3e775e981a0e3d1faf9febad0c16b84f 100644 (file)
@@ -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.
index cff11baef4690b8552666861b5659f32951794a2..b9f3b87b60b9281f17769c134c35b62fcef52c37 100644 (file)
@@ -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:
index 889e33bbc65415e13c164d212ef23b23afd8dd43..ec613497bbce18eeb813b1eb52faffb9e9bd755d 100644 (file)
@@ -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 (file)
index 0000000..72bfab6
--- /dev/null
@@ -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; }