... if the approach makes sense, we want to pass a proper in_decl in one
more place, otherwise specializations are not handled (eg, K in the
testcase). Like the below, lightly tested so far.
Paolo.
///////////////////////
Index: cp/pt.c
===================================================================
--- cp/pt.c (revision 210956)
+++ cp/pt.c (working copy)
@@ -1987,7 +1987,7 @@ determine_specialization (tree template_id,
continue;
/* Make sure that the deduced arguments actually work. */
- insttype = tsubst (TREE_TYPE (fn), targs, tf_none, NULL_TREE);
+ insttype = tsubst (TREE_TYPE (fn), targs, tf_none, fn);
if (insttype == error_mark_node)
continue;
fn_arg_types
@@ -11323,7 +11323,28 @@ tsubst_function_type (tree t,
gcc_assert (TYPE_CONTEXT (t) == NULL_TREE);
/* Substitute the return type. */
+ tree save_ccp = current_class_ptr;
+ tree save_ccr = current_class_ref;
+ bool do_inject = (!current_class_ref
+ && TREE_CODE (t) == METHOD_TYPE
+ && TREE_CODE (TREE_TYPE (t)) == DECLTYPE_TYPE);
+ if (do_inject)
+ {
+ /* DR 1207: 'this' is in scope in the trailing return type. */
+ inject_this_parameter (current_class_type
+ ? current_class_type
+ : DECL_CONTEXT (in_decl),
+ type_memfn_quals (t));
+ }
+
return_type = tsubst (TREE_TYPE (t), args, complain, in_decl);
+
+ if (do_inject)
+ {
+ current_class_ptr = save_ccp;
+ current_class_ref = save_ccr;
+ }
+
if (return_type == error_mark_node)
return error_mark_node;
/* DR 486 clarifies that creation of a function type with an
@@ -15872,7 +15893,7 @@ fn_type_unification (tree fn,
access path at this point. */
push_deferring_access_checks (dk_deferred);
fntype = tsubst (TREE_TYPE (fn), explicit_targs,
- complain | tf_partial, NULL_TREE);
+ complain | tf_partial, fn);
pop_deferring_access_checks ();
input_location = loc;
processing_template_decl -= incomplete;
Index: testsuite/g++.dg/cpp0x/decltype59.C
===================================================================
--- testsuite/g++.dg/cpp0x/decltype59.C (revision 0)
+++ testsuite/g++.dg/cpp0x/decltype59.C (working copy)
@@ -0,0 +1,41 @@
+// PR c++/57543
+// { dg-do compile { target c++11 } }
+
+template< typename > struct X
+{
+ void foo();
+ auto bar() -> decltype( X::foo() );
+};
+
+template< typename > struct Y
+{
+ void foo();
+ template< typename >
+ auto bar() -> decltype( Y::foo() );
+};
+
+template< typename > struct Z
+{
+ void foo();
+ template< typename T >
+ auto bar() -> decltype( T::foo() );
+};
+
+template< typename > struct K
+{
+ void foo();
+ template< typename T >
+ auto bar() -> decltype( T::foo() );
+};
+
+template<>
+template<>
+auto K<int>::bar<K<int>>() -> decltype( K<int>::foo() );
+
+int main()
+{
+ X<int>().bar();
+ Y<int>().bar<double>();
+ Z<int>().bar<Z<int>>();
+ K<int>().bar<K<int>>();
+}