Fix PR c++/70204 (ICE in non_const_var_error)
authorPatrick Palka <ppalka@gcc.gnu.org>
Tue, 22 Mar 2016 00:30:57 +0000 (00:30 +0000)
committerPatrick Palka <ppalka@gcc.gnu.org>
Tue, 22 Mar 2016 00:30:57 +0000 (00:30 +0000)
gcc/cp/ChangeLog:

PR c++/70204
* constexpr.c (non_const_var_error): Check
DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P.

gcc/testsuite/ChangeLog:

PR c++/70204
* g++.dg/cpp0x/constexpr-70204a.C: New test.
* g++.dg/cpp0x/constexpr-70204b.C: New test.

From-SVN: r234390

gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/constexpr-70204a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/constexpr-70204b.C [new file with mode: 0644]

index c8919f9437ed4466869535fef6629ec82b4cf406..578fc6fba358909516ec3262f04f1cfa78170437 100644 (file)
@@ -1,3 +1,9 @@
+2016-03-22  Patrick Palka  <ppalka@gcc.gnu.org>
+
+       PR c++/70204
+       * constexpr.c (non_const_var_error): Check
+       DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P.
+
 2016-03-21  Richard Henderson  <rth@redhat.com>
 
        PR c++/70273
index 1f496b5f9bd67b0e6989fca0b924ab8a4dd317d1..7b136330b3f2ed923f668f3c95b09db6f50f5258 100644 (file)
@@ -2763,7 +2763,8 @@ non_const_var_error (tree r)
        inform (DECL_SOURCE_LOCATION (r),
                "%q#D is volatile", r);
       else if (!DECL_INITIAL (r)
-              || !TREE_CONSTANT (DECL_INITIAL (r)))
+              || !TREE_CONSTANT (DECL_INITIAL (r))
+              || !DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (r))
        inform (DECL_SOURCE_LOCATION (r),
                "%qD was not initialized with a constant "
                "expression", r);
index e05b897a9b82bf782c7eb0b1e5b7678560e1168a..69c97a7fa360accee15b7da29ac8f7def1999953 100644 (file)
@@ -1,3 +1,9 @@
+2016-03-22  Patrick Palka  <ppalka@gcc.gnu.org>
+
+       PR c++/70204
+       * g++.dg/cpp0x/constexpr-70204a.C: New test.
+       * g++.dg/cpp0x/constexpr-70204b.C: New test.
+
 2016-03-21  Jakub Jelinek  <jakub@redhat.com>
 
        PR middle-end/70326
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-70204a.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-70204a.C
new file mode 100644 (file)
index 0000000..5ac5519
--- /dev/null
@@ -0,0 +1,18 @@
+// PR c++/70204
+// { dg-do compile { target c++11 } }
+
+int a;
+
+template < int N, int I >
+void fn1 ()
+{
+  const int x = I * a, y = x;
+  fn1 < y, I > (); // { dg-error "constant|no match" }
+}
+
+int
+main ()
+{
+  fn1 < 0, 0 > ();
+  return 0;
+}
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-70204b.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-70204b.C
new file mode 100644 (file)
index 0000000..2b07d4f
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/70204
+// { dg-do compile { target c++11 } }
+
+int a;
+
+void fn1 ()
+{
+  const int x = 0 * a;
+  constexpr int y = x; // { dg-error "constant" }
+}