diff mbox series

[C++] Improve locations in flexible array members diagnostic

Message ID 4dd5ad72-6381-5f50-8e6b-d239ca08ff36@oracle.com
State New
Headers show
Series [C++] Improve locations in flexible array members diagnostic | expand

Commit Message

Paolo Carlini Oct. 30, 2018, 3:23 p.m. UTC
Hi,

today I noticed quite a few additional places where we can exploit 
declarator->id_loc, the below are the first bits. Tested x86_64-linux.

Thanks, Paolo.

//////////////////////
/cp
2018-10-30  Paolo Carlini  <paolo.carlini@oracle.com>

	* decl.c (grokdeclarator): Use declarator->id_loc in diagnostic
	about flexible array members.

/testsuite
2018-10-30  Paolo Carlini  <paolo.carlini@oracle.com>

	* g++.dg/cpp1z/has-unique-obj-representations1.C: Test location too.
	* g++.dg/ext/flexarray-mangle-2.C: Likewise.
	* g++.dg/ext/flexarray-mangle.C: Likewise.
	* g++.dg/ext/flexarray-subst.C: Likewise.
	* g++.dg/ext/flexary10.C: Likewise.
	* g++.dg/ext/flexary11.C: Likewise.
	* g++.dg/ext/flexary14.C: Likewise.
	* g++.dg/ext/flexary16.C: Likewise.
	* g++.dg/ext/flexary26.C: Likewise.
	* g++.dg/ext/flexary27.C: Likewise.
	* g++.dg/ext/flexary7.C: Likewise.
	* g++.dg/ext/pr71290.C: Likewise.

Comments

Jason Merrill Oct. 30, 2018, 3:49 p.m. UTC | #1
OK.
On Tue, Oct 30, 2018 at 11:23 AM Paolo Carlini <paolo.carlini@oracle.com> wrote:
>
> Hi,
>
> today I noticed quite a few additional places where we can exploit
> declarator->id_loc, the below are the first bits. Tested x86_64-linux.
>
> Thanks, Paolo.
>
> //////////////////////
>
diff mbox series

Patch

Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 265616)
+++ cp/decl.c	(working copy)
@@ -12210,7 +12223,7 @@  grokdeclarator (const cp_declarator *declarator,
 		  /* Do not warn on flexible array members in system
 		     headers because glibc uses them.  */;
 		else if (name)
-		  pedwarn (input_location, OPT_Wpedantic,
+		  pedwarn (declarator->id_loc, OPT_Wpedantic,
 			   "ISO C++ forbids flexible array member %qs", name);
 		else
 		  pedwarn (input_location, OPT_Wpedantic,
Index: testsuite/g++.dg/cpp1z/has-unique-obj-representations1.C
===================================================================
--- testsuite/g++.dg/cpp1z/has-unique-obj-representations1.C	(revision 265616)
+++ testsuite/g++.dg/cpp1z/has-unique-obj-representations1.C	(working copy)
@@ -9,7 +9,7 @@  struct V { int i : INTB * 3 / 4; int j : INTB / 4
 struct W {};
 struct X : public W { int i; void bar (); };
 struct Y {
-  char a[3]; char b[];   // { dg-warning "forbids flexible array member" }
+  char a[3]; char b[];   // { dg-warning "19:ISO C\\+\\+ forbids flexible array member" }
 };
 struct Z { int a; float b; };
 struct A { int i : INTB * 2; int j; };			// { dg-warning "exceeds its type" }
Index: testsuite/g++.dg/ext/flexarray-mangle-2.C
===================================================================
--- testsuite/g++.dg/ext/flexarray-mangle-2.C	(revision 265616)
+++ testsuite/g++.dg/ext/flexarray-mangle-2.C	(working copy)
@@ -4,7 +4,7 @@ 
 
 struct A {
   int n;
-  char a[];   // { dg-warning "forbids flexible array member" }
+  char a[];   // { dg-warning "8:ISO C\\+\\+ forbids flexible array member" }
 };
 
 // Declare but do not define function templates.
Index: testsuite/g++.dg/ext/flexarray-mangle.C
===================================================================
--- testsuite/g++.dg/ext/flexarray-mangle.C	(revision 265616)
+++ testsuite/g++.dg/ext/flexarray-mangle.C	(working copy)
@@ -4,7 +4,7 @@ 
 
 struct A {
   int n;
-  char a[];   // { dg-warning "forbids flexible array member" }
+  char a[];   // { dg-warning "8:ISO C\\+\\+ forbids flexible array member" }
 };
 
 // Declare but do not define function templates.
Index: testsuite/g++.dg/ext/flexarray-subst.C
===================================================================
--- testsuite/g++.dg/ext/flexarray-subst.C	(revision 265616)
+++ testsuite/g++.dg/ext/flexarray-subst.C	(working copy)
@@ -5,7 +5,7 @@ 
 
 struct A {
   int n;
-  char a[];   // { dg-warning "forbids flexible array member" }
+  char a[];   // { dg-warning "8:ISO C\\+\\+ forbids flexible array member" }
 };
 
 template <class>
Index: testsuite/g++.dg/ext/flexary10.C
===================================================================
--- testsuite/g++.dg/ext/flexary10.C	(revision 265616)
+++ testsuite/g++.dg/ext/flexary10.C	(working copy)
@@ -4,7 +4,7 @@ 
 
 struct A {
   int n;
-  int a[];  // { dg-warning "forbids flexible array member" }
+  int a[];  // { dg-warning "7:ISO C\\+\\+ forbids flexible array member" }
 };
 
 struct A foo (void)
Index: testsuite/g++.dg/ext/flexary11.C
===================================================================
--- testsuite/g++.dg/ext/flexary11.C	(revision 265616)
+++ testsuite/g++.dg/ext/flexary11.C	(working copy)
@@ -4,7 +4,7 @@ 
 
 struct A {
   int n;
-  char a[];   // { dg-error "forbids flexible array member" }
+  char a[];   // { dg-error "8:ISO C\\+\\+ forbids flexible array member" }
 };
 
 void f ()
Index: testsuite/g++.dg/ext/flexary14.C
===================================================================
--- testsuite/g++.dg/ext/flexary14.C	(revision 265616)
+++ testsuite/g++.dg/ext/flexary14.C	(working copy)
@@ -10,7 +10,7 @@  struct A<T[]> { typedef int X; };
 template <class T> int foo (T&, typename A<T>::X = 0) { return 0; }
 
 struct B {
-  int n, a[];     // { dg-error "forbids flexible array member" }
+  int n, a[];     // { dg-error "10:ISO C\\+\\+ forbids flexible array member" }
 };
 
 void bar (B *b)
Index: testsuite/g++.dg/ext/flexary16.C
===================================================================
--- testsuite/g++.dg/ext/flexary16.C	(revision 265616)
+++ testsuite/g++.dg/ext/flexary16.C	(working copy)
@@ -12,7 +12,7 @@  struct container
 
   struct incomplete {
     int x;
-    elem array[];  // { dg-warning "forbids flexible array member" }
+    elem array[];  // { dg-warning "10:ISO C\\+\\+ forbids flexible array member" }
   };
 };
 
@@ -27,7 +27,7 @@  struct D: container<T>
 {
   struct S {
     int x;
-    typename container<T>::elem array[];  // { dg-warning "forbids flexible array member" }
+    typename container<T>::elem array[];  // { dg-warning "33:ISO C\\+\\+ forbids flexible array member" }
   };
 };
 
Index: testsuite/g++.dg/ext/flexary26.C
===================================================================
--- testsuite/g++.dg/ext/flexary26.C	(revision 265616)
+++ testsuite/g++.dg/ext/flexary26.C	(working copy)
@@ -2,8 +2,8 @@ 
 // { dg-do compile }
 // { dg-options "-Wpedantic" }
 
-struct S { const char *a; char b[]; };	// { dg-warning "forbids flexible array member" }
-struct T { int a; int b[]; };	// { dg-warning "forbids flexible array member" }
+struct S { const char *a; char b[]; };	// { dg-warning "32:ISO C\\+\\+ forbids flexible array member" }
+struct T { int a; int b[]; };	// { dg-warning "23:ISO C\\+\\+ forbids flexible array member" }
 #if __cplusplus >= 201103L
 S c[] { "", "" };		// { dg-error "initialization of flexible array member in a nested context" "" { target c++11 } }
 				// { dg-warning "initialization of a flexible array member" "" { target c++11 } .-1 }
Index: testsuite/g++.dg/ext/flexary27.C
===================================================================
--- testsuite/g++.dg/ext/flexary27.C	(revision 265616)
+++ testsuite/g++.dg/ext/flexary27.C	(working copy)
@@ -1,8 +1,8 @@ 
 // PR c++/81922
 // { dg-do compile }
 
-struct S { const char *a; char b[]; };	// { dg-error "forbids flexible array member" }
-struct T { int a; int b[]; };	// { dg-error "forbids flexible array member" }
+struct S { const char *a; char b[]; };	// { dg-error "32:ISO C\\+\\+ forbids flexible array member" }
+struct T { int a; int b[]; };	// { dg-error "23:ISO C\\+\\+ forbids flexible array member" }
 #if __cplusplus >= 201103L
 S c[] { "", "" };		// { dg-error "initialization of flexible array member in a nested context" "" { target c++11 } }
 				// { dg-error "initialization of a flexible array member" "" { target c++11 } .-1 }
Index: testsuite/g++.dg/ext/flexary7.C
===================================================================
--- testsuite/g++.dg/ext/flexary7.C	(revision 265616)
+++ testsuite/g++.dg/ext/flexary7.C	(working copy)
@@ -5,7 +5,7 @@ 
 
 struct FlexChar {
     int n;
-    char a[];       // { dg-warning "forbids flexible array member" }
+    char a[];       // { dg-warning "10:ISO C\\+\\+ forbids flexible array member" }
 };
 
 struct FlexChar ac =
@@ -18,7 +18,7 @@  typedef __WCHAR_TYPE__ wchar_t;
 
 struct FlexWchar {
     int n;
-    wchar_t a[];    // { dg-warning "forbids flexible array member" }
+    wchar_t a[];    // { dg-warning "13:ISO C\\+\\+ forbids flexible array member" }
 };
 
 struct FlexWchar awc =
@@ -27,7 +27,7 @@  struct FlexWchar awc =
 
 struct FlexInt {
     int n;
-    int a[];        // { dg-warning "forbids flexible array member" }
+    int a[];        // { dg-warning "9:ISO C\\+\\+ forbids flexible array member" }
 };
 
 // Verify that no warning is issued for the case when a flexible array
@@ -48,7 +48,7 @@  struct FlexInt ai2 =
 template <class T>
 struct FlexT {
     int n;
-    T a[];          // { dg-warning "forbids flexible array member" }
+    T a[];          // { dg-warning "7:ISO C\\+\\+ forbids flexible array member" }
 };
 
 struct FlexT<char> atc =
Index: testsuite/g++.dg/ext/pr71290.C
===================================================================
--- testsuite/g++.dg/ext/pr71290.C	(revision 265616)
+++ testsuite/g++.dg/ext/pr71290.C	(working copy)
@@ -1,17 +1,17 @@ 
 // PR c++/71290 - [6/7 Regression] Flexible array member is not diagnosed
 // with -pedantic
 
-// { dg-do compile }s
+// { dg-do compile }
 // { dg-options "-Wall -Wpedantic" }
 
 struct A
 {
   int i;
-  int arr[];   // { dg-warning "forbids flexible array member .arr." }
+  int arr[];   // { dg-warning "7:ISO C\\+\\+ forbids flexible array member .arr." }
 };
 
 template <class T>
 struct B {
   T n;
-  T a[];       // { dg-warning "forbids flexible array member .a." }
+  T a[];       // { dg-warning "5:ISO C\\+\\+ forbids flexible array member .a." }
 };