re PR c++/51421 ([c++0x] ICE with invalid use of auto)
authorPaolo Carlini <paolo.carlini@oracle.com>
Sat, 25 Aug 2012 09:53:30 +0000 (09:53 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Sat, 25 Aug 2012 09:53:30 +0000 (09:53 +0000)
/cp
2012-08-25  Paolo Carlini  <paolo.carlini@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.carlini@oracle.com>

PR c++/51421
* g++.dg/cpp0x/auto34.C: New.

From-SVN: r190665

gcc/cp/ChangeLog
gcc/cp/decl2.c
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/auto34.C [new file with mode: 0644]

index 4cad303dc4482dc14d17db88d85291a6657d67b6..845f0b4ea6caf13fc357754c284bf2a2a429a7ad 100644 (file)
@@ -1,3 +1,11 @@
+2012-08-25  Paolo Carlini  <paolo.carlini@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.
+
 2012-08-24  Jason Merrill  <jason@redhat.com>
 
        PR c++/51213 (again)
index 281f6ff36f9ea19418035d0b3795abcabb6497a9..f76b59605ae21b57c793bbc871849d5bbc627e09 100644 (file)
@@ -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 4faca9147161a5cbc5e9d9ca73ea4f053d95fb8e..d66accfa934cca6f91ea7d9cabd09eab7af72498 100644 (file)
@@ -3221,11 +3221,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
index eeb62dc03a92d6107f02919d430daa279d82d205..94b23a444f88c4ac2a82b2cf19d4e2ece3562494 100644 (file)
@@ -1,3 +1,8 @@
+2012-08-25  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/51421
+       * g++.dg/cpp0x/auto34.C: New.
+
 2012-08-24  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/54363
diff --git a/gcc/testsuite/g++.dg/cpp0x/auto34.C b/gcc/testsuite/g++.dg/cpp0x/auto34.C
new file mode 100644 (file)
index 0000000..3682d60
--- /dev/null
@@ -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" }
+}