Back when we added C++11 auto deduction, I thought we could shortcut the normal deduction in some templates, when the type is adequately describable (thus the late, unlamented function describable_type). Over time various problems with this have arisen, of which this is the most recent; as a result, I'm giving up the attempt as a bad idea and just deferring auto deduction if the initializer is type-dependent.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit 639eddf82da171a041d5184d5dd2917f102dde3c
Author: Jason Merrill <ja...@redhat.com>
Date:   Thu May 31 11:50:20 2012 -0400

    	PR c++/53484
    	* pt.c (do_auto_deduction): Don't try to deduce from a
    	type-dependent initializer.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index c55687b..b58dd13 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -20318,10 +20318,9 @@ do_auto_deduction (tree type, tree init, tree auto_node)
   if (init == error_mark_node)
     return error_mark_node;
 
-  if (processing_template_decl
-      && (TREE_TYPE (init) == NULL_TREE
-	  || BRACE_ENCLOSED_INITIALIZER_P (init)))
-    /* Not enough information to try this yet.  */
+  if (type_dependent_expression_p (init))
+    /* Defining a subset of type-dependent expressions that we can deduce
+       from ahead of time isn't worth the trouble.  */
     return type;
 
   /* [dcl.spec.auto]: Obtain P from T by replacing the occurrences of auto
diff --git a/gcc/testsuite/g++.dg/cpp0x/auto33.C b/gcc/testsuite/g++.dg/cpp0x/auto33.C
new file mode 100644
index 0000000..dade5a8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/auto33.C
@@ -0,0 +1,15 @@
+// PR c++/53484
+// { dg-do compile { target c++11 } }
+
+template<class T,class U> struct ST;
+template<class T> struct ST<T,T> {};
+
+template <class T>
+void f(T x){
+   [&]{
+     auto y = x;
+     ST<decltype(y),int>();
+   }();
+}
+
+int main(){ f(0); }

Reply via email to