Patchwork Fix PR c++/47172

login
register
mail settings
Submitter Dodji Seketeli
Date Feb. 11, 2011, 5:43 p.m.
Message ID <m3wrl679hj.fsf@redhat.com>
Download mbox | patch
Permalink /patch/82816/
State New
Headers show

Comments

Dodji Seketeli - Feb. 11, 2011, 5:43 p.m.
Oh well.  I did it again.  I haven't *locally* committed my last changes
yesterday night before launching the script that pushes my local commits
to the compile farm and kicks off a full bootstrap + regression tests.
I was just testing the previously committed stuff -- which didn't have
the test that ensures we have a FUNCTION_DECL.  Sorry.

So I have reverted the faulty commit.

The first diff below is just what it takes to fix the breakage, from
what we had yesterday. It's just that in the test case the function is a
BASELINK node instead of a FUNCTION_DECL.

The second one is the full patch I am testing at the moment.
Dodji Seketeli - Feb. 11, 2011, 7:43 p.m.
Dodji Seketeli <dodji@redhat.com> writes:

> The second one is the full patch I am testing at the moment.

It passed the bootstrap & testing and I double-checked it was the
right one this time.

Patch

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index a941b3b..fec3762 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -2038,7 +2038,7 @@  finish_call_expr (tree fn, VEC(tree,gc) **args, bool disallow_virtual,
 	     is not included in *ARGS even though it is considered to
 	     be part of the list of arguments.  Note that this is
 	     related to CWG issues 515 and 1005.  */
-	  || (TREE_CODE (fn) == FUNCTION_DECL
+	  || ((TREE_CODE (fn) == FUNCTION_DECL || TREE_CODE (fn) == BASELINK)
 	      && DECL_NONSTATIC_MEMBER_FUNCTION_P (fn)
 	      && current_class_ref
 	      && type_dependent_expression_p (current_class_ref)))


From 8cc0f7f544289e91135babc72826516ce3623591 Mon Sep 17 00:00:00 2001
From: dodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Fri, 11 Feb 2011 07:33:53 +0000
Subject: [PATCH] Fix PR c++/47172

gcc/cp/

	PR c++/47172
	* pt.c (finish_call_expr): Consider a call expression that has a
	dependent "this" pointer as being dependent.  Add comments.
	(dependent_type_p, type_dependent_expression_p): Update comments.

gcc/testsuite/

	* g++.dg/template/inherit6.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@170045 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/cp/ChangeLog                         |    7 +++++++
 gcc/cp/pt.c                              |    7 +++++--
 gcc/cp/semantics.c                       |   14 +++++++++++++-
 gcc/testsuite/ChangeLog                  |    5 +++++
 gcc/testsuite/g++.dg/template/inherit6.C |   23 +++++++++++++++++++++++
 5 files changed, 53 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/template/inherit6.C

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index d59f32a..a55a35a 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 to be fully recursive.  */
 
 bool
 type_dependent_expression_p (tree expression)
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 58a59ee..fec3762 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -2028,8 +2028,20 @@  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)
+	  /* For a non-static member function, we need to specifically
+	     test the type dependency of the "this" pointer because it
+	     is not included in *ARGS even though it is considered to
+	     be part of the list of arguments.  Note that this is
+	     related to CWG issues 515 and 1005.  */
+	  || ((TREE_CODE (fn) == FUNCTION_DECL || TREE_CODE (fn) == BASELINK)
+	      && 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();
+}