Patchwork C++ PATCH for c++/48581 (sfinae failure with ADL in default template arg)

login
register
mail settings
Submitter Jason Merrill
Date April 13, 2011, 2:33 p.m.
Message ID <4DA5B438.7040208@redhat.com>
Download mbox | patch
Permalink /patch/91017/
State New
Headers show

Comments

Jason Merrill - April 13, 2011, 2:33 p.m.
We can't decide that a lookup has failed while we're still in template 
context, as phase 2 lookup might find it.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit bf1635b662fb30ac7dc03b292bb52943c4dccc18
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Apr 12 13:59:07 2011 -0400

    	* pt.c (tsubst_copy_and_build) [CALL_EXPR]: Don't complain about
    	unqualified lookup failing if we're still in a template.

Patch

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 208ff2b..3356e75 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -12938,7 +12938,8 @@  tsubst_copy_and_build (tree t,
 	    && !any_type_dependent_arguments_p (call_args))
 	  function = perform_koenig_lookup (function, call_args, false);
 
-	if (TREE_CODE (function) == IDENTIFIER_NODE)
+	if (TREE_CODE (function) == IDENTIFIER_NODE
+	    && !processing_template_decl)
 	  {
 	    unqualified_name_lookup_error (function);
 	    release_tree_vector (call_args);
diff --git a/gcc/testsuite/g++.dg/cpp0x/sfinae13.C b/gcc/testsuite/g++.dg/cpp0x/sfinae13.C
new file mode 100644
index 0000000..465df2d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/sfinae13.C
@@ -0,0 +1,20 @@ 
+// PR c++/48581
+// { dg-options -std=c++0x }
+
+template<class T>
+T&& create();
+
+template<class T,
+  class = decltype(foo(create<T>()))
+>
+auto f(int) -> char;
+
+template<class>
+auto f(...) -> char (&)[2];
+
+struct S {};
+void foo(S);
+
+static_assert(sizeof(f<S>(0)) == 1, "Error"); // (#)
+
+int main() {}