]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Backport:
authorVolker Reichelt <v.reichelt@netcologne.de>
Sat, 27 Jan 2007 19:58:38 +0000 (19:58 +0000)
committerVolker Reichelt <reichelt@gcc.gnu.org>
Sat, 27 Jan 2007 19:58:38 +0000 (19:58 +0000)
2006-11-13  Mark Mitchell  <mark@codesourcery.com>

PR c++/29106
* init.c (constant_value_1): Treat a DECL_INITIAL of
error_mark_node as meaning that the variable is uninitialized,
rather than erroneously initialized.

* g++.dg/init/self1.C: New test.
* g++.dg/other/fold1.C: Adjust error markers.
* g++.dg/init/member1.C: Likewise.

2006-08-27  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.

* g++.dg/template/pr28284.C: New test.

From-SVN: r121238

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

index 22ca0608540ffac1cd16ba82cfca2047c247fd3d..bc75286953987de4270a51d402f0c351d4b2ab04 100644 (file)
@@ -1,3 +1,18 @@
+2007-01-27  Volker Reichelt  <v.reichelt@netcologne.de>
+
+       Backport:
+       2006-11-13  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/29106
+       * g++.dg/init/self1.C: New test.
+       * g++.dg/other/fold1.C: Adjust error markers.
+       * g++.dg/init/member1.C: Likewise.
+
+       2006-08-27  Simon Martin  <simartin@users.sourceforge.net>
+
+       PR c++/28284
+       * g++.dg/template/pr28284.C: New test.
+
 2006-11-18 Lee Millward <lee.millward@codesourcery.com>
 
        PR c++/29022
index a8249e7f452cb92d36e9b7ef60e834a60152bc37..7ce0881183945a3ff11a9431399634525e135250 100644 (file)
@@ -1608,8 +1608,11 @@ constant_value_1 (tree decl, bool integral_p)
          mark_used (decl);
          init = DECL_INITIAL (decl);
        }
+      /* If INIT is ERROR_MARK_NODE, that may mean that we are
+        presently processing the initializer, so we conservatively
+        treat this situation as meaning that DECL is uninitialized.  */
       if (init == error_mark_node)
-       return error_mark_node;
+       break;
       if (!init
          || !TREE_TYPE (init)
          || (integral_p
index 75b063b75588067e29b0cd9507b907f08a16f8f9..f6a4f3a83b34acb5ccb12c5e738c9cea29b46bf1 100644 (file)
@@ -3314,6 +3314,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:
      
index 0e0027d05f4cdbae105497e7455f5c5bd4392c9d..7ca006e02b3b259a84bc36f94a989abc411b1b6e 100644 (file)
@@ -1,3 +1,19 @@
+2007-01-27  Volker Reichelt  <v.reichelt@netcologne.de>
+
+       Backport:
+       2006-11-13  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/29106
+       * init.c (constant_value_1): Treat a DECL_INITIAL of
+       error_mark_node as meaning that the variable is uninitialized,
+       rather than erroneously initialized.
+
+       2006-08-27  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.
+
 2007-01-25  Richard Guenther  <rguenther@suse.de>
 
        Backport from mainline:
index aededf23e7b72043720c50a5c6e307538b6d3dda..e2af0809c713cf3a8ab623e0539a5cf8734f22cb 100644 (file)
@@ -11,7 +11,7 @@ template<int> struct B {};
 template<typename T> struct C
 {
   static const int i = A<T>::i;  // { dg-error "incomplete" }
-  static const int j = i;
+  static const int j = i;  // { dg-error "non-constant expression" }
   B<j> b;  // { dg-error "not a valid template arg" }
 };
 
diff --git a/gcc/testsuite/g++.dg/init/self1.C b/gcc/testsuite/g++.dg/init/self1.C
new file mode 100644 (file)
index 0000000..dd37c8e
--- /dev/null
@@ -0,0 +1,19 @@
+// PR c++/29106
+// { dg-do run } 
+
+int i;
+
+void f(__SIZE_TYPE__) {
+  i = 3;
+}
+
+
+int main()
+{
+  int* const savepos = sizeof(*savepos) ? 0 : 0;
+
+  f (sizeof (*savepos));
+
+  if (i != 3)
+    return 1;
+}
index f1f0dd9b99b5ebeac95531e5c4e469de2688f7ef..b085a84f0dda9529163f6162ae586dfcc3ca5caf 100644 (file)
@@ -4,5 +4,5 @@
 struct A
 {
     static const int i = i;  // { dg-error "not declared" }
-    int x[i];                // { dg-error "variable-size array" }
+    int x[i];                // { dg-error "integral constant-expression" }
 };
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;