re PR c++/85134 (ICE with invalid constexpr in 'shared' OpenMP clause)
authorJakub Jelinek <jakub@redhat.com>
Tue, 3 Apr 2018 16:20:02 +0000 (18:20 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 3 Apr 2018 16:20:02 +0000 (18:20 +0200)
PR c++/85134
* decl.c (cp_finish_decl): If ensure_literal_type_for_constexpr_object
fails, after clearing DECL_DECLARED_CONSTEXPR_P don't return early,
instead for static data members clear init and set DECL_EXTERNAL.

* g++.dg/gomp/pr85134.C: New test.
* g++.dg/cpp0x/constexpr-ice19.C: Expect one further error.

From-SVN: r259038

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/constexpr-ice19.C
gcc/testsuite/g++.dg/gomp/pr85134.C [new file with mode: 0644]

index e97442a5bea78d422e133c8861a5b031e7455c83..6404a74c36300f47c0cf2fe2b83e81e71230ea9a 100644 (file)
@@ -1,3 +1,10 @@
+2018-04-03  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/85134
+       * decl.c (cp_finish_decl): If ensure_literal_type_for_constexpr_object
+       fails, after clearing DECL_DECLARED_CONSTEXPR_P don't return early,
+       instead for static data members clear init and set DECL_EXTERNAL.
+
 2018-04-02  Jason Merrill  <jason@redhat.com>
 
        PR c++/64095 - auto... parameter pack.
index ba456737e0e72b7c57f0850b0c982d611c24c2aa..6ddbe2343f4870be2fac5aaa88adf05b101c1e38 100644 (file)
@@ -6923,11 +6923,14 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
     }
 
-  if (ensure_literal_type_for_constexpr_object (decl)
-      == error_mark_node)
+  if (ensure_literal_type_for_constexpr_object (decl) == error_mark_node)
     {
       DECL_DECLARED_CONSTEXPR_P (decl) = 0;
-      return;
+      if (VAR_P (decl) && DECL_CLASS_SCOPE_P (decl))
+       {
+         init = NULL_TREE;
+         DECL_EXTERNAL (decl) = 1;
+       }
     }
 
   if (VAR_P (decl)
index a53d46b6bac95e1a10c62631ab39f132db071f60..bcc0714d1070051afb3f3669a09447f500f21287 100644 (file)
@@ -1,5 +1,9 @@
 2018-04-03  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/85134
+       * g++.dg/gomp/pr85134.C: New test.
+       * g++.dg/cpp0x/constexpr-ice19.C: Expect one further error.
+
        PR target/85169
        * gcc.c-torture/execute/pr85169.c: New test.
        * gcc.target/i386/avx512f-pr85169.c: New test.
index 7066eabdfc70384c3d2c63bc54a4b75001b4341e..f62a0d995c2cd54b1ac01a56bd4dc6647e4f6f28 100644 (file)
@@ -9,5 +9,5 @@ struct A
 
 struct B
 {
-  static constexpr A a {};  // { dg-error "not literal" }
+  static constexpr A a {};  // { dg-error "not literal|in-class initialization" }
 };
diff --git a/gcc/testsuite/g++.dg/gomp/pr85134.C b/gcc/testsuite/g++.dg/gomp/pr85134.C
new file mode 100644 (file)
index 0000000..9872ae5
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/85134
+// { dg-do compile }
+// { dg-options "-std=c++14 -fopenmp" }
+
+void
+foo (int i)
+{
+  constexpr int x[i] = {};     // { dg-error "'constexpr' variable 'x' has variably-modified type" }
+#pragma omp parallel shared(x)
+  ;
+}