diff mbox series

[C++] More grokdeclarator locations fixes

Message ID 814e2078-c135-56c8-201f-44ac9712dbc6@oracle.com
State New
Headers show
Series [C++] More grokdeclarator locations fixes | expand

Commit Message

Paolo Carlini June 10, 2019, 10:36 a.m. UTC
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.

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

Comments

Jason Merrill June 12, 2019, 7:49 p.m. UTC | #1
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
diff mbox series

Patch

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