Hi,
On 05/27/2014 07:15 PM, Jason Merrill wrote:
I don't think this is the right place for the fix; why do we have a
dummy object at all? Doesn't maybe_dummy_object return
current_class_ref in this situation?
I see, thanks for the dummy object clarification.
Therefore, it seems to me that the real issue is that current_class_ref
is null when maybe_dummy_object is called in the template case, vs the
non-template case where cp_parser_late_return_type_opt calls
inject_this_parameter. Thus the below, which at least passes testing.
The most tricky case is tested with struct Z: in that case
tsubst_function_type is called , via 3/4 hops, from fn_type_unification,
thus the former cannot simply use current_class_type, which is null. I
tried to cope with that by using DECL_CONTEXT (in_decl) but then
fn_type_unification has to pass the actual TEMPLATE_DECL as in_decl, not
NULL_TREE. Is that reasonable??
Thanks!
Paolo.
////////////////////
Index: cp/pt.c
===================================================================
--- cp/pt.c (revision 210956)
+++ cp/pt.c (working copy)
@@ -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,29 @@
+// 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() );
+};
+
+int main()
+{
+ X<int>().bar();
+ Y<int>().bar<double>();
+ Z<int>().bar<Z<int>>();
+}