public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ Patch] More grokdeclarator locations fixes
@ 2019-08-08 10:18 Paolo Carlini
  2019-08-08 15:09 ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Paolo Carlini @ 2019-08-08 10:18 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 374 bytes --]

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.

///////////////////


[-- Attachment #2: CL_locs_41 --]
[-- Type: text/plain, Size: 456 bytes --]

/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.

[-- Attachment #3: patch_locs_41 --]
[-- Type: text/plain, Size: 5758 bytes --]

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.*

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [C++ Patch] More grokdeclarator locations fixes
  2019-08-08 10:18 [C++ Patch] More grokdeclarator locations fixes Paolo Carlini
@ 2019-08-08 15:09 ` Jason Merrill
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2019-08-08 15:09 UTC (permalink / raw)
  To: Paolo Carlini, gcc-patches

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [C++ Patch] More grokdeclarator locations fixes
  2019-06-10 10:36 Paolo Carlini
@ 2019-06-12 19:49 ` Jason Merrill
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2019-06-12 19:49 UTC (permalink / raw)
  To: Paolo Carlini, gcc-patches

On 6/10/19 6:36 AM, Paolo Carlini wrote:
> Hi,
> 
> this one requires my last patch, uses id_loc in a few additional places 
> in the last part of the function.
> 
> Most of the changes should be straightforward, I only want to mention 
> the "typedef name may not be a nested-name-specifier" change, where, not 
> using input_location means that for a test like 
> g++.old-deja/g++.jason/crash10.C:
> 
> struct A {
>    enum foo { bar };
> };
> 
> typedef A::foo A::foo;
> 
> the location is under the 'A' of the second 'A::foo'. The EDG front-end 
> does exactly the same; clang points to the 'f' but then has the wavy 
> thing reaching back to 'A' (a while ago I already mentioned that we 
> don't have that option). Tested x86_64-linux.

OK.

Jason

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [C++ Patch] More grokdeclarator locations fixes
@ 2019-06-10 10:36 Paolo Carlini
  2019-06-12 19:49 ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Paolo Carlini @ 2019-06-10 10:36 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 703 bytes --]

Hi,

this one requires my last patch, uses id_loc in a few additional places 
in the last part of the function.

Most of the changes should be straightforward, I only want to mention 
the "typedef name may not be a nested-name-specifier" change, where, not 
using input_location means that for a test like 
g++.old-deja/g++.jason/crash10.C:

struct A {
   enum foo { bar };
};

typedef A::foo A::foo;

the location is under the 'A' of the second 'A::foo'. The EDG front-end 
does exactly the same; clang points to the 'f' but then has the wavy 
thing reaching back to 'A' (a while ago I already mentioned that we 
don't have that option). Tested x86_64-linux.

Thanks, Paolo.

/////////////////////


[-- Attachment #2: CL_locs_35 --]
[-- Type: text/plain, Size: 731 bytes --]

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

	* decl.c (grokdeclarator): Use id_loc in five additional places
	in the last part of the function.

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

	* g++.dg/diagnostic/variably-modified-type-1.C: New.
	* g++.dg/cpp0x/alias-decl-1.C: Test the location too.
	* g++.dg/other/pr84792-1.C: Likewise.
	* g++.dg/other/pr84792-2.C: Likewise.
	* g++.dg/parse/error24.C: Likewise.
	* g++.dg/parse/error32.C: Likewise.
	* g++.dg/parse/error33.C: Likewise.
	* g++.dg/parse/saved1.C: Likewise.
	* g++.dg/template/operator6.C: Likewise.
	* g++.dg/template/pr61745.C: Likewise.
	* g++.dg/template/typedef41.C: Likewise.
	* g++.old-deja/g++.jason/crash10.C: Likewise.

[-- Attachment #3: patch_locs_35 --]
[-- Type: text/plain, Size: 7813 bytes --]

Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 272105)
+++ cp/decl.c	(working copy)
@@ -12000,9 +12000,11 @@ grokdeclarator (const cp_declarator *declarator,
       && variably_modified_type_p (type, NULL_TREE))
     {
       if (decl_context == FIELD)
-	error ("data member may not have variably modified type %qT", type);
+	error_at (id_loc,
+		  "data member may not have variably modified type %qT", type);
       else
-	error ("parameter may not have variably modified type %qT", type);
+	error_at (id_loc,
+		  "parameter may not have variably modified type %qT", type);
       type = error_mark_node;
     }
 
@@ -12106,7 +12108,7 @@ grokdeclarator (const cp_declarator *declarator,
 
       if (id_declarator && declarator->u.id.qualifying_scope)
 	{
-	  error ("typedef name may not be a nested-name-specifier");
+	  error_at (id_loc, "typedef name may not be a nested-name-specifier");
 	  type = error_mark_node;
 	}
 
@@ -12130,7 +12132,7 @@ grokdeclarator (const cp_declarator *declarator,
 	}
       else if (current_class_type
 	       && constructor_name_p (unqualified_id, current_class_type))
-	permerror (input_location, "ISO C++ forbids nested type %qD with same name "
+	permerror (id_loc, "ISO C++ forbids nested type %qD with same name "
 		   "as enclosing class",
 		   unqualified_id);
 
@@ -12288,7 +12290,7 @@ grokdeclarator (const cp_declarator *declarator,
       /* Only functions may be declared using an operator-function-id.  */
       if (dname && IDENTIFIER_ANY_OP_P (dname))
 	{
-	  error ("declaration of %qD as non-function", dname);
+	  error_at (id_loc, "declaration of %qD as non-function", dname);
 	  return error_mark_node;
 	}
 
Index: testsuite/g++.dg/cpp0x/alias-decl-1.C
===================================================================
--- testsuite/g++.dg/cpp0x/alias-decl-1.C	(revision 272105)
+++ testsuite/g++.dg/cpp0x/alias-decl-1.C	(working copy)
@@ -11,5 +11,6 @@ template <class U> using Ptr = U*;
 template<class U> struct Ptr<U*> {}; // { dg-error "specialization" }
 
 struct A {
-    using A = int;//{ dg-error "nested|has|same name as|class|in which|declared" }
+    using A = int;  // { dg-error "11:ISO C\\+\\+ forbids nested type .A." }
+// { dg-error "same name as" "" { target c++11 } .-1 }  
 };
Index: testsuite/g++.dg/diagnostic/variably-modified-type-1.C
===================================================================
--- testsuite/g++.dg/diagnostic/variably-modified-type-1.C	(nonexistent)
+++ testsuite/g++.dg/diagnostic/variably-modified-type-1.C	(working copy)
@@ -0,0 +1,12 @@
+// { dg-options "" }
+
+void foo ()
+{
+  int n;
+  typedef int X[n];
+  struct Z
+  {
+    X x __attribute__((unused)); // { dg-error "7:data member may not have variably modified type" }
+    void bar (X x __attribute__((unused))); // { dg-error "17:parameter may not have variably modified type" }
+  };
+}
Index: testsuite/g++.dg/other/pr84792-1.C
===================================================================
--- testsuite/g++.dg/other/pr84792-1.C	(revision 272105)
+++ testsuite/g++.dg/other/pr84792-1.C	(working copy)
@@ -3,4 +3,4 @@ struct A {};
 typedef struct
 {
   virtual void foo() {}
-} A::B;  // { dg-error "typedef" }
+} A::B;  // { dg-error "3:typedef" }
Index: testsuite/g++.dg/other/pr84792-2.C
===================================================================
--- testsuite/g++.dg/other/pr84792-2.C	(revision 272105)
+++ testsuite/g++.dg/other/pr84792-2.C	(working copy)
@@ -3,4 +3,4 @@ struct A {};
 typedef struct
 {
   void foo() {}
-} A::B;  // { dg-error "typedef" }
+} A::B;  // { dg-error "3:typedef" }
Index: testsuite/g++.dg/parse/error24.C
===================================================================
--- testsuite/g++.dg/parse/error24.C	(revision 272105)
+++ testsuite/g++.dg/parse/error24.C	(working copy)
@@ -2,7 +2,7 @@
 // PR c++/19395
 
 struct A {
-  typedef int ::X; // { dg-error "17:typedef name may not be a nested-name-specifier" }
+  typedef int ::X; // { dg-error "15:typedef name may not be a nested-name-specifier" }
 };
 
 
Index: testsuite/g++.dg/parse/error32.C
===================================================================
--- testsuite/g++.dg/parse/error32.C	(revision 272105)
+++ testsuite/g++.dg/parse/error32.C	(working copy)
@@ -3,7 +3,7 @@
 
 struct A {};
 
-typedef void (A::T)(); /* { dg-error "typedef name may not be a nested-name-specifier" } */
+typedef void (A::T)(); /* { dg-error "15:typedef name may not be a nested-name-specifier" } */
 
 void foo()
 {
Index: testsuite/g++.dg/parse/error33.C
===================================================================
--- testsuite/g++.dg/parse/error33.C	(revision 272105)
+++ testsuite/g++.dg/parse/error33.C	(working copy)
@@ -6,7 +6,7 @@ struct A
   void foo();
 };
 
-typedef void (A::T)(); /* { dg-error "typedef name may not be a nested" } */
+typedef void (A::T)(); /* { dg-error "15:typedef name may not be a nested" } */
 
 void bar(T); /* { dg-message "note: declared here" } */
 
Index: testsuite/g++.dg/parse/saved1.C
===================================================================
--- testsuite/g++.dg/parse/saved1.C	(revision 272105)
+++ testsuite/g++.dg/parse/saved1.C	(working copy)
@@ -1,6 +1,7 @@
 // Test that the parser doesn't go into an infinite loop from ignoring the
 // PRE_PARSED_FUNCTION_DECL token.
 
-class C { static void* operator new(size_t); }; // { dg-error "" }
+class C { static void* operator new(size_t); }; // { dg-error "24:declaration of .operator new. as non-function" }
+// { dg-error "expected|ISO C\\+\\+ forbids" "" { target *-*-* } .-1 }
 void* C::operator new(size_t) { return 0; } // { dg-error "" }
 class D { D(int i): integer(i){}}; // { dg-error "" }
Index: testsuite/g++.dg/template/operator6.C
===================================================================
--- testsuite/g++.dg/template/operator6.C	(revision 272105)
+++ testsuite/g++.dg/template/operator6.C	(working copy)
@@ -1,4 +1,4 @@
 // PR c++/27315
 // { dg-do compile }
 
-template void operator+; // { dg-error "non-function" }
+template void operator+; // { dg-error "15:declaration of .operator\\+. as non-function" }
Index: testsuite/g++.dg/template/pr61745.C
===================================================================
--- testsuite/g++.dg/template/pr61745.C	(revision 272105)
+++ testsuite/g++.dg/template/pr61745.C	(working copy)
@@ -20,5 +20,6 @@ class Zp {
   Zp  operator-() const { return Zp(p-val); }
   // In C++2A, we have an unqualified-id (operator-) followed by
   // '<', and name lookup found a function.
-  friend Zp<INT,P> operator- <>(const Zp<INT,P>& a, const Zp<INT,P>& b); // { dg-error "declaration|expected" "" { target c++17_down } }
+  friend Zp<INT,P> operator- <>(const Zp<INT,P>& a, const Zp<INT,P>& b); // { dg-error "20:declaration of .operator\\-. as non-function" "" { target c++17_down } }
+  // { dg-error "expected" "" { target c++17_down } .-1 }
 };
Index: testsuite/g++.dg/template/typedef41.C
===================================================================
--- testsuite/g++.dg/template/typedef41.C	(revision 272105)
+++ testsuite/g++.dg/template/typedef41.C	(working copy)
@@ -2,7 +2,7 @@
 
 template<int> struct A
 {
-  typedef int ::X;		// { dg-error "" }
+  typedef int ::X;		// { dg-error "15:typedef name" }
 };
 
 A<0> a;
Index: testsuite/g++.old-deja/g++.jason/crash10.C
===================================================================
--- testsuite/g++.old-deja/g++.jason/crash10.C	(revision 272105)
+++ testsuite/g++.old-deja/g++.jason/crash10.C	(working copy)
@@ -5,4 +5,4 @@ struct A {
   enum foo { bar };
 };
 
-typedef A::foo A::foo;		// { dg-error "" } causes compiler segfault
+typedef A::foo A::foo;		// { dg-error "16:typedef name" } causes compiler segfault

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-08-08 14:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-08 10:18 [C++ Patch] More grokdeclarator locations fixes Paolo Carlini
2019-08-08 15:09 ` Jason Merrill
  -- strict thread matches above, loose matches on Subject: below --
2019-06-10 10:36 Paolo Carlini
2019-06-12 19:49 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).