public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/56100] New: spurious -Wshadow warning with local variable in template class
@ 2013-01-24 21:11 f.heckenbach@fh-soft.de
  2013-01-24 21:15 ` [Bug c++/56100] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: f.heckenbach@fh-soft.de @ 2013-01-24 21:11 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 56100
           Summary: spurious -Wshadow warning with local variable in
                    template class
    Classification: Unclassified
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: f.heckenbach@fh-soft.de


Created attachment 29268
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29268
Test case

Compiling the test case with "-Wshadow" gives:

shadow.cpp: In instantiation of 'void bar<T>::baz() [with T = int]':
shadow.cpp:4:17:   required from 'void bar<T>::qux() [with T = int]'
shadow.cpp:13:21:   required from here
shadow.cpp:6:21: warning: declaration of 'foo' shadows a global declaration
[-Wshadow]
shadow.cpp:9:5: warning: shadowed declaration is here [-Wshadow]

Observed with 4.4.6, 4.6.1 and 4.7.2.

Note: "private" is not necessary to trigger the warning, it's just there to
show it occurs even with "private".

The warning seems strange because the supposedly shadowed variable is declared
after the shadowing one. (I assume that's because of the processing done during
instantiation.) It's annoying because it means that an identifier used in a
template defined in some header, even in a local scope in a private method is
"poisoned" when used anywhere else with -Wshadow.


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

* [Bug c++/56100] spurious -Wshadow warning with local variable in template class
  2013-01-24 21:11 [Bug c++/56100] New: spurious -Wshadow warning with local variable in template class f.heckenbach@fh-soft.de
@ 2013-01-24 21:15 ` pinskia at gcc dot gnu.org
  2013-01-24 21:25 ` f.heckenbach@fh-soft.de
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2013-01-24 21:15 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2013-01-24 21:14:51 UTC ---
I think this is an artifact of warning during instantiation rather than at
definition time.


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

* [Bug c++/56100] spurious -Wshadow warning with local variable in template class
  2013-01-24 21:11 [Bug c++/56100] New: spurious -Wshadow warning with local variable in template class f.heckenbach@fh-soft.de
  2013-01-24 21:15 ` [Bug c++/56100] " pinskia at gcc dot gnu.org
@ 2013-01-24 21:25 ` f.heckenbach@fh-soft.de
  2015-03-31 11:19 ` paolo.carlini at oracle dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: f.heckenbach@fh-soft.de @ 2013-01-24 21:25 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #2 from Frank Heckenbach <f.heckenbach@fh-soft.de> 2013-01-24 21:25:09 UTC ---
I guess many warnings can only be given correctly during instantiation because
they depend on the actual arguments.

But shadowing is not one of them as the set of identifiers declared doesn't
depend on the arguments. (Even in the case of partial specializations, one
would expect the warning where the specialization is defined, not when it's
instantiated.)

So perhaps a simple fix is to turn off -Wshadow temporarily during
instantiation. After all, the instantiated code has no access to currently
declared global identifiers. This code fails as it should (AFAIK), unless foo
is declared before the template:

template <typename T>
struct bar
{
  int qux () { return foo; }
};

int foo;

int main ()
{
  bar <int> ().qux ();
}


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

* [Bug c++/56100] spurious -Wshadow warning with local variable in template class
  2013-01-24 21:11 [Bug c++/56100] New: spurious -Wshadow warning with local variable in template class f.heckenbach@fh-soft.de
  2013-01-24 21:15 ` [Bug c++/56100] " pinskia at gcc dot gnu.org
  2013-01-24 21:25 ` f.heckenbach@fh-soft.de
@ 2015-03-31 11:19 ` paolo.carlini at oracle dot com
  2015-03-31 13:29 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-03-31 11:19 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-03-31
     Ever confirmed|0                           |1


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

* [Bug c++/56100] spurious -Wshadow warning with local variable in template class
  2013-01-24 21:11 [Bug c++/56100] New: spurious -Wshadow warning with local variable in template class f.heckenbach@fh-soft.de
                   ` (2 preceding siblings ...)
  2015-03-31 11:19 ` paolo.carlini at oracle dot com
@ 2015-03-31 13:29 ` jason at gcc dot gnu.org
  2015-03-31 14:23 ` paolo.carlini at oracle dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2015-03-31 13:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> ---
(In reply to Paolo Carlini from comment #3)
> I wonder if in such cases would it simply make sense to suppress the warning
> basing on the locations

I think we want to suppress the warning on instantiation even if the order is
reversed:  given

int foo;

template <typename T>
struct bar
{
  void qux () { baz (); }
private:
  void baz () { int foo; }
};

int main ()
{
  bar <int> ().qux ();
}

We first warn about the declaration in the template, and then again about the
instantiation.


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

* [Bug c++/56100] spurious -Wshadow warning with local variable in template class
  2013-01-24 21:11 [Bug c++/56100] New: spurious -Wshadow warning with local variable in template class f.heckenbach@fh-soft.de
                   ` (3 preceding siblings ...)
  2015-03-31 13:29 ` jason at gcc dot gnu.org
@ 2015-03-31 14:23 ` paolo.carlini at oracle dot com
  2015-04-01 21:28 ` paolo at gcc dot gnu.org
  2015-04-01 21:38 ` paolo.carlini at oracle dot com
  6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-03-31 14:23 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|paolo.carlini at oracle dot com    |
           Assignee|unassigned at gcc dot gnu.org      |paolo.carlini at oracle dot com

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Doh, thanks Jason I thought I had already checked the behavior in that case.


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

* [Bug c++/56100] spurious -Wshadow warning with local variable in template class
  2013-01-24 21:11 [Bug c++/56100] New: spurious -Wshadow warning with local variable in template class f.heckenbach@fh-soft.de
                   ` (4 preceding siblings ...)
  2015-03-31 14:23 ` paolo.carlini at oracle dot com
@ 2015-04-01 21:28 ` paolo at gcc dot gnu.org
  2015-04-01 21:38 ` paolo.carlini at oracle dot com
  6 siblings, 0 replies; 8+ messages in thread
From: paolo at gcc dot gnu.org @ 2015-04-01 21:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> ---
Author: paolo
Date: Wed Apr  1 21:27:55 2015
New Revision: 221814

URL: https://gcc.gnu.org/viewcvs?rev=221814&root=gcc&view=rev
Log:
/cp
2015-04-01  Paolo Carlini  <paolo.carlini@oracle.com>

    PR c++/56100
    * pt.c (instantiating_current_function_p): New.
    * name-lookup.c (pushdecl_maybe_friend_1): Use it.
    * cp-tree.h (instantiating_current_function_p): Declare.

/testsuite
2015-04-01  Paolo Carlini  <paolo.carlini@oracle.com>

    PR c++/56100
    * g++.dg/warn/Wshadow-8.C: New.
    * g++.dg/warn/Wshadow-9.C: Likewise.
    * g++.dg/warn/Wshadow-10.C: Likewise.
    * g++.dg/warn/Wshadow-11.C: Likewise.

Added:
    trunk/gcc/testsuite/g++.dg/warn/Wshadow-10.C
    trunk/gcc/testsuite/g++.dg/warn/Wshadow-11.C
    trunk/gcc/testsuite/g++.dg/warn/Wshadow-8.C
    trunk/gcc/testsuite/g++.dg/warn/Wshadow-9.C
Modified:
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/name-lookup.c
    trunk/gcc/cp/pt.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug c++/56100] spurious -Wshadow warning with local variable in template class
  2013-01-24 21:11 [Bug c++/56100] New: spurious -Wshadow warning with local variable in template class f.heckenbach@fh-soft.de
                   ` (5 preceding siblings ...)
  2015-04-01 21:28 ` paolo at gcc dot gnu.org
@ 2015-04-01 21:38 ` paolo.carlini at oracle dot com
  6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-04-01 21:38 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED
           Assignee|paolo.carlini at oracle dot com    |unassigned at gcc dot gnu.org
   Target Milestone|---                         |5.0

--- Comment #7 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Fixed for 5.0.


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

end of thread, other threads:[~2015-04-01 21:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-24 21:11 [Bug c++/56100] New: spurious -Wshadow warning with local variable in template class f.heckenbach@fh-soft.de
2013-01-24 21:15 ` [Bug c++/56100] " pinskia at gcc dot gnu.org
2013-01-24 21:25 ` f.heckenbach@fh-soft.de
2015-03-31 11:19 ` paolo.carlini at oracle dot com
2015-03-31 13:29 ` jason at gcc dot gnu.org
2015-03-31 14:23 ` paolo.carlini at oracle dot com
2015-04-01 21:28 ` paolo at gcc dot gnu.org
2015-04-01 21:38 ` paolo.carlini at oracle dot com

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