public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/48062] New: `shadowed declaration is here' should be a note
@ 2011-03-10 16:42 d.g.gorbachev at gmail dot com
  2011-03-10 18:44 ` [Bug c/48062] " manu at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: d.g.gorbachev at gmail dot com @ 2011-03-10 16:42 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48062

           Summary: `shadowed declaration is here' should be a note
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: trivial
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: d.g.gorbachev@gmail.com


cat > main.c
int i;

int main(void)
{
  int i = 0;
  return i;
}
^D
$ gcc -Wshadow main.c
main.c: In function 'main':
main.c:5:7: warning: declaration of 'i' shadows a global declaration [-Wshadow]
main.c:1:5: warning: shadowed declaration is here [-Wshadow]


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/48062] `shadowed declaration is here' should be a note
  2011-03-10 16:42 [Bug c/48062] New: `shadowed declaration is here' should be a note d.g.gorbachev at gmail dot com
@ 2011-03-10 18:44 ` manu at gcc dot gnu.org
  2011-06-09  1:46 ` momchil at xaxo dot eu
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu.org @ 2011-03-10 18:44 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48062

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011.03.10 18:44:34
                 CC|                            |manu at gcc dot gnu.org
     Ever Confirmed|0                           |1

--- Comment #1 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2011-03-10 18:44:34 UTC ---
This is a one liner that would qualify as obvious and it won't require
copyright assignment. Feel free to submit a patch!

(but it probably requires to adjust testcases, so run the testsuite and look
for new failures)


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/48062] `shadowed declaration is here' should be a note
  2011-03-10 16:42 [Bug c/48062] New: `shadowed declaration is here' should be a note d.g.gorbachev at gmail dot com
  2011-03-10 18:44 ` [Bug c/48062] " manu at gcc dot gnu.org
@ 2011-06-09  1:46 ` momchil at xaxo dot eu
  2011-06-09  7:55 ` manu at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: momchil at xaxo dot eu @ 2011-06-09  1:46 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48062

momchil at xaxo dot eu changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |momchil at xaxo dot eu

--- Comment #2 from momchil at xaxo dot eu 2011-06-09 01:46:43 UTC ---
Hi, there is an ambiguity here, consider the following examples:

$ cat > 1.c
int
main(void)
{
    int i;

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
    { int i; }
#pragma GCC diagnostic pop
}

$ gcc46 -Wshadow 1.c
1.c: In function 'main':
1.c:4:6: warning: shadowed declaration is here [-Wshadow]

Here I would suppose to see no warning at all, because I have turned it off for
the case that shadows. But:

$ cat > 2.c
int
main(void)
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
    int i;
#pragma GCC diagnostic pop

    {int i;}
}
$ gcc46 -Wshadow 2.c
2.c: In function 'main':
2.c:9:7: warning: declaration of 'i' shadows a previous local [-Wshadow]

And it is something that I whould also not expect. And now:

$ cat > 3.c
int
main(void)
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
    int i;
#pragma GCC diagnostic pop

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
    { int i; }
#pragma GCC diagnostic pop
}
$ gcc46 -Wshadow 3.c

Produces no warning. So for me it is a bit confusing, since the warning setting
refers to pieces of code and not to variables.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/48062] `shadowed declaration is here' should be a note
  2011-03-10 16:42 [Bug c/48062] New: `shadowed declaration is here' should be a note d.g.gorbachev at gmail dot com
  2011-03-10 18:44 ` [Bug c/48062] " manu at gcc dot gnu.org
  2011-06-09  1:46 ` momchil at xaxo dot eu
@ 2011-06-09  7:55 ` manu at gcc dot gnu.org
  2012-02-13 17:25 ` manu at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu.org @ 2011-06-09  7:55 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48062

--- Comment #3 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2011-06-09 07:55:37 UTC ---
(In reply to comment #2)
> Produces no warning. So for me it is a bit confusing, since the warning setting
> refers to pieces of code and not to variables.

You are right and it is a bug. The reason is that each warning message (the
second should be note) is produced by different calls to warning(). These calls
are conditional on Wshadow but the #pragmas only disable Wshadow for a certain
location. The fix is to make "shadowed declaration is here" a call to inform()
(that is, a note) conditional on the first warning being emitted, which one can
test by checking the return value of warning(). Patches welcome.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/48062] `shadowed declaration is here' should be a note
  2011-03-10 16:42 [Bug c/48062] New: `shadowed declaration is here' should be a note d.g.gorbachev at gmail dot com
                   ` (2 preceding siblings ...)
  2011-06-09  7:55 ` manu at gcc dot gnu.org
@ 2012-02-13 17:25 ` manu at gcc dot gnu.org
  2014-06-03 16:57 ` mpolacek at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu.org @ 2012-02-13 17:25 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48062

--- Comment #4 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-02-13 17:25:11 UTC ---
There is a patch in PR52116


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/48062] `shadowed declaration is here' should be a note
  2011-03-10 16:42 [Bug c/48062] New: `shadowed declaration is here' should be a note d.g.gorbachev at gmail dot com
                   ` (3 preceding siblings ...)
  2012-02-13 17:25 ` manu at gcc dot gnu.org
@ 2014-06-03 16:57 ` mpolacek at gcc dot gnu.org
  2014-06-05  5:31 ` mpolacek at gcc dot gnu.org
  2014-06-05  6:21 ` mpolacek at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-06-03 16:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48062

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |mpolacek at gcc dot gnu.org
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org
   Target Milestone|---                         |4.10.0

--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Mine.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/48062] `shadowed declaration is here' should be a note
  2011-03-10 16:42 [Bug c/48062] New: `shadowed declaration is here' should be a note d.g.gorbachev at gmail dot com
                   ` (4 preceding siblings ...)
  2014-06-03 16:57 ` mpolacek at gcc dot gnu.org
@ 2014-06-05  5:31 ` mpolacek at gcc dot gnu.org
  2014-06-05  6:21 ` mpolacek at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-06-05  5:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48062

--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Author: mpolacek
Date: Thu Jun  5 05:30:39 2014
New Revision: 211254

URL: http://gcc.gnu.org/viewcvs?rev=211254&root=gcc&view=rev
Log:
    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.

Added:
    trunk/gcc/testsuite/gcc.dg/pr48062.c
Modified:
    trunk/gcc/c/ChangeLog
    trunk/gcc/c/c-decl.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/Wshadow-1.c
    trunk/gcc/testsuite/gcc.dg/Wshadow-3.c


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/48062] `shadowed declaration is here' should be a note
  2011-03-10 16:42 [Bug c/48062] New: `shadowed declaration is here' should be a note d.g.gorbachev at gmail dot com
                   ` (5 preceding siblings ...)
  2014-06-05  5:31 ` mpolacek at gcc dot gnu.org
@ 2014-06-05  6:21 ` mpolacek at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-06-05  6:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48062

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-06-05  6:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-10 16:42 [Bug c/48062] New: `shadowed declaration is here' should be a note d.g.gorbachev at gmail dot com
2011-03-10 18:44 ` [Bug c/48062] " manu at gcc dot gnu.org
2011-06-09  1:46 ` momchil at xaxo dot eu
2011-06-09  7:55 ` manu at gcc dot gnu.org
2012-02-13 17:25 ` manu at gcc dot gnu.org
2014-06-03 16:57 ` mpolacek at gcc dot gnu.org
2014-06-05  5:31 ` mpolacek at gcc dot gnu.org
2014-06-05  6:21 ` mpolacek at gcc dot gnu.org

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