From 712c948a074b0df50a1df6c5ce2d05acbd9ac972 Mon Sep 17 00:00:00 2001
From: Jason Merrill <jason@redhat.com>
Date: Mon, 8 Aug 2011 11:32:21 -0400
Subject: [PATCH] re PR c++/50020 ([C++0x] internal compiler error range for in
 templated class)

	PR c++/50020
	* semantics.c (finish_call_expr): Don't look at 'this' if we
	had an explicit object argument.

From-SVN: r177567
---
 gcc/cp/ChangeLog                         |  4 ++++
 gcc/cp/semantics.c                       |  6 ++++--
 gcc/testsuite/ChangeLog                  |  2 ++
 gcc/testsuite/g++.dg/cpp0x/range-for20.C | 20 ++++++++++++--------
 4 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 8c1ecba038b9..65a270147a76 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,9 @@
 2011-08-08  Jason Merrill  <jason@redhat.com>
 
+	PR c++/50020
+	* semantics.c (finish_call_expr): Don't look at 'this' if we
+	had an explicit object argument.
+
 	PR c++/50011
 	* typeck2.c (check_narrowing): Fix integer logic.
 
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index aa62049f8be9..59b25e5066a0 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -2042,12 +2042,14 @@ finish_call_expr (tree fn, VEC(tree,gc) **args, bool disallow_virtual,
 	 expressions with no type as being dependent.  */
       if (type_dependent_expression_p (fn)
 	  || any_type_dependent_arguments_p (*args)
-	  /* For a non-static member function, we need to specifically
+	  /* For a non-static member function that doesn't have an
+	     explicit object argument, 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.  */
-	  || (non_static_member_function_p (fn)
+	  || (TREE_CODE (fn) != COMPONENT_REF
+	      && non_static_member_function_p (fn)
 	      && current_class_ref
 	      && type_dependent_expression_p (current_class_ref)))
 	{
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 33832179d8f6..8b4c15a62a83 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,7 @@
 2011-08-08  Jason Merrill  <jason@redhat.com>
 
+	* g++.dg/cpp0x/range-for20.C: Adjust to test 50020 as well.
+
 	* g++.dg/cpp0x/initlist5.C: Add 50011 test.
 
 2011-08-07  Janus Weil  <janus@gcc.gnu.org>
diff --git a/gcc/testsuite/g++.dg/cpp0x/range-for20.C b/gcc/testsuite/g++.dg/cpp0x/range-for20.C
index 8205b228df30..890eb0aeaf90 100644
--- a/gcc/testsuite/g++.dg/cpp0x/range-for20.C
+++ b/gcc/testsuite/g++.dg/cpp0x/range-for20.C
@@ -1,4 +1,5 @@
 // PR c++/49834
+// PR c++/50020
 // { dg-options -std=c++0x }
 
 struct A
@@ -17,16 +18,19 @@ struct C
 };
 
 template <typename Ret>
-Ret f(const C &p)
+struct D
 {
-  for (const B &i: p)		// OK
-    i.second.get_value<int>();
-  for (const auto &i: p)	// ERROR
-    i.second.get_value<int>();
-  return Ret(0);
-}
+  Ret f(const C &p)
+  {
+    for (const B &i: p)		// OK
+      i.second.get_value<int>();
+    for (const auto &i: p)	// ERROR
+      i.second.get_value<int>();
+    return Ret(0);
+  }
+};
 
 void g()
 {
-  f<int>(C());
+  D<int>().f(C());
 }
-- 
GitLab