diff mbox

Fix PR c++/47172

Message ID m31v3fbv2h.fsf@redhat.com
State New
Headers show

Commit Message

Dodji Seketeli Feb. 10, 2011, 6:31 p.m. UTC
Jason Merrill <jason@redhat.com> writes:

> Just add a reference to issues 515 and 1005.

Done.

>> +	  || (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn)
>> +	      && current_class_ref
>> +	      && type_dependent_expression_p (current_class_ref)))
>
> I'm uncomfortable with checking DECL_NONSTATIC_MEMBER_FUNCTION_P
> before we've established that fn is a FUNCTION_DECL.  Let's check its
> TREE_CODE first.

Right; done.


>>  /* Returns TRUE if the EXPRESSION is type-dependent, in the sense of
>> -   [temp.dep.expr].  */
>> +   [temp.dep.expr]. Note that an expression with no type is
>> +   considered dependent.  */
>
> Let's also note that other parts of the compiler arrange for an
> expression with type-dependent subexpressions to have no type, so we
> don't need to recurse in type_dependent_expression_p.

Done.

I am currently running a full bootstrap & regression tests.

OK to commit to trunk if the testing succeeds?

Comments

Jason Merrill Feb. 10, 2011, 7:43 p.m. UTC | #1
On 02/10/2011 01:31 PM, Dodji Seketeli wrote:
> +	  /* In a template scope, a call expression which
> +	     id-expression is non-dependent is considered dependent if
> +	     the implicit "this" is dependent.  Note that the

To be a bit clearer, the implicit 'this' is an argument even though our 
internal representation doesn't include it in *args, so we need to 
consider it specifically.

Jason
Jason Merrill Feb. 10, 2011, 7:43 p.m. UTC | #2
On 02/10/2011 01:31 PM, Dodji Seketeli wrote:
> +	  /* In a template scope, a call expression which
> +	     id-expression is non-dependent is considered dependent if
> +	     the implicit "this" is dependent.  Note that the

To be a bit clearer, the implicit 'this' is an argument even though our 
internal representation doesn't include it in *args, so we need to 
consider it specifically.

OK.

Jason
diff mbox

Patch

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index d59f32a..746e295 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -17912,7 +17912,7 @@  dependent_type_p_r (tree type)
 }
 
 /* Returns TRUE if TYPE is dependent, in the sense of
-   [temp.dep.type].  */
+   [temp.dep.type].  Note that a NULL type is considered dependent.  */
 
 bool
 dependent_type_p (tree type)
@@ -18184,7 +18184,10 @@  value_dependent_expression_p (tree expression)
 }
 
 /* Returns TRUE if the EXPRESSION is type-dependent, in the sense of
-   [temp.dep.expr].  */
+   [temp.dep.expr].  Note that an expression with no type is
+   considered dependent.  Other parts of the compiler arrange for an
+   expression with type-dependent subexpressions to have no type, so
+   this function doesn't have be fully recursive.  */
 
 bool
 type_dependent_expression_p (tree expression)
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 6d45fb9..4e9e71e 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -2028,8 +2028,21 @@  finish_call_expr (tree fn, VEC(tree,gc) **args, bool disallow_virtual,
 
   if (processing_template_decl)
     {
+      /* If the call expression is dependent, build a CALL_EXPR node
+	 with no type; type_dependent_expression_p recognizes
+	 expressions with no type as being dependent.  */
       if (type_dependent_expression_p (fn)
-	  || any_type_dependent_arguments_p (*args))
+	  || any_type_dependent_arguments_p (*args)
+	  /* In a template scope, a call expression which
+	     id-expression is non-dependent is considered dependent if
+	     the implicit "this" is dependent.  Note that the
+	     id-expression is already bound (at template definition
+	     time) so this respects the essence of the two-phases name
+	     lookup.  This is related to CWG issues 515 and 1005.  */
+	  || (TREE_CODE (fn) == FUNCTION_DECL
+	      && DECL_NONSTATIC_MEMBER_FUNCTION_P (fn)
+	      && current_class_ref
+	      && type_dependent_expression_p (current_class_ref)))
 	{
 	  result = build_nt_call_vec (fn, *args);
 	  KOENIG_LOOKUP_P (result) = koenig_p;
diff --git a/gcc/testsuite/g++.dg/template/inherit6.C b/gcc/testsuite/g++.dg/template/inherit6.C
new file mode 100644
index 0000000..241a68e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/inherit6.C
@@ -0,0 +1,23 @@ 
+// Origin PR c++/47172
+// { dg-options "-std=c++0x" }
+// { dg-do compile }
+
+struct A
+{
+    int f() const;
+};
+
+template <class T>
+struct B : A { };
+
+template <class T>
+struct C : B<T>
+{
+    void g();
+};
+
+template <class T>
+void C<T>::g()
+{
+    A::f();
+}