This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH: PR 29106


In this PR, we were silently not generating code for an entire
statement.  The proximate cause was that we produced an
error_mark_node expression -- without issuing an error.  The root
cause was that, prior to 4.2, we set DECL_INITIAL for a VAR_DECL to
error_mark_node to indicate that it was initialized -- but that we had
not yet processed the initializer.  That's clearly an ugly
representation, since fixed -- but we backported a patch to 4.1 that
did not take this into account.  In particular, for a constant
VAR_DECL, when using its value in an integral constant-expression, we
noticed that the initializer was error_mark_node, and decided that the
entire expression was ernoneous.

This patch fixes the problem by conservatively treating such a
variable as uninitialized.  The changes to the error messages for
existing tests are the same changes that were made in 4.2 after the
representation adjustment.

Tested on x86_64-unknown-linux-gnu, applied to the 4.1 branch.

--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

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-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.

Index: gcc/cp/init.c
===================================================================
--- gcc/cp/init.c	(revision 118746)
+++ gcc/cp/init.c	(working copy)
@@ -1609,8 +1609,11 @@ constant_value_1 (tree decl, bool integr
 	  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: gcc/testsuite/g++.dg/other/fold1.C
===================================================================
--- gcc/testsuite/g++.dg/other/fold1.C	(revision 118746)
+++ gcc/testsuite/g++.dg/other/fold1.C	(working copy)
@@ -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" }
 };
Index: gcc/testsuite/g++.dg/init/member1.C
===================================================================
--- gcc/testsuite/g++.dg/init/member1.C	(revision 118746)
+++ gcc/testsuite/g++.dg/init/member1.C	(working copy)
@@ -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" }
 };
 
Index: gcc/testsuite/g++.dg/init/self1.C
===================================================================
--- gcc/testsuite/g++.dg/init/self1.C	(revision 0)
+++ gcc/testsuite/g++.dg/init/self1.C	(revision 0)
@@ -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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]