diff mbox series

[C++] Another bunch of location fixes

Message ID ea639a5a-71da-8a02-c999-d100fc5c885b@oracle.com
State New
Headers show
Series [C++] Another bunch of location fixes | expand

Commit Message

Paolo Carlini Sept. 12, 2019, 2:41 p.m. UTC
Hi,

nothing special here, various bits I missed so far or in the past meant 
to test more thoroughly.

Thanks, Paolo.

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

	* decl.c (grokdeclarator): Use declspecs->locations and
	declarator->id_loc in a few error messages.
	* pt.c (finish_member_template_decl): Use DECL_SOURCE_LOCATION.
	(push_template_decl_real): Likewise.

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

	* g++.dg/ext/int128-6.C: New.
	* c-c++-common/pr68107.c: Test location(s).
	* g++.dg/other/large-size-array.C: Likewise.
	* g++.dg/template/dtor2.C: Likewise.
	* g++.dg/template/error9.C: Likewise.
	* g++.dg/tls/diag-2.C: Likewise.
	* g++.dg/tls/diag-4.C: Likewise.
	* g++.dg/tls/diag-5.C: Likewise.
	* g++.old-deja/g++.pt/memtemp71.C: Likewise.

Comments

Jason Merrill Sept. 15, 2019, 2:22 p.m. UTC | #1
On 9/12/19 9:41 AM, Paolo Carlini wrote:
> +	  if (!valid_array_size_p (dname
> +				   ? declarator->id_loc : input_location,

Use the id_loc local variable?

OK with that change.

Jason
Paolo Carlini Sept. 16, 2019, 9:22 a.m. UTC | #2
Hi,

On 15/09/19 16:22, Jason Merrill wrote:
> On 9/12/19 9:41 AM, Paolo Carlini wrote:
>> +      if (!valid_array_size_p (dname
>> +                   ? declarator->id_loc : input_location,
>
> Use the id_loc local variable?

This diagnostic is inside the loop over declarator->declarator. 
Eventually, outside the loop, the id_loc local is updated to the final 
declarator->id_loc or input_location. Norrmally in the loop we use the 
current declarator->id_loc: what I tested seems more correct to me (we 
have to account for input_location too because valid_array_size_p, 
shared with the C front-end, wants a sound location)

Paolo.
Jason Merrill Sept. 16, 2019, 3:42 p.m. UTC | #3
On Mon, Sep 16, 2019 at 5:22 AM Paolo Carlini <paolo.carlini@oracle.com> wrote:
>
> On 15/09/19 16:22, Jason Merrill wrote:
> > On 9/12/19 9:41 AM, Paolo Carlini wrote:
> >> +      if (!valid_array_size_p (dname
> >> +                   ? declarator->id_loc : input_location,
> >
> > Use the id_loc local variable?
>
> This diagnostic is inside the loop over declarator->declarator.
> Eventually, outside the loop, the id_loc local is updated to the final
> declarator->id_loc or input_location. Norrmally in the loop we use the
> current declarator->id_loc: what I tested seems more correct to me (we
> have to account for input_location too because valid_array_size_p,
> shared with the C front-end, wants a sound location)

OK.

Jason
diff mbox series

Patch

Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 275681)
+++ cp/decl.c	(working copy)
@@ -10948,14 +10948,15 @@  grokdeclarator (const cp_declarator *declarator,
     {
       if (! int_n_enabled_p[declspecs->int_n_idx])
 	{
-	  error ("%<__int%d%> is not supported by this target",
-		 int_n_data[declspecs->int_n_idx].bitsize);
+	  error_at (declspecs->locations[ds_type_spec],
+		    "%<__int%d%> is not supported by this target",
+		    int_n_data[declspecs->int_n_idx].bitsize);
 	  explicit_intN = false;
 	}
       /* Don't pedwarn if the alternate "__intN__" form has been used instead
 	 of "__intN".  */
       else if (!int_n_alt && pedantic && ! in_system_header_at (input_location))
-	pedwarn (input_location, OPT_Wpedantic,
+	pedwarn (declspecs->locations[ds_type_spec], OPT_Wpedantic,
 		 "ISO C++ does not support %<__int%d%> for %qs",
 		 int_n_data[declspecs->int_n_idx].bitsize, name);
     }
@@ -11330,7 +11331,10 @@  grokdeclarator (const cp_declarator *declarator,
 	   && storage_class != sc_static)
 	  || typedef_p))
     {
-      error ("multiple storage classes in declaration of %qs", name);
+      location_t loc
+	= min_location (declspecs->locations[ds_thread],
+			declspecs->locations[ds_storage_class]);
+      error_at (loc, "multiple storage classes in declaration of %qs", name);
       thread_p = false;
     }
   if (decl_context != NORMAL
@@ -11489,7 +11493,9 @@  grokdeclarator (const cp_declarator *declarator,
 	  type = create_array_type_for_decl (dname, type,
 					     declarator->u.array.bounds,
 					     declarator->id_loc);
-	  if (!valid_array_size_p (input_location, type, dname))
+	  if (!valid_array_size_p (dname
+				   ? declarator->id_loc : input_location,
+				   type, dname))
 	    type = error_mark_node;
 
 	  if (declarator->std_attributes)
Index: cp/pt.c
===================================================================
--- cp/pt.c	(revision 275681)
+++ cp/pt.c	(working copy)
@@ -298,7 +298,8 @@  finish_member_template_decl (tree decl)
       return NULL_TREE;
     }
   else if (TREE_CODE (decl) == FIELD_DECL)
-    error ("data member %qD cannot be a member template", decl);
+    error_at (DECL_SOURCE_LOCATION (decl),
+	      "data member %qD cannot be a member template", decl);
   else if (DECL_TEMPLATE_INFO (decl))
     {
       if (!DECL_TEMPLATE_SPECIALIZATION (decl))
@@ -310,7 +311,8 @@  finish_member_template_decl (tree decl)
 	return decl;
     }
   else
-    error ("invalid member template declaration %qD", decl);
+    error_at (DECL_SOURCE_LOCATION (decl),
+	      "invalid member template declaration %qD", decl);
 
   return error_mark_node;
 }
@@ -5515,7 +5517,8 @@  push_template_decl_real (tree decl, bool is_friend
 	      /* [temp.mem]
 
 		 A destructor shall not be a member template.  */
-	      error ("destructor %qD declared as member template", decl);
+	      error_at (DECL_SOURCE_LOCATION (decl),
+			"destructor %qD declared as member template", decl);
 	      return error_mark_node;
 	    }
 	  if (IDENTIFIER_NEWDEL_OP_P (DECL_NAME (decl))
Index: testsuite/c-c++-common/pr68107.c
===================================================================
--- testsuite/c-c++-common/pr68107.c	(revision 275681)
+++ testsuite/c-c++-common/pr68107.c	(working copy)
@@ -3,34 +3,34 @@ 
 
 #define N ((__SIZE_MAX__ / sizeof (int)) / 2 + 1)
 
-typedef int (*T1)[N]; /* { dg-error "exceeds maximum object size" } */
+typedef int (*T1)[N]; /* { dg-error "15:exceeds maximum object size" } */
 typedef int (*T2)[N - 1];
-typedef int (*T3)[N][N]; /* { dg-error "exceeds maximum object size" } */
-typedef int (*T4)[N - 1][N - 1]; /* { dg-error "exceeds maximum object size" } */
-typedef int (**T5)[N]; /* { dg-error "exceeds maximum object size" } */
+typedef int (*T3)[N][N]; /* { dg-error "15:exceeds maximum object size" } */
+typedef int (*T4)[N - 1][N - 1]; /* { dg-error "15:exceeds maximum object size" } */
+typedef int (**T5)[N]; /* { dg-error "16:exceeds maximum object size" } */
 
 struct S {
-  int (*q1)[N]; /* { dg-error "exceeds maximum object size" } */
+  int (*q1)[N]; /* { dg-error "9:exceeds maximum object size" } */
   int (*q2)[N - 1];
-  int (*q3)[N][N]; /* { dg-error "exceeds maximum object size" } */
-  int (*q4)[N - 1][N - 1]; /* { dg-error "exceeds maximum object size" } */
-  int (**q5)[N]; /* { dg-error "exceeds maximum object size" } */
+  int (*q3)[N][N]; /* { dg-error "9:exceeds maximum object size" } */
+  int (*q4)[N - 1][N - 1]; /* { dg-error "9:exceeds maximum object size" } */
+  int (**q5)[N]; /* { dg-error "10:exceeds maximum object size" } */
 };
 
-void fn1 (int (*p1)[N]); /* { dg-error "exceeds maximum object size" } */
+void fn1 (int (*p1)[N]); /* { dg-error "17:exceeds maximum object size" } */
 void fn2 (int (*p1)[N - 1]);
-void fn3 (int (*p3)[N][N]); /* { dg-error "exceeds maximum object size" } */
-void fn4 (int (*p4)[N - 1][N - 1]); /* { dg-error "exceeds maximum object size" } */
-void fn5 (int (**p5)[N]); /* { dg-error "exceeds maximum object size" } */
+void fn3 (int (*p3)[N][N]); /* { dg-error "17:exceeds maximum object size" } */
+void fn4 (int (*p4)[N - 1][N - 1]); /* { dg-error "17:exceeds maximum object size" } */
+void fn5 (int (**p5)[N]); /* { dg-error "18:exceeds maximum object size" } */
 
 void
 fn (void)
 {
-  int (*n1)[N]; /* { dg-error "exceeds maximum object size" } */
+  int (*n1)[N]; /* { dg-error "9:exceeds maximum object size" } */
   int (*n2)[N - 1];
-  int (*n3)[N][N]; /* { dg-error "exceeds maximum object size" } */
-  int (*n4)[N - 1][N - 1]; /* { dg-error "exceeds maximum object size" } */
-  int (**n5)[N]; /* { dg-error "exceeds maximum object size" } */
+  int (*n3)[N][N]; /* { dg-error "9:exceeds maximum object size" } */
+  int (*n4)[N - 1][N - 1]; /* { dg-error "9:exceeds maximum object size" } */
+  int (**n5)[N]; /* { dg-error "10:exceeds maximum object size" } */
 
   sizeof (int (*)[N]); /* { dg-error "exceeds maximum object size" } */
   sizeof (int [N]); /* { dg-error "exceeds maximum object size" } */
Index: testsuite/g++.dg/ext/int128-6.C
===================================================================
--- testsuite/g++.dg/ext/int128-6.C	(nonexistent)
+++ testsuite/g++.dg/ext/int128-6.C	(working copy)
@@ -0,0 +1,5 @@ 
+// { dg-do compile { target int128 } }
+
+__int128 i __attribute__((unused));  // { dg-error "1:ISO C\\+\\+ does not support" }
+
+unsigned __int128 ui __attribute__((unused));  // { dg-error "10:ISO C\\+\\+ does not support" }
Index: testsuite/g++.dg/other/large-size-array.C
===================================================================
--- testsuite/g++.dg/other/large-size-array.C	(revision 275681)
+++ testsuite/g++.dg/other/large-size-array.C	(working copy)
@@ -20,7 +20,7 @@  sub (int *a)
 int
 main (void)
 {
-  int a[DIM][DIM];  /* { dg-error "exceeds maximum object size" } */
+  int a[DIM][DIM];  /* { dg-error "7:exceeds maximum object size" } */
   return sub (&a[0][0]);  /* { dg-error "declared" } */
 }
 
Index: testsuite/g++.dg/template/dtor2.C
===================================================================
--- testsuite/g++.dg/template/dtor2.C	(revision 275681)
+++ testsuite/g++.dg/template/dtor2.C	(working copy)
@@ -1,7 +1,7 @@ 
 struct Foo
 {
     template <int i>
-    ~Foo() {} // { dg-error "" }
+    ~Foo() {} // { dg-error "5:destructor .Foo::~Foo\\\(\\\)." }
 };
 
 int main()
Index: testsuite/g++.dg/template/error9.C
===================================================================
--- testsuite/g++.dg/template/error9.C	(revision 275681)
+++ testsuite/g++.dg/template/error9.C	(working copy)
@@ -3,5 +3,5 @@ 
 struct Foo
 {
     template <int i>
-    ~Foo(); // { dg-error "" }
+    ~Foo(); // { dg-error "5:destructor .Foo::~Foo\\\(\\\)." }
 };
Index: testsuite/g++.dg/tls/diag-2.C
===================================================================
--- testsuite/g++.dg/tls/diag-2.C	(revision 275681)
+++ testsuite/g++.dg/tls/diag-2.C	(working copy)
@@ -4,14 +4,14 @@ 
 __thread extern int g1;		/* { dg-error "'__thread' before 'extern'" } */
 __thread static int g2;		/* { dg-error "'__thread' before 'static'" } */
 __thread __thread int g3;	/* { dg-error "duplicate '__thread'" } */
-typedef __thread int g4;	/* { dg-error "multiple storage classes" } */
+typedef __thread int g4;	/* { dg-error "9:multiple storage classes" } */
 
 void foo()
 {
   __thread int l1;		/* { dg-error "3:function-scope .l1. implicitly auto and declared '__thread'" } */
-  auto __thread int l2;		/* { dg-error "multiple storage classes|data types" } */
+  auto __thread int l2;		/* { dg-error "3:multiple storage classes|data types" } */
   __thread extern int l3;	/* { dg-error "'__thread' before 'extern'" } */
-  register __thread int l4;	/* { dg-error "multiple storage classes" } */
+  register __thread int l4;	/* { dg-error "3:multiple storage classes" } */
 }				/* { dg-error "ISO C\\+\\+17 does not allow 'register' storage class specifier" "" { target c++17 } .-1 } */
 
 __thread void f1 ();		/* { dg-error "1:storage class .__thread. invalid for function" } */
Index: testsuite/g++.dg/tls/diag-4.C
===================================================================
--- testsuite/g++.dg/tls/diag-4.C	(revision 275681)
+++ testsuite/g++.dg/tls/diag-4.C	(working copy)
@@ -1,10 +1,10 @@ 
 /* Invalid __thread specifiers.  */
 /* { dg-require-effective-target tls } */
 
-__thread typedef int g4;	/* { dg-error "multiple storage classes" } */
+__thread typedef int g4;	/* { dg-error "1:multiple storage classes" } */
 
 void foo()
 {
-  __thread auto int l2;		/* { dg-error "multiple storage classes|data types" } */
-  __thread register int l4;	/* { dg-error "multiple storage classes" } */
+  __thread auto int l2;		/* { dg-error "3:multiple storage classes|data types" } */
+  __thread register int l4;	/* { dg-error "3:multiple storage classes" } */
 }				/* { dg-error "ISO C\\+\\+17 does not allow 'register' storage class specifier" "" { target c++17 } .-1 } */
Index: testsuite/g++.dg/tls/diag-5.C
===================================================================
--- testsuite/g++.dg/tls/diag-5.C	(revision 275681)
+++ testsuite/g++.dg/tls/diag-5.C	(working copy)
@@ -2,4 +2,4 @@ 
 // Invalid __thread specifiers.
 // { dg-require-effective-target tls }
 
-struct A { __thread register int i; }; // { dg-error "multiple storage classes|storage class specified" }
+struct A { __thread register int i; }; // { dg-error "12:multiple storage classes|storage class specified" }
Index: testsuite/g++.old-deja/g++.pt/memtemp71.C
===================================================================
--- testsuite/g++.old-deja/g++.pt/memtemp71.C	(revision 275681)
+++ testsuite/g++.old-deja/g++.pt/memtemp71.C	(working copy)
@@ -2,5 +2,5 @@ 
 
 class A
 {
-  template<class T>T epsilon; // { dg-error "" } invalid member template
+  template<class T>T epsilon; // { dg-error "22:data member .epsilon. cannot be a member template" }
 };