diff mbox series

[C++] More grokdeclarator locations fixes

Message ID 69d03ed6-77cd-522b-3d8c-f87fd0d25db3@oracle.com
State New
Headers show
Series [C++] More grokdeclarator locations fixes | expand

Commit Message

Paolo Carlini Aug. 8, 2019, 9:41 a.m. UTC
Hi,

these are all more or less straightforward, exploit the existing 
infrastructure. Nits: the first change also removes an 'a' in the 
wording because all the other error messages - a few - mentioning class 
or namespace don't have it; the fixes using EXPR_LOCATION also change 
%qD to %qE because we are dealing with BIT_NOT_EXPRs.

Thanks, Paolo.

///////////////////
/cp
2019-08-08  Paolo Carlini  <paolo.carlini@oracle.com>

	* decl.c (grokdeclarator): Use id_loc and EXPR_LOCATION in
	a few error messages.

/testsuite
2019-08-08  Paolo Carlini  <paolo.carlini@oracle.com>

	* g++.dg/cpp0x/enum20.C: Test location(s) too.
	* g++.dg/other/friend3.C: Likewise.
	* g++.dg/parse/dtor5.C: Likewise.
	* g++.dg/parse/friend7.C: Likewise.
	* g++.dg/template/error22.C: Likewise.
	* g++.old-deja/g++.brendan/err-msg5.C: Likewise.

Comments

Jason Merrill Aug. 8, 2019, 2:54 p.m. UTC | #1
On 8/8/19 5:41 AM, Paolo Carlini wrote:
> Hi,
> 
> these are all more or less straightforward, exploit the existing 
> infrastructure. Nits: the first change also removes an 'a' in the 
> wording because all the other error messages - a few - mentioning class 
> or namespace don't have it; the fixes using EXPR_LOCATION also change 
> %qD to %qE because we are dealing with BIT_NOT_EXPRs.

OK.

Jason
diff mbox series

Patch

Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 274195)
+++ cp/decl.c	(working copy)
@@ -10579,7 +10579,8 @@  grokdeclarator (const cp_declarator *declarator,
 		    ctype = qualifying_scope;
 		    if (!MAYBE_CLASS_TYPE_P (ctype))
 		      {
-			error ("%q#T is not a class or a namespace", ctype);
+			error_at (id_declarator->id_loc,
+				  "%q#T is not a class or namespace", ctype);
 			ctype = NULL_TREE;
 		      }
 		    else if (innermost_code != cdk_function
@@ -10601,13 +10602,15 @@  grokdeclarator (const cp_declarator *declarator,
 		{
 		  if (innermost_code != cdk_function)
 		    {
-		      error ("declaration of %qD as non-function", decl);
+		      error_at (EXPR_LOCATION (decl),
+				"declaration of %qE as non-function", decl);
 		      return error_mark_node;
 		    }
 		  else if (!qualifying_scope
 			   && !(current_class_type && at_class_scope_p ()))
 		    {
-		      error ("declaration of %qD as non-member", decl);
+		      error_at (EXPR_LOCATION (decl),
+				"declaration of %qE as non-member", decl);
 		      return error_mark_node;
 		    }
 
@@ -12510,7 +12513,7 @@  grokdeclarator (const cp_declarator *declarator,
 	else if (in_namespace && !friendp)
 	  {
 	    /* Something like struct S { int N::j; };  */
-	    error ("invalid use of %<::%>");
+	    error_at (id_loc, "invalid use of %<::%>");
 	    return error_mark_node;
 	  }
 	else if (FUNC_OR_METHOD_TYPE_P (type) && unqualified_id)
@@ -12565,15 +12568,15 @@  grokdeclarator (const cp_declarator *declarator,
 		if (!ctype)
 		  {
 		    gcc_assert (friendp);
-		    error ("expected qualified name in friend declaration "
-			   "for destructor %qD", uqname);
+		    error_at (id_loc, "expected qualified name in friend "
+			      "declaration for destructor %qD", uqname);
 		    return error_mark_node;
 		  }
 
 		if (!check_dtor_name (ctype, TREE_OPERAND (uqname, 0)))
 		  {
-		    error ("declaration of %qD as member of %qT",
-			   uqname, ctype);
+		    error_at (id_loc, "declaration of %qD as member of %qT",
+			      uqname, ctype);
 		    return error_mark_node;
 		  }
                 if (concept_p)
Index: testsuite/g++.dg/cpp0x/enum20.C
===================================================================
--- testsuite/g++.dg/cpp0x/enum20.C	(revision 274195)
+++ testsuite/g++.dg/cpp0x/enum20.C	(working copy)
@@ -2,4 +2,4 @@ 
 // { dg-do compile { target c++11 } }
 
 enum A { };
-void A::f() { }			// { dg-error "not a class" }
+void A::f() { }			// { dg-error "6:.enum A. is not a class" }
Index: testsuite/g++.dg/other/friend3.C
===================================================================
--- testsuite/g++.dg/other/friend3.C	(revision 274195)
+++ testsuite/g++.dg/other/friend3.C	(working copy)
@@ -4,10 +4,10 @@ 
 
 struct A
 {
-  friend ~A();  // { dg-error "qualified name" }
+  friend ~A();  // { dg-error "10:expected qualified name" }
 };
 
 struct B
 {
-  friend ~A();  // { dg-error "qualified name" }
+  friend ~A();  // { dg-error "10:expected qualified name" }
 };
Index: testsuite/g++.dg/parse/dtor5.C
===================================================================
--- testsuite/g++.dg/parse/dtor5.C	(revision 274195)
+++ testsuite/g++.dg/parse/dtor5.C	(working copy)
@@ -1,12 +1,12 @@ 
 // PR c++/19732
 
 struct A;
-typedef int ~A; // { dg-error "non-function" }
+typedef int ~A; // { dg-error "13:declaration of .~ A. as non-function" }
 struct B { 
-  ~A(); // { dg-error "" }
-  typedef int ~A; // { dg-error "non-function" }
+  ~A(); // { dg-error "3:declaration of .~A. as member of .B." }
+  typedef int ~A; // { dg-error "15:declaration of .~ A. as non-function" }
   void f() {
-    extern ~B(); // { dg-error "non-member" }
+    extern ~B(); // { dg-error "12:declaration of .~ B. as non-member" }
   }
 };
-void ~A(); // { dg-error "non-member" }
+void ~A(); // { dg-error "6:declaration of .~ A. as non-member" }
Index: testsuite/g++.dg/parse/friend7.C
===================================================================
--- testsuite/g++.dg/parse/friend7.C	(revision 274195)
+++ testsuite/g++.dg/parse/friend7.C	(working copy)
@@ -19,7 +19,8 @@  struct B
 struct C
 {
   friend int C ();
-  friend int ~C ();		// { dg-error "return type|in friend decl" }
+  friend int ~C ();		// { dg-error "10:return type" }
+  // { dg-error "14:expected qualified name in friend decl" "" { target *-*-* } .-1 }
   friend int C (const C &);
 };
 
@@ -26,7 +27,8 @@  struct C
 struct D
 {
   friend int D () {}
-  friend int ~D () {}		// { dg-error "return type|in friend decl" }
+  friend int ~D () {}		// { dg-error "10:return type" }
+  // { dg-error "14:expected qualified name in friend decl" "" { target *-*-* } .-1 }
   friend int D (const D &) {}
 };
 
Index: testsuite/g++.dg/template/error22.C
===================================================================
--- testsuite/g++.dg/template/error22.C	(revision 274195)
+++ testsuite/g++.dg/template/error22.C	(working copy)
@@ -3,7 +3,7 @@ 
 struct A
 {
     template<void (A::*)()> struct B {};
-    void ::foo(); // { dg-error "invalid use" }
+    void ::foo(); // { dg-error "10:invalid use" }
     B<&A::foo> b; // { dg-error "incomplete type|template argument" }
 };
  
Index: testsuite/g++.old-deja/g++.brendan/err-msg5.C
===================================================================
--- testsuite/g++.old-deja/g++.brendan/err-msg5.C	(revision 274195)
+++ testsuite/g++.old-deja/g++.brendan/err-msg5.C	(working copy)
@@ -1,4 +1,4 @@ 
 // { dg-do assemble  }
 // GROUPS passed error-messages
 class foo {};
-~foo () {}// { dg-error "" }  destructors must be member functions.*
+~foo () {}// { dg-error "1:declaration of .~ foo. as non-member" }  destructors must be member functions.*