diff mbox

C++ PATCH to diagnostic location for default template arguments

Message ID 4EC99705.4030904@redhat.com
State New
Headers show

Commit Message

Jason Merrill Nov. 21, 2011, 12:10 a.m. UTC
It seems to me that when we give diagnostics during substitution of a 
default template argument, the source location should be the definition 
of the default argument, not the call site; when we get there we will 
have already said that the call didn't find a match, and are explaining 
why the template isn't a match.

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

Patch

commit 1031c69cc4844896d0345831ab4ad068bef889f5
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Nov 18 23:25:03 2011 -0500

    	* pt.c (type_unification_real): Set input_location
    	during default arg instantiation.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 2b02fa4..3232527 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -15218,9 +15218,13 @@  type_unification_real (tree tparms,
 	    {
 	      tree parm = TREE_VALUE (TREE_VEC_ELT (tparms, i));
 	      tree arg = TREE_PURPOSE (TREE_VEC_ELT (tparms, i));
+	      location_t save_loc = input_location;
+	      if (DECL_P (parm))
+		input_location = DECL_SOURCE_LOCATION (parm);
 	      arg = tsubst_template_arg (arg, targs, complain, NULL_TREE);
 	      arg = convert_template_argument (parm, arg, targs, complain,
 					       i, NULL_TREE);
+	      input_location = save_loc;
 	      if (arg == error_mark_node)
 		return 1;
 	      else
diff --git a/gcc/testsuite/g++.dg/cpp0x/sfinae11.C b/gcc/testsuite/g++.dg/cpp0x/sfinae11.C
index 25902cb..2e8408d 100644
--- a/gcc/testsuite/g++.dg/cpp0x/sfinae11.C
+++ b/gcc/testsuite/g++.dg/cpp0x/sfinae11.C
@@ -12,7 +12,8 @@  inline void f1( T& x ) noexcept( noexcept( declval<T&>().foo() ) ) // { dg-error
 }
 
 template< class T,
-  bool Noexcept = noexcept( declval<T&>().foo() )
+  bool Noexcept = noexcept( declval<T&>().foo() ) // { dg-error "no member|not convert" }
+
 >
 inline void f2( T& x ) noexcept( Noexcept )
 {
@@ -51,7 +52,6 @@  int main()
   // static_assert(  noexcept( f3(y) ), "shall be ill-formed(OK)." );
 
   noexcept( f1(z) );		// { dg-message "required" }
-  static_assert(  noexcept( f2(z) ), "shall be ill-formed." ); // { dg-error "no match|could not convert" }
-  // { dg-error "no member" "" { target *-*-* } 54 }
+  static_assert(  noexcept( f2(z) ), "shall be ill-formed." ); // { dg-error "no match" }
   noexcept( f3(z) );		// { dg-message "required" }
 }
diff --git a/gcc/testsuite/g++.dg/template/unify11.C b/gcc/testsuite/g++.dg/template/unify11.C
index 25606dc..85bdbbc 100644
--- a/gcc/testsuite/g++.dg/template/unify11.C
+++ b/gcc/testsuite/g++.dg/template/unify11.C
@@ -6,9 +6,10 @@  struct A
 {
 };
 
-template <typename S, typename T, typename U, typename S::v = &S::v::s>
+template <typename S, typename T, typename U,
+	  typename S::v = &S::v::s> // { dg-error "is not a" }
 typename S::A
-foo (S c, T t, U u)		// { dg-message "note" }
+foo (S c, T t, U u)
 {
 }
 
@@ -20,8 +21,7 @@  struct B
     C (U t)
     {
       A a;
-      A b = foo (this, a, t); // { dg-error "(no matching function|is not a)" }
-      // { dg-message "candidate" "candidate note" { target *-*-* } 23 }
+      A b = foo (this, a, t); // { dg-error "no matching function" }
     }
   } c;
   B () : c (A ())
diff --git a/libstdc++-v3/testsuite/20_util/bind/ref_neg.cc b/libstdc++-v3/testsuite/20_util/bind/ref_neg.cc
index f5a08c2..d2441a3 100644
--- a/libstdc++-v3/testsuite/20_util/bind/ref_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/bind/ref_neg.cc
@@ -29,8 +29,12 @@  int inc(int& i) { return ++i; }
 void test01()
 {
   const int dummy = 0;
-  std::bind(&inc, _1)(0);               // { dg-error  "no match|rvalue" }
-  std::bind(&inc, std::ref(dummy))();	// { dg-error  "no match|const" }
+  std::bind(&inc, _1)(0);               // { dg-error  "no match" }
+  // { dg-error "rvalue|const" "" { target *-*-* } 1199 }
+  // { dg-error "rvalue|const" "" { target *-*-* } 1212 }
+  // { dg-error "rvalue|const" "" { target *-*-* } 1226 }
+  // { dg-error "rvalue|const" "" { target *-*-* } 1240 }
+  std::bind(&inc, std::ref(dummy))();	// { dg-error  "no match" }
 }
 
 struct Inc