===================================================================
@@ -11322,8 +11322,32 @@ tsubst_function_type (tree t,
/* The TYPE_CONTEXT is not used for function/method types. */
gcc_assert (TYPE_CONTEXT (t) == NULL_TREE);
+ /* Substitute the argument types. */
+ arg_types = tsubst_arg_types (TYPE_ARG_TYPES (t), args, NULL_TREE,
+ complain, in_decl);
+ if (arg_types == error_mark_node)
+ return error_mark_node;
+
/* Substitute the return type. */
+ tree save_ccp = current_class_ptr;
+ tree save_ccr = current_class_ref;
+ tree this_type = (TREE_CODE (t) == METHOD_TYPE
+ ? TREE_TYPE (TREE_VALUE (arg_types)) : NULL_TREE);
+ bool do_inject = this_type && !dependent_type_p (this_type);
+ if (do_inject)
+ {
+ /* DR 1207: 'this' is in scope in the trailing return type. */
+ inject_this_parameter (this_type, cp_type_quals (this_type));
+ }
+
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
@@ -11344,12 +11368,6 @@ tsubst_function_type (tree t,
if (abstract_virtuals_error_sfinae (ACU_RETURN, return_type, complain))
return error_mark_node;
- /* Substitute the argument types. */
- arg_types = tsubst_arg_types (TYPE_ARG_TYPES (t), args, NULL_TREE,
- complain, in_decl);
- if (arg_types == error_mark_node)
- return error_mark_node;
-
/* Construct a new type node and return it. */
if (TREE_CODE (t) == FUNCTION_TYPE)
{
===================================================================
@@ -8,9 +8,9 @@ template <class F, int N>
void ft (F f, typename enable_if<N!=0, int>::type) {}
template< class F, int N >
-decltype(ft<F, N-1> (F(), 0)) // { dg-error "depth" }
+decltype(ft<F, N-1> (F(), 0))
ft (F f, typename enable_if<N==0, int>::type) {}
int main() {
- ft<struct a*, 2> (0, 0); // { dg-message "from here" }
+ ft<struct a*, 2> (0, 0);
}
===================================================================
@@ -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>>();
+}