Hi,
a rather simple issue. In mainline we have machinery to detect broken
uses of auto variables before deduction, for which mark_used is designed
to error out and return false to the caller. However, in the specific
cases pointed out in this PR the error recovery is not Ok, because
mark_used doesn't return false after error and anyway the caller -
finish_id_expression - doesn't check the return value.
Tested x86_64-linux.
Thanks,
Paolo.
//////////////////////////
/cp
2012-08-25 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/51421
* decl2.c (mark_used): Consistently return false after errors
about uses before deduction of auto.
* semantics.c (finish_id_expression): Check mark_used return
value and return error_mark_node in case of failure.
/testsuite
2012-08-25 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/51421
* g++.dg/cpp0x/auto34.C: New.
Index: testsuite/g++.dg/cpp0x/auto34.C
===================================================================
--- testsuite/g++.dg/cpp0x/auto34.C (revision 0)
+++ testsuite/g++.dg/cpp0x/auto34.C (revision 0)
@@ -0,0 +1,18 @@
+// PR c++/51421
+// { dg-do compile { target c++11 } }
+
+int foo1(int);
+
+void bar1()
+{
+ auto i = foo1(i); // { dg-error "before deduction" }
+}
+
+struct A {};
+
+A foo2(A);
+
+void bar2()
+{
+ auto a = foo2(a); // { dg-error "before deduction" }
+}
Index: cp/decl2.c
===================================================================
--- cp/decl2.c (revision 190649)
+++ cp/decl2.c (working copy)
@@ -4238,7 +4238,10 @@ mark_used (tree decl)
|| DECL_THUNK_P (decl))
{
if (!processing_template_decl && type_uses_auto (TREE_TYPE (decl)))
- error ("use of %qD before deduction of %<auto%>", decl);
+ {
+ error ("use of %qD before deduction of %<auto%>", decl);
+ return false;
+ }
return true;
}
@@ -4284,7 +4287,10 @@ mark_used (tree decl)
}
if (type_uses_auto (TREE_TYPE (decl)))
- error ("use of %qD before deduction of %<auto%>", decl);
+ {
+ error ("use of %qD before deduction of %<auto%>", decl);
+ return false;
+ }
/* If we don't need a value, then we don't need to synthesize DECL. */
if (cp_unevaluated_operand != 0)
Index: cp/semantics.c
===================================================================
--- cp/semantics.c (revision 190649)
+++ cp/semantics.c (working copy)
@@ -3220,11 +3220,12 @@ finish_id_expression (tree id_expression,
/* Mark variable-like entities as used. Functions are similarly
marked either below or after overload resolution. */
- if (TREE_CODE (decl) == VAR_DECL
- || TREE_CODE (decl) == PARM_DECL
- || TREE_CODE (decl) == CONST_DECL
- || TREE_CODE (decl) == RESULT_DECL)
- mark_used (decl);
+ if ((TREE_CODE (decl) == VAR_DECL
+ || TREE_CODE (decl) == PARM_DECL
+ || TREE_CODE (decl) == CONST_DECL
+ || TREE_CODE (decl) == RESULT_DECL)
+ && !mark_used (decl))
+ return error_mark_node;
/* Only certain kinds of names are allowed in constant
expression. Template parameters have already