diff mbox

C++ PATCH for c++/50848 (ice-on-invalid with call to int&)

Message ID 4EB88186.7080006@redhat.com
State New
Headers show

Commit Message

Jason Merrill Nov. 8, 2011, 1:10 a.m. UTC
Here our code trying to give a helpful diagnostic for a call to an 
undeclared name in a template assumed that doing the lookup in 
instantiated context would find a function; in this testcase it finds an 
int&, and gets all confused.

Tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox

Patch

commit 2bf99c2e68564b35f93f941a80fdc049e9a5d717
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Nov 7 18:10:05 2011 -0500

    	PR c++/50848
    	* pt.c (tsubst_copy_and_build) [CALL_EXPR]: Don't crash
    	if lookup finds a non-function.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 53a5358..bf2a2c6 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -13673,6 +13673,8 @@  tsubst_copy_and_build (tree t,
 		if (unq != function)
 		  {
 		    tree fn = unq;
+		    if (TREE_CODE (fn) == INDIRECT_REF)
+		      fn = TREE_OPERAND (fn, 0);
 		    if (TREE_CODE (fn) == COMPONENT_REF)
 		      fn = TREE_OPERAND (fn, 1);
 		    if (is_overloaded_fn (fn))
@@ -13682,7 +13684,9 @@  tsubst_copy_and_build (tree t,
 			       "and no declarations were found by "
 			       "argument-dependent lookup at the point "
 			       "of instantiation", function);
-		    if (DECL_CLASS_SCOPE_P (fn))
+		    if (!DECL_P (fn))
+		      /* Can't say anything more.  */;
+		    else if (DECL_CLASS_SCOPE_P (fn))
 		      {
 			inform (EXPR_LOC_OR_HERE (t),
 				"declarations in dependent base %qT are "
diff --git a/gcc/testsuite/g++.dg/template/lookup9.C b/gcc/testsuite/g++.dg/template/lookup9.C
new file mode 100644
index 0000000..4a1dc79
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/lookup9.C
@@ -0,0 +1,10 @@ 
+// PR c++/50848
+// { dg-options "-fpermissive" }
+
+template<class T> class A {T& foo;};
+template<class T> class B: public A<T> {
+  void f(){
+    foo(1);			// { dg-message "foo" }
+  }
+};
+template class B<int>;