PR c++/84559 - ICE with constexpr VLA.
authorJason Merrill <jason@redhat.com>
Mon, 26 Feb 2018 21:55:41 +0000 (16:55 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 26 Feb 2018 21:55:41 +0000 (16:55 -0500)
* constexpr.c (ensure_literal_type_for_constexpr_object): Check
for constexpr variable with VLA type.

From-SVN: r258015

gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/testsuite/g++.dg/ext/constexpr-vla5.C [new file with mode: 0644]

index 14f899c1881b8ed7b325df9702c374becd0c69a8..3a2a17d57204d52702b364ec41d9eba36121ab33 100644 (file)
@@ -1,3 +1,9 @@
+2018-02-26  Jason Merrill  <jason@redhat.com>
+
+       PR c++/84559 - ICE with constexpr VLA.
+       * constexpr.c (ensure_literal_type_for_constexpr_object): Check
+       for constexpr variable with VLA type.
+
 2018-02-26  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/84558
index b3de62a5beaaeeb4059868214c1659620a4593b0..4bbdbf43487794d82fd77d98c69968798df36a8a 100644 (file)
@@ -112,6 +112,13 @@ ensure_literal_type_for_constexpr_object (tree decl)
              cp_function_chain->invalid_constexpr = true;
            }
        }
+      else if (DECL_DECLARED_CONSTEXPR_P (decl)
+              && variably_modified_type_p (type, NULL_TREE))
+       {
+         error ("%<constexpr%> variable %qD has variably-modified type %qT",
+                decl, type);
+         decl = error_mark_node;
+       }
     }
   return decl;
 }
diff --git a/gcc/testsuite/g++.dg/ext/constexpr-vla5.C b/gcc/testsuite/g++.dg/ext/constexpr-vla5.C
new file mode 100644 (file)
index 0000000..565d40a
--- /dev/null
@@ -0,0 +1,7 @@
+// PR c++/84559
+// { dg-do compile { target c++11 } }
+
+void foo(int i)
+{
+  constexpr char x[i] = "";    // { dg-error "" }
+}