===================================================================
@@ -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;
+ bool do_inject = (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. */
+ tree this_type = TREE_TYPE (TREE_VALUE (arg_types));
+ 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);
}