diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index c6da5e29a34a37a72eae8e6308aaeb3170668683..6d590239f4eae33b5228fcbab51207631f5543bf 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 715b9461aba4bf8d4e79e032522cfe833639938d..aea943ed0c18f4b7643581f0702b81951d9beb6c 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -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
index 0000000000000000000000000000000000000000..7ef9aa12b2b33d4efb64909468bd29c1017e239b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/pr28284.C
@@ -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;