public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/66472] New: -Wshadow gets confused by using statements in template classes
@ 2015-06-09 11:25 gael.guennebaud at gmail dot com
  2015-06-09 12:39 ` [Bug c++/66472] " chtz at informatik dot uni-bremen.de
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: gael.guennebaud at gmail dot com @ 2015-06-09 11:25 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 66472
           Summary: -Wshadow gets confused by using statements in template
                    classes
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gael.guennebaud at gmail dot com
  Target Milestone: ---

This is a followup to bug 57709 that disabled shadow warnings between variables
and class functions. However, -Wshadow still trigger false positive when a base
member functions is imported with the "using" keyword, as in the following
example (tested with gcc 5.1):


template<typename T> struct BaseClass {
  BaseClass(int size) : m_size(size) {}
  int size() { return m_size; }
  int m_size;
};

template<typename T> struct Foo : BaseClass<T> {
  typedef BaseClass<T> Base;
  Foo(int size) : Base(size) {}
  using Base::size;
};



$ g++-mp-5 gcc_shadow.cpp -c  -Wshadow 
gcc_shadow.cpp: In constructor 'Foo<T>::Foo(int)':
gcc_shadow.cpp:9:17: warning: declaration of 'size' shadows a member of
'Foo<T>' [-Wshadow]
   Foo(int size) : Base(size) {}
                 ^
gcc_shadow.cpp:10:15: note: shadowed declaration is here
   using Base::size;



Note that clang does not warn in this case, so it should be possible to figure
out that in this case, the imported "size" symbol is a function and not a
variable.

As suggested there https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57709#c16, I
tried to break at the call to warning_at to give you more input, but with no
luck, as if warning_at was not called at all. (I also tried to break at any
*warning* symbol with same result).


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

* [Bug c++/66472] -Wshadow gets confused by using statements in template classes
  2015-06-09 11:25 [Bug c++/66472] New: -Wshadow gets confused by using statements in template classes gael.guennebaud at gmail dot com
@ 2015-06-09 12:39 ` chtz at informatik dot uni-bremen.de
  2015-06-09 12:54 ` gael.guennebaud at gmail dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: chtz at informatik dot uni-bremen.de @ 2015-06-09 12:39 UTC (permalink / raw)
  To: gcc-bugs

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

Christoph Hertzberg <chtz at informatik dot uni-bremen.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |chtz at informatik dot uni-bremen.
                   |                            |de

--- Comment #1 from Christoph Hertzberg <chtz at informatik dot uni-bremen.de> ---
Wouldn't this actually be a valid warning if BaseClass had a constructor taking
a function pointer/member function pointer?

struct BaseClass {
  BaseClass(int) { std::cout << "int\n"; }
  BaseClass(int () ) { std::cout << "int()\n"; }
  BaseClass(int (BaseClass::*)()) {std::cout << "int (BaseClass::*)()\n"; }
  static int size() { return 0;}
  int size2() { return 0; }
};

struct Foo : public BaseClass {
  using BaseClass::size;
  using BaseClass::size2;

  // size shadows BaseClass::size!
  Foo(int size) : BaseClass(size) {}
  Foo() : BaseClass(size) {}      // uses BaseClass::size
  Foo(char) : BaseClass(size2) {} // uses BaseClass::size2
};


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

* [Bug c++/66472] -Wshadow gets confused by using statements in template classes
  2015-06-09 11:25 [Bug c++/66472] New: -Wshadow gets confused by using statements in template classes gael.guennebaud at gmail dot com
  2015-06-09 12:39 ` [Bug c++/66472] " chtz at informatik dot uni-bremen.de
@ 2015-06-09 12:54 ` gael.guennebaud at gmail dot com
  2015-06-09 13:07 ` glisse at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: gael.guennebaud at gmail dot com @ 2015-06-09 12:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Gael Guennebaud <gael.guennebaud at gmail dot com> ---
But with the same reasoning you would end up reintroducing shadow warnings
between local variables and *any* functions, not only the ones visible from a
using statement. It has been recognized that triggering a warning in such a
case was too much:
 - gcc 4.8 removed them for free functions
 - gcc 5.0 removed them for member functions
and I think that it thus make sense to remove them for member functions visible
through  "using". Did I miss something special regarding the use of "using"?


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

* [Bug c++/66472] -Wshadow gets confused by using statements in template classes
  2015-06-09 11:25 [Bug c++/66472] New: -Wshadow gets confused by using statements in template classes gael.guennebaud at gmail dot com
  2015-06-09 12:39 ` [Bug c++/66472] " chtz at informatik dot uni-bremen.de
  2015-06-09 12:54 ` gael.guennebaud at gmail dot com
@ 2015-06-09 13:07 ` glisse at gcc dot gnu.org
  2015-06-09 13:11 ` manu at gcc dot gnu.org
  2021-12-25  1:43 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: glisse at gcc dot gnu.org @ 2015-06-09 13:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Marc Glisse <glisse at gcc dot gnu.org> ---
(In reply to Gael Guennebaud from comment #0)
> As suggested there https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57709#c16, I
> tried to break at the call to warning_at to give you more input, but with no
> luck, as if warning_at was not called at all. (I also tried to break at any
> *warning* symbol with same result).

I compile with g++ -wrapper gdb,--args ... where this gcc was compile with -O0
-g. Breaking on warning_at shows that member is a using_decl.


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

* [Bug c++/66472] -Wshadow gets confused by using statements in template classes
  2015-06-09 11:25 [Bug c++/66472] New: -Wshadow gets confused by using statements in template classes gael.guennebaud at gmail dot com
                   ` (2 preceding siblings ...)
  2015-06-09 13:07 ` glisse at gcc dot gnu.org
@ 2015-06-09 13:11 ` manu at gcc dot gnu.org
  2021-12-25  1:43 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: manu at gcc dot gnu.org @ 2015-06-09 13:11 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu.org

--- Comment #4 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
> As suggested there https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57709#c16, I
> tried to break at the call to warning_at to give you more input, but with no
> luck, as if warning_at was not called at all. (I also tried to break at any
> *warning* symbol with same result).

Probably because you are debugging the driver instead of the compiler proper:
https://gcc.gnu.org/wiki/DebuggingGCC

Sorry, I should have mentioned that.
>From gcc-bugs-return-488483-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Tue Jun 09 13:15:23 2015
Return-Path: <gcc-bugs-return-488483-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 99094 invoked by alias); 9 Jun 2015 13:15:23 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 99048 invoked by uid 48); 9 Jun 2015 13:15:19 -0000
From: "manu at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/66472] -Wshadow gets confused by using statements in template classes
Date: Tue, 09 Jun 2015 13:15:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: 5.1.0
X-Bugzilla-Keywords: diagnostic
X-Bugzilla-Severity: normal
X-Bugzilla-Who: manu at gcc dot gnu.org
X-Bugzilla-Status: NEW
X-Bugzilla-Resolution:
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-66472-4-tWJ2OreXEW@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-66472-4@http.gcc.gnu.org/bugzilla/>
References: <bug-66472-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-06/txt/msg00815.txt.bz2
Content-length: 599

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

--- Comment #5 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
(In reply to Marc Glisse from comment #3)
> I compile with g++ -wrapper gdb,--args ... where this gcc was compile with
> -O0 -g. Breaking on warning_at shows that member is a using_decl.

Is there anyway to tell what the using_decl is actually representing? Perhaps
via its type?

I think this is one of those cases where false negatives are more annoying than
false positives are dangerous, thus maybe the warning should be silent for all
using_decl.
>From gcc-bugs-return-488484-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Tue Jun 09 13:15:58 2015
Return-Path: <gcc-bugs-return-488484-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 100121 invoked by alias); 9 Jun 2015 13:15:58 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 100062 invoked by uid 48); 9 Jun 2015 13:15:54 -0000
From: "chtz at informatik dot uni-bremen.de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/66472] -Wshadow gets confused by using statements in template classes
Date: Tue, 09 Jun 2015 13:15:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: 5.1.0
X-Bugzilla-Keywords: diagnostic
X-Bugzilla-Severity: normal
X-Bugzilla-Who: chtz at informatik dot uni-bremen.de
X-Bugzilla-Status: NEW
X-Bugzilla-Resolution:
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-66472-4-q3NI0BucVi@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-66472-4@http.gcc.gnu.org/bugzilla/>
References: <bug-66472-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-06/txt/msg00816.txt.bz2
Content-length: 760

https://gcc.gnu.org/bugzilla/show_bug.cgi?idf472

--- Comment #6 from Christoph Hertzberg <chtz at informatik dot uni-bremen.de> ---
Ok, good point on shadowing free functions.
Next pathological example: If you have a template specialization of your Base
with a static member variable called `size`, wouldn't the warning make sense?

template <class T>
struct Base {
  Base(int y) {std::cout << "y=" <<y <<"\n";}
  T size();
};

template<class T>
struct Bar : Base<T> {
  using Base<T>::size;
  Bar(int size) : Base<T>(size) {}
  Bar() : Base<T>(size) {} // only works for T==int
};

// Specialization, probably not visible when Bar is defined:
template<>
struct Base<int> {
  Base<int>(int x) {std::cout << "x=" <<x <<"\n";}
  const static int sizeB;
};


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

* [Bug c++/66472] -Wshadow gets confused by using statements in template classes
  2015-06-09 11:25 [Bug c++/66472] New: -Wshadow gets confused by using statements in template classes gael.guennebaud at gmail dot com
                   ` (3 preceding siblings ...)
  2015-06-09 13:11 ` manu at gcc dot gnu.org
@ 2021-12-25  1:43 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-25  1:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
GCC even warns for:
template<typename T> struct Foo : T {
  typedef T Base;
  Foo(int size) : Base(size) {}
  using Base::size;
};


While clang does not even warn for this case:
struct Foo  {
  Foo(int size) {}
  int size;
};


clang does not warn for constructors but do for normal methods:
struct Foo  {
  void g(int size) {}
  int size;
};

I don't know if it is a good idea to warn for constructors after all ....

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

end of thread, other threads:[~2021-12-25  1:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-09 11:25 [Bug c++/66472] New: -Wshadow gets confused by using statements in template classes gael.guennebaud at gmail dot com
2015-06-09 12:39 ` [Bug c++/66472] " chtz at informatik dot uni-bremen.de
2015-06-09 12:54 ` gael.guennebaud at gmail dot com
2015-06-09 13:07 ` glisse at gcc dot gnu.org
2015-06-09 13:11 ` manu at gcc dot gnu.org
2021-12-25  1:43 ` pinskia 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).