diff mbox

[C++] PR 51404

Message ID 4EDBB331.2030208@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Dec. 4, 2011, 5:51 p.m. UTC
Hi,

for this ice on invalid, 4.7 Regression, the idea is just early 
returning error_mark_node from build_functional_cast, after the error, 
like in all the other error conditions explicitly dealt with there, 
instead of setting type = error_mark_node.

The catch is, for testcases like auto25.C:

template<int> struct A
{
   int a[auto(1)]; // { dg-error "invalid use of" }
};

we don't want to add an additional redundant error message saying that 
array bound is not an integer constant. Thus the tweak to 
cp_parser_direct_declarator. As-is, patch tested x86_64-linux without 
regressions.

Thanks,
Paolo.

////////////////
/cp
2011-12-04  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/51404
	* typeck2.c (build_functional_cast): Early return error_mark_node
	for invalid uses of 'auto'.
	* parser.c (cp_parser_direct_declarator): When non_constant_p
	and cp_parser_constant_expression returns error do not produce
	further diagnostic for the bound.

/testsuite
2011-12-04  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/51404
	* g++.dg/cpp0x/auto28.C: New.

Comments

Jason Merrill Dec. 5, 2011, 3 p.m. UTC | #1
Hmm, I think giving the additional error was intentional, which is why 
we check for error_operand_p after giving it.  But I suppose I'm not 
attached to that.

We could avoid reformatting by adding

if (error_operand_p (bounds))
   /* Already gave an error.  */;

OK either way.

Jason
diff mbox

Patch

Index: testsuite/g++.dg/cpp0x/auto28.C
===================================================================
--- testsuite/g++.dg/cpp0x/auto28.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/auto28.C	(revision 0)
@@ -0,0 +1,4 @@ 
+// PR c++/51404
+// { dg-options -std=c++0x }
+
+int i = auto().x;  // { dg-error "invalid use of" }
Index: cp/typeck2.c
===================================================================
--- cp/typeck2.c	(revision 181984)
+++ cp/typeck2.c	(working copy)
@@ -1653,7 +1653,7 @@  build_functional_cast (tree exp, tree parms, tsubs
     {
       if (complain & tf_error)
 	error ("invalid use of %<auto%>");
-      type = error_mark_node;
+      return error_mark_node;
     }
 
   if (processing_template_decl)
Index: cp/parser.c
===================================================================
--- cp/parser.c	(revision 181984)
+++ cp/parser.c	(working copy)
@@ -16055,23 +16055,26 @@  cp_parser_direct_declarator (cp_parser* parser,
 						 &non_constant_p);
 	      if (!non_constant_p)
 		/* OK */;
-	      /* Normally, the array bound must be an integral constant
-		 expression.  However, as an extension, we allow VLAs
-		 in function scopes as long as they aren't part of a
-		 parameter declaration.  */
-	      else if (!parser->in_function_body
-		       || current_binding_level->kind == sk_function_parms)
+	      else if (!error_operand_p (bounds))
 		{
-		  cp_parser_error (parser,
-				   "array bound is not an integer constant");
-		  bounds = error_mark_node;
+		  /* Normally, the array bound must be an integral constant
+		     expression.  However, as an extension, we allow VLAs
+		     in function scopes as long as they aren't part of a
+		     parameter declaration.  */
+		  if (!parser->in_function_body
+		      || current_binding_level->kind == sk_function_parms)
+		    {
+		      cp_parser_error (parser, "array bound is not an "
+				       "integer constant");
+		      bounds = error_mark_node;
+		    }
+		  else if (processing_template_decl)
+		    {
+		      /* Remember this wasn't a constant-expression.  */
+		      bounds = build_nop (TREE_TYPE (bounds), bounds);
+		      TREE_SIDE_EFFECTS (bounds) = 1;
+		    }
 		}
-	      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;