* [C PATCH] Use inform for "shadowed decl" (PR c/48062)
@ 2014-06-03 16:02 Marek Polacek
2014-06-03 16:07 ` Jakub Jelinek
0 siblings, 1 reply; 4+ messages in thread
From: Marek Polacek @ 2014-06-03 16:02 UTC (permalink / raw)
To: GCC Patches; +Cc: Joseph S. Myers
For "shadowed declaration" note we were calling warning_at, while we
should use inform.
Regtested/bootstrapped on x86_64-linux, ok for trunk?
2014-06-03 Marek Polacek <polacek@redhat.com>
PR c/48062
* c-decl.c (warn_if_shadowing): Call inform instead of warning_at.
* gcc.dg/Wshadow-1.c: Use dg-message for "shadowed declaration".
* gcc.dg/Wshadow-3.c: Likewise.
diff --git gcc/c/c-decl.c gcc/c/c-decl.c
index dc8dbc2..05ab20e 100644
--- gcc/c/c-decl.c
+++ gcc/c/c-decl.c
@@ -2635,8 +2635,8 @@ warn_if_shadowing (tree new_decl)
warning (OPT_Wshadow, "declaration of %q+D shadows a previous local",
new_decl);
- warning_at (DECL_SOURCE_LOCATION (old_decl), OPT_Wshadow,
- "shadowed declaration is here");
+ inform (DECL_SOURCE_LOCATION (old_decl),
+ "shadowed declaration is here");
break;
}
diff --git gcc/testsuite/gcc.dg/Wshadow-1.c gcc/testsuite/gcc.dg/Wshadow-1.c
index 40073f3..6075711 100644
--- gcc/testsuite/gcc.dg/Wshadow-1.c
+++ gcc/testsuite/gcc.dg/Wshadow-1.c
@@ -5,7 +5,7 @@
/* Source: Neil Booth, 5 Dec 2001. */
-int decl1; /* { dg-warning "shadowed declaration" } */
+int decl1; /* { dg-message "shadowed declaration" } */
void foo (double decl1) /* { dg-warning "shadows a global decl" } */
{
}
@@ -16,7 +16,7 @@ void foo1 (int d) /* { dg-message "note: previous definition" } */
/* { dg-error "redeclared as different" "" { target *-*-* } 15 } */
}
-void foo2 (int d) /* { dg-warning "shadowed declaration" } */
+void foo2 (int d) /* { dg-message "shadowed declaration" } */
{
{
double d; /* { dg-warning "shadows a parameter" } */
@@ -25,7 +25,7 @@ void foo2 (int d) /* { dg-warning "shadowed declaration" } */
void foo3 ()
{
- int local; /* { dg-warning "shadowed declaration" } */
+ int local; /* { dg-message "shadowed declaration" } */
{
int local; /* { dg-warning "shadows a previous local" } */
}
diff --git gcc/testsuite/gcc.dg/Wshadow-3.c gcc/testsuite/gcc.dg/Wshadow-3.c
index a7f06a2..ce2879c 100644
--- gcc/testsuite/gcc.dg/Wshadow-3.c
+++ gcc/testsuite/gcc.dg/Wshadow-3.c
@@ -5,7 +5,7 @@
/* { dg-do compile } */
/* { dg-options "-std=gnu89 -Wshadow" } */
-int v; /* { dg-warning "shadowed declaration" } */
+int v; /* { dg-message "shadowed declaration" } */
int f1(int v);
int f2(int v, int x[v]); /* { dg-warning "declaration of 'v' shadows a global declaration" } */
int f3(int v, int y[sizeof(v)]); /* { dg-warning "declaration of 'v' shadows a global declaration" } */
@@ -18,4 +18,4 @@ int f9(x) int x; { return 0; }
int f10(v) { return 0; } /* { dg-warning "declaration of 'v' shadows a global declaration" } */
int f11(int a, int b(int a));
int f12(int a, int b(int a, int x[a])); /* { dg-warning "declaration of 'a' shadows a parameter" } */
-/* { dg-warning "shadowed declaration" "outer parm" { target *-*-* } 20 } */
+/* { dg-message "shadowed declaration" "outer parm" { target *-*-* } 20 } */
Marek
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [C PATCH] Use inform for "shadowed decl" (PR c/48062)
2014-06-03 16:02 [C PATCH] Use inform for "shadowed decl" (PR c/48062) Marek Polacek
@ 2014-06-03 16:07 ` Jakub Jelinek
2014-06-03 17:01 ` Marek Polacek
0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2014-06-03 16:07 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches, Joseph S. Myers
On Tue, Jun 03, 2014 at 06:01:57PM +0200, Marek Polacek wrote:
> For "shadowed declaration" note we were calling warning_at, while we
> should use inform.
>
> Regtested/bootstrapped on x86_64-linux, ok for trunk?
Shouldn't you remember the return value from warning/warning_at calls
which fall through into this spot and guard the inform call with that?
Jakub
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [C PATCH] Use inform for "shadowed decl" (PR c/48062)
2014-06-03 16:07 ` Jakub Jelinek
@ 2014-06-03 17:01 ` Marek Polacek
2014-06-04 23:03 ` Joseph S. Myers
0 siblings, 1 reply; 4+ messages in thread
From: Marek Polacek @ 2014-06-03 17:01 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: GCC Patches, Joseph S. Myers
On Tue, Jun 03, 2014 at 06:07:03PM +0200, Jakub Jelinek wrote:
> On Tue, Jun 03, 2014 at 06:01:57PM +0200, Marek Polacek wrote:
> > For "shadowed declaration" note we were calling warning_at, while we
> > should use inform.
> >
> > Regtested/bootstrapped on x86_64-linux, ok for trunk?
>
> Shouldn't you remember the return value from warning/warning_at calls
> which fall through into this spot and guard the inform call with that?
Oops, yea, for the #pragma case. Fixed + testcase attached.
Ok?
2014-06-03 Marek Polacek <polacek@redhat.com>
PR c/48062
* c-decl.c (warn_if_shadowing): Call inform instead of warning_at.
Print note only if the warning was printed.
* gcc.dg/Wshadow-1.c: Use dg-message for "shadowed declaration".
* gcc.dg/Wshadow-3.c: Likewise.
* gcc.dg/pr48062.c: New test.
diff --git gcc/c/c-decl.c gcc/c/c-decl.c
index dc8dbc2..8fb3296 100644
--- gcc/c/c-decl.c
+++ gcc/c/c-decl.c
@@ -2601,6 +2601,7 @@ warn_if_shadowing (tree new_decl)
DECL_SOURCE_LOCATION (b->decl))))
{
tree old_decl = b->decl;
+ bool warned = false;
if (old_decl == error_mark_node)
{
@@ -2609,8 +2610,9 @@ warn_if_shadowing (tree new_decl)
break;
}
else if (TREE_CODE (old_decl) == PARM_DECL)
- warning (OPT_Wshadow, "declaration of %q+D shadows a parameter",
- new_decl);
+ warned = warning (OPT_Wshadow,
+ "declaration of %q+D shadows a parameter",
+ new_decl);
else if (DECL_FILE_SCOPE_P (old_decl))
{
/* Do not warn if a variable shadows a function, unless
@@ -2620,9 +2622,10 @@ warn_if_shadowing (tree new_decl)
&& !FUNCTION_POINTER_TYPE_P (TREE_TYPE (new_decl)))
continue;
- warning_at (DECL_SOURCE_LOCATION (new_decl), OPT_Wshadow,
- "declaration of %qD shadows a global declaration",
- new_decl);
+ warned = warning_at (DECL_SOURCE_LOCATION (new_decl), OPT_Wshadow,
+ "declaration of %qD shadows a global "
+ "declaration",
+ new_decl);
}
else if (TREE_CODE (old_decl) == FUNCTION_DECL
&& DECL_BUILT_IN (old_decl))
@@ -2632,11 +2635,12 @@ warn_if_shadowing (tree new_decl)
break;
}
else
- warning (OPT_Wshadow, "declaration of %q+D shadows a previous local",
- new_decl);
+ warned = warning (OPT_Wshadow, "declaration of %q+D shadows a "
+ "previous local", new_decl);
- warning_at (DECL_SOURCE_LOCATION (old_decl), OPT_Wshadow,
- "shadowed declaration is here");
+ if (warned)
+ inform (DECL_SOURCE_LOCATION (old_decl),
+ "shadowed declaration is here");
break;
}
diff --git gcc/testsuite/gcc.dg/Wshadow-1.c gcc/testsuite/gcc.dg/Wshadow-1.c
index 40073f3..6075711 100644
--- gcc/testsuite/gcc.dg/Wshadow-1.c
+++ gcc/testsuite/gcc.dg/Wshadow-1.c
@@ -5,7 +5,7 @@
/* Source: Neil Booth, 5 Dec 2001. */
-int decl1; /* { dg-warning "shadowed declaration" } */
+int decl1; /* { dg-message "shadowed declaration" } */
void foo (double decl1) /* { dg-warning "shadows a global decl" } */
{
}
@@ -16,7 +16,7 @@ void foo1 (int d) /* { dg-message "note: previous definition" } */
/* { dg-error "redeclared as different" "" { target *-*-* } 15 } */
}
-void foo2 (int d) /* { dg-warning "shadowed declaration" } */
+void foo2 (int d) /* { dg-message "shadowed declaration" } */
{
{
double d; /* { dg-warning "shadows a parameter" } */
@@ -25,7 +25,7 @@ void foo2 (int d) /* { dg-warning "shadowed declaration" } */
void foo3 ()
{
- int local; /* { dg-warning "shadowed declaration" } */
+ int local; /* { dg-message "shadowed declaration" } */
{
int local; /* { dg-warning "shadows a previous local" } */
}
diff --git gcc/testsuite/gcc.dg/Wshadow-3.c gcc/testsuite/gcc.dg/Wshadow-3.c
index a7f06a2..ce2879c 100644
--- gcc/testsuite/gcc.dg/Wshadow-3.c
+++ gcc/testsuite/gcc.dg/Wshadow-3.c
@@ -5,7 +5,7 @@
/* { dg-do compile } */
/* { dg-options "-std=gnu89 -Wshadow" } */
-int v; /* { dg-warning "shadowed declaration" } */
+int v; /* { dg-message "shadowed declaration" } */
int f1(int v);
int f2(int v, int x[v]); /* { dg-warning "declaration of 'v' shadows a global declaration" } */
int f3(int v, int y[sizeof(v)]); /* { dg-warning "declaration of 'v' shadows a global declaration" } */
@@ -18,4 +18,4 @@ int f9(x) int x; { return 0; }
int f10(v) { return 0; } /* { dg-warning "declaration of 'v' shadows a global declaration" } */
int f11(int a, int b(int a));
int f12(int a, int b(int a, int x[a])); /* { dg-warning "declaration of 'a' shadows a parameter" } */
-/* { dg-warning "shadowed declaration" "outer parm" { target *-*-* } 20 } */
+/* { dg-message "shadowed declaration" "outer parm" { target *-*-* } 20 } */
diff --git gcc/testsuite/gcc.dg/pr48062.c gcc/testsuite/gcc.dg/pr48062.c
index e69de29..0f4cdde 100644
--- gcc/testsuite/gcc.dg/pr48062.c
+++ gcc/testsuite/gcc.dg/pr48062.c
@@ -0,0 +1,13 @@
+/* PR c/48062 */
+/* { dg-do compile } */
+/* { dg-options "-Wshadow" } */
+
+int
+main (void)
+{
+ int i; /* { dg-bogus "shadowed declaration" } */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wshadow"
+ { int i; }
+#pragma GCC diagnostic pop
+}
Marek
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [C PATCH] Use inform for "shadowed decl" (PR c/48062)
2014-06-03 17:01 ` Marek Polacek
@ 2014-06-04 23:03 ` Joseph S. Myers
0 siblings, 0 replies; 4+ messages in thread
From: Joseph S. Myers @ 2014-06-04 23:03 UTC (permalink / raw)
To: Marek Polacek; +Cc: Jakub Jelinek, GCC Patches
On Tue, 3 Jun 2014, Marek Polacek wrote:
> On Tue, Jun 03, 2014 at 06:07:03PM +0200, Jakub Jelinek wrote:
> > On Tue, Jun 03, 2014 at 06:01:57PM +0200, Marek Polacek wrote:
> > > For "shadowed declaration" note we were calling warning_at, while we
> > > should use inform.
> > >
> > > Regtested/bootstrapped on x86_64-linux, ok for trunk?
> >
> > Shouldn't you remember the return value from warning/warning_at calls
> > which fall through into this spot and guard the inform call with that?
>
> Oops, yea, for the #pragma case. Fixed + testcase attached.
>
> Ok?
OK.
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-06-04 23:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-03 16:02 [C PATCH] Use inform for "shadowed decl" (PR c/48062) Marek Polacek
2014-06-03 16:07 ` Jakub Jelinek
2014-06-03 17:01 ` Marek Polacek
2014-06-04 23:03 ` Joseph S. Myers
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).