re PR c++/28284 (ICE with invalid static const variable)
authorSimon Martin <simartin@users.sourceforge.net>
Thu, 7 Sep 2006 17:25:05 +0000 (17:25 +0000)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 7 Sep 2006 17:25:05 +0000 (13:25 -0400)
        PR c++/28284
        * pt.c (fold_non_dependent_expr): Make sure expr is not dereferenced if it
        is NULL.

From-SVN: r116755

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.dg/template/pr28284.C [new file with mode: 0644]

index c6da5e2..6d59023 100644 (file)
@@ -1,3 +1,9 @@
+2006-09-07  Simon Martin  <simartin@users.sourceforge.net>
+
+       PR c++/28284
+       * pt.c (fold_non_dependent_expr): Make sure expr is not dereferenced if it
+       is NULL.
+
 2006-09-06  Zak Kipling  <zak@transversal.com>
 
         PR c++/26195
index 715b946..aea943e 100644 (file)
@@ -3410,6 +3410,9 @@ redeclare_class_template (tree type, tree parms)
 tree
 fold_non_dependent_expr (tree expr)
 {
+  if (expr == NULL_TREE)
+    return NULL_TREE;
+
   /* If we're in a template, but EXPR isn't value dependent, simplify
      it.  We're supposed to treat:
 
diff --git a/gcc/testsuite/g++.dg/template/pr28284.C b/gcc/testsuite/g++.dg/template/pr28284.C
new file mode 100644 (file)
index 0000000..7ef9aa1
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+
+template<int> struct A
+{
+  static const int i=x; /* { dg-error "was not declared in this scope" } */
+  static const int j, k;
+};
+
+template<int N> const int A<N>::j = i;
+template<int N> const int A<N>::k = j;
+
+A<0> a;