diff mbox

[C++] PR 57543

Message ID 5386406B.9050902@oracle.com
State New
Headers show

Commit Message

Paolo Carlini May 28, 2014, 8 p.m. UTC
Hi again,

On 05/28/2014 07:06 PM, Paolo Carlini wrote:
> (In case I would have also to double check something weird I was 
> seeing if the injection happens for all method types...)
In the meanwhile I investigated the reason of all those regressions I 
was seeing when injecting in all METHOD_TYPEs: while handling, eg, from 
cpp0x/access02.C:

template<class T>
struct foo_argument
{
   template<class Ret, class C, class Arg>
   static Arg test(Ret (C::*)(Arg));
   ...
};

we may still have, *after* substituting the argument types, that the the 
TREE_TYPE of the 0-th argument is still dependent, eg, a 
TEMPLATE_TYPE_PARM. In such cases it seems to me clear that it doesn't 
make sense to inject it, we don't really know the type. Indeed, if we 
try, we ICE in type_of_this_parm.

Thus the below, which passes testing.

Thanks!
Paolo.

////////////////////////////

Comments

Paolo Carlini May 29, 2014, 12:04 a.m. UTC | #1
On 05/28/2014 10:00 PM, Paolo Carlini wrote:
> Hi again,
>
> On 05/28/2014 07:06 PM, Paolo Carlini wrote:
>> (In case I would have also to double check something weird I was 
>> seeing if the injection happens for all method types...)
> In the meanwhile I investigated the reason of all those regressions I 
> was seeing when injecting in all METHOD_TYPEs: while handling, eg, 
> from cpp0x/access02.C:
>
> template<class T>
> struct foo_argument
> {
>   template<class Ret, class C, class Arg>
>   static Arg test(Ret (C::*)(Arg));
>   ...
> };
Just wanted to add that I spent some time analyzing what we do for the 
above and things seem in good shape: the first time we call 
tsubst_function_type on Ret (C::)(Arg) we don't know the type of C and 
we do not inject. Then we work again on it, when we actually know the 
types of Ret, C, and Arg, and then we inject, and tsubst_function_type 
returns a fully substituted fntype, an (int) (base::) (int).

Paolo.
diff mbox

Patch

Index: cp/pt.c
===================================================================
--- cp/pt.c	(revision 211024)
+++ cp/pt.c	(working copy)
@@ -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)
     {
Index: testsuite/g++.dg/cpp0x/decltype28.C
===================================================================
--- testsuite/g++.dg/cpp0x/decltype28.C	(revision 211024)
+++ testsuite/g++.dg/cpp0x/decltype28.C	(working copy)
@@ -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);
 }
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>>();
+}