This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C PATCH] Better location for -Wnested-externs (PR c/70791)


This patch improves the location info for -Wnested-externs.

Bootstrapped/regtested on x86_64-linux, applying to trunk.

2016-04-26  Marek Polacek  <polacek@redhat.com>

	PR c/70791
	* c-decl.c (pushdecl): Pass LOCUS down to warning.

	* gcc.dg/Wnested-externs-2.c: New test.

diff --git gcc/c/c-decl.c gcc/c/c-decl.c
index f0c677b..16e4250 100644
--- gcc/c/c-decl.c
+++ gcc/c/c-decl.c
@@ -2949,7 +2949,8 @@ pushdecl (tree x)
 	}
       if (scope != file_scope
 	  && !DECL_IN_SYSTEM_HEADER (x))
-	warning (OPT_Wnested_externs, "nested extern declaration of %qD", x);
+	warning_at (locus, OPT_Wnested_externs,
+		    "nested extern declaration of %qD", x);
 
       while (b && !B_IN_EXTERNAL_SCOPE (b))
 	{
diff --git gcc/testsuite/gcc.dg/Wnested-externs-2.c gcc/testsuite/gcc.dg/Wnested-externs-2.c
index e69de29..77bed5f 100644
--- gcc/testsuite/gcc.dg/Wnested-externs-2.c
+++ gcc/testsuite/gcc.dg/Wnested-externs-2.c
@@ -0,0 +1,11 @@
+/* PR c/70791 */
+/* { dg-do compile } */
+/* { dg-options "-Wnested-externs" } */
+
+void
+bar (void)
+{
+  extern int i; /* { dg-warning "14:nested extern declaration of 'i'" } */
+  extern short foo (void); /* { dg-warning "16:nested extern declaration of 'foo'" } */
+  extern struct S *s; /* { dg-warning "20:nested extern declaration of 's'" } */
+}

	Marek


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]