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] Fix two little fallouts from the VLA changes (PR c++/40370, PR c++/40372)


Hi!

PR40370 testcase fails because after the PR28879 (r144988) changes
cp_parser_direct_declaration no longer complains about
!parser->in_function_body uses of VLAs.  The PR28879 changes added
else if (processing_template_decl) { ... } right after the
if (!non_constant_p), I believe it should be after the check for
else if (!parser->in_function_body).

The PR40372 testcase ICEs because build_nop doesn't create NOP_EXPR for
error_operand_p (bounds) (or for error_mark_node type, but as build_nop
is called with exp's TREE_TYPE, that is already covered), so it can
e.g. set TREE_SIDE_EFFECTS (error_mark_node) = 1, which confuses the
compiler in many places later on.  Fixed by not doing the wrapping for
errorneous bounds.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/4.4?

2009-06-08  Jakub Jelinek  <jakub@redhat.com>

	PR c++/40370
	PR c++/40372
	* parser.c (cp_parser_direct_declarator): Don't set TREE_SIDE_EFFECTS
	on error_mark_node.  Check for VLAs outside of function context
	before check whether to wrap bounds into a NOP_EXPR with
	TREE_SIDE_EFFECTS.

	* g++.dg/template/error41.C: New test.
	* g++.dg/template/error42.C: New test.

--- gcc/cp/parser.c.jj	2009-05-21 15:59:14.000000000 +0200
+++ gcc/cp/parser.c	2009-06-08 11:33:44.000000000 +0200
@@ -13313,13 +13313,6 @@ cp_parser_direct_declarator (cp_parser* 
 						 &non_constant_p);
 	      if (!non_constant_p)
 		bounds = fold_non_dependent_expr (bounds);
-	      else if (processing_template_decl)
-		{
-		  /* Remember this wasn't a constant-expression.  */
-		  bounds = build_nop (TREE_TYPE (bounds), bounds);
-		  TREE_SIDE_EFFECTS (bounds) = 1;
-		}
-
 	      /* Normally, the array bound must be an integral constant
 		 expression.  However, as an extension, we allow VLAs
 		 in function scopes.  */
@@ -13329,6 +13322,12 @@ cp_parser_direct_declarator (cp_parser* 
 			 &token->location);
 		  bounds = error_mark_node;
 		}
+	      else if (processing_template_decl && !error_operand_p (bounds))
+		{
+		  /* Remember this wasn't a constant-expression.  */
+		  bounds = build_nop (TREE_TYPE (bounds), bounds);
+		  TREE_SIDE_EFFECTS (bounds) = 1;
+		}
 	    }
 	  else
 	    bounds = NULL_TREE;
--- gcc/testsuite/g++.dg/template/error41.C.jj	2009-06-08 11:40:03.000000000 +0200
+++ gcc/testsuite/g++.dg/template/error41.C	2009-06-08 11:42:12.000000000 +0200
@@ -0,0 +1,12 @@
+// PR c++/40370
+// { dg-do compile }
+
+struct A
+{
+  static int i;
+};
+
+template <int> struct B
+{
+  int x[A::i];	// { dg-error "array bound is not an integer constant" }
+};
--- gcc/testsuite/g++.dg/template/error42.C.jj	2009-06-08 11:02:09.000000000 +0200
+++ gcc/testsuite/g++.dg/template/error42.C	2009-06-08 11:04:15.000000000 +0200
@@ -0,0 +1,20 @@
+// PR c++/40372
+// { dg-do compile }
+
+template <int> struct A
+{
+  int i;		// { dg-error "invalid use of non-static data member" }
+  friend void foo ()
+  {
+    int x[i];		// { dg-error "from this location" }
+  }
+};
+
+struct B
+{
+  int j;		// { dg-error "invalid use of non-static data member" }
+  friend int bar ()
+  {
+    return j;		// { dg-error "from this location" }
+  }
+};

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]