public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/20710] New: g++ should warn when hiding non-virtual method in base class
@ 2005-04-01  8:14 loose at astron dot nl
  2005-07-02  1:00 ` [Bug c++/20710] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 9+ messages in thread
From: loose at astron dot nl @ 2005-04-01  8:14 UTC (permalink / raw)
  To: gcc-bugs

I was wondering whether it is possible to have GCC produce a warning
whenever a non-virtual method in the base class is hidden by a method in the
derived class. I know this is possible for virtual methods by using
the -Woverload-virtual switch, but I haven't been able to find the
equivalent for non-virtual methods.

For example, I would like GCC to produce a warning about the following code.

$ cat tHide.cc
class A
{
public:
  void f() {}
};

class B : public A
{
public:
  void f(int) {}
};

int main()
{
  A a;
  B b;
  b.f(10);
  a.f();
}

Something like: warning: void A::f() was hidden by void B::f(int)

$ g++ -v -save-temps -Wall -Wextra tHide.cc
Reading specs from /usr/local/gcc343/lib/gcc/i686-pc-linux-gnu/3.4.3/specs
Configured with: ../gcc-3.4.3/configure --prefix=/usr/local/gcc343 --enable-
threads=posix
Thread model: posix
gcc version 3.4.3
 /usr/local/gcc343/libexec/gcc/i686-pc-linux-gnu/3.4.3/cc1plus -E -quiet -v -
D_GNU_SOURCE tHide.cc -mtune=pentiumpro -Wall -Wextra -o tHide.ii
ignoring nonexistent directory "/usr/local/gcc343/lib/gcc/i686-pc-linux-
gnu/3.4.3/../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/gcc343/lib/gcc/i686-pc-linux-gnu/3.4.3/../../../../include/c++/3.4.3
 /usr/local/gcc343/lib/gcc/i686-pc-linux-
gnu/3.4.3/../../../../include/c++/3.4.3/i686-pc-linux-gnu
 /usr/local/gcc343/lib/gcc/i686-pc-linux-
gnu/3.4.3/../../../../include/c++/3.4.3/backward
 /usr/local/include
 /usr/local/gcc343/include
 /usr/local/gcc343/lib/gcc/i686-pc-linux-gnu/3.4.3/include
 /usr/include
End of search list.
 /usr/local/gcc343/libexec/gcc/i686-pc-linux-gnu/3.4.3/cc1plus -fpreprocessed 
tHide.ii -quiet -dumpbase tHide.cc -mtune=pentiumpro -auxbase tHide -Wall -
Wextra -version -o tHide.s
GNU C++ version 3.4.3 (i686-pc-linux-gnu)
        compiled by GNU C version 3.4.3.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
 as -V -Qy -o tHide.o tHide.s
GNU assembler version 2.13.90.0.18 (i386-redhat-linux) using BFD version 
2.13.90.0.18 20030206
 /usr/local/gcc343/libexec/gcc/i686-pc-linux-gnu/3.4.3/collect2 --eh-frame-hdr -
m elf_i386 -dynamic-linker /lib/ld-
linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o /usr/local/gcc343/lib/gcc/i686-pc-
linux-gnu/3.4.3/crtbegin.o -L/usr/local/gcc343/lib/gcc/i686-pc-linux-gnu/3.4.3 -
L/usr/local/gcc343/lib/gcc/i686-pc-linux-gnu/3.4.3/../../.. tHide.o -lstdc++ -
lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/local/gcc343/lib/gcc/i686-pc-linux-
gnu/3.4.3/crtend.o /usr/lib/crtn.o

-- 
           Summary: g++ should warn when hiding non-virtual method in base
                    class
           Product: gcc
           Version: 3.4.3
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: loose at astron dot nl
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug c++/20710] g++ should warn when hiding non-virtual method in base class
  2005-04-01  8:14 [Bug c++/20710] New: g++ should warn when hiding non-virtual method in base class loose at astron dot nl
@ 2005-07-02  1:00 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-07-02  1:00 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-07-02 01:00 -------
Confirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |diagnostic
   Last reconfirmed|0000-00-00 00:00:00         |2005-07-02 01:00:21
               date|                            |


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


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

* [Bug c++/20710] g++ should warn when hiding non-virtual method in base class
       [not found] <bug-20710-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2010-11-01 13:01 ` redi at gcc dot gnu.org
@ 2022-06-24 22:34 ` jason at gcc dot gnu.org
  6 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu.org @ 2022-06-24 22:34 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |EisahLee at gmx dot de

--- Comment #11 from Jason Merrill <jason at gcc dot gnu.org> ---
*** Bug 67345 has been marked as a duplicate of this bug. ***

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

* [Bug c++/20710] g++ should warn when hiding non-virtual method in base class
       [not found] <bug-20710-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2010-11-01 12:54 ` loose at astron dot nl
@ 2010-11-01 13:01 ` redi at gcc dot gnu.org
  2022-06-24 22:34 ` jason at gcc dot gnu.org
  6 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2010-11-01 13:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-11-01 13:01:43 UTC ---
Yup, that's why I haven't closed this as a duplicate.  

The C++0x override control works for virtual and non-virtual names, so is
relevant to this PR *and* the others.  Noting and linking to similar PRs helps
people looking at this in future.


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

* [Bug c++/20710] g++ should warn when hiding non-virtual method in base class
       [not found] <bug-20710-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2010-11-01 12:39 ` redi at gcc dot gnu.org
@ 2010-11-01 12:54 ` loose at astron dot nl
  2010-11-01 13:01 ` redi at gcc dot gnu.org
  2022-06-24 22:34 ` jason at gcc dot gnu.org
  6 siblings, 0 replies; 9+ messages in thread
From: loose at astron dot nl @ 2010-11-01 12:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from loose at astron dot nl 2010-11-01 12:54:25 UTC ---
OK, fair enough.

However, I reported this "bug", because I would like GCC to produce a warning
when hiding a non-virtual method in *existing* code; an option similar to
-Woverloaded-virtual.

New code could of course be written, using either C0x attributes or GCC
attributes. But that won't solve the issue for C98-compliant code.

I agree that it's preferable to remove duplicate bugs. However, I'm not sure
the bugs you mention are real duplicates, because at least some of them
explicitly refer to overriding (virtual) functions, whereas I'm referring to
overloading (non-virtual) functions.


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

* [Bug c++/20710] g++ should warn when hiding non-virtual method in base class
       [not found] <bug-20710-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2010-11-01 12:36 ` redi at gcc dot gnu.org
@ 2010-11-01 12:39 ` redi at gcc dot gnu.org
  2010-11-01 12:54 ` loose at astron dot nl
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2010-11-01 12:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-11-01 12:39:48 UTC ---
also, GNU-style attributes are not being removed from GCC, even if C++0x
attributes get dropped

my point was just that there are several similar bugs and that whatever it
looks like, the final implementation of C++0x override control is likely to
influence this enhancement request.


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

* [Bug c++/20710] g++ should warn when hiding non-virtual method in base class
       [not found] <bug-20710-4@http.gcc.gnu.org/bugzilla/>
  2010-11-01 11:22 ` redi at gcc dot gnu.org
  2010-11-01 12:29 ` loose at astron dot nl
@ 2010-11-01 12:36 ` redi at gcc dot gnu.org
  2010-11-01 12:39 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2010-11-01 12:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-11-01 12:36:45 UTC ---
Attributes were still in the FCD, and are still in the current draft, but might
be removed.  Override control may not be done by attributes, but will be
present in C++0x in some form, see
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3151.html and
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3163.pdf for the
latest proposals.


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

* [Bug c++/20710] g++ should warn when hiding non-virtual method in base class
       [not found] <bug-20710-4@http.gcc.gnu.org/bugzilla/>
  2010-11-01 11:22 ` redi at gcc dot gnu.org
@ 2010-11-01 12:29 ` loose at astron dot nl
  2010-11-01 12:36 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: loose at astron dot nl @ 2010-11-01 12:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from loose at astron dot nl 2010-11-01 12:29:27 UTC ---
As far as I know attributes were removed from the C0x Final Draft.
Besides, if GCC were to provide a compiler flag to warn for this, you would
also be able to catch potential bugs in "old" code, or in code where the author
was not explicit about overrides.


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

* [Bug c++/20710] g++ should warn when hiding non-virtual method in base class
       [not found] <bug-20710-4@http.gcc.gnu.org/bugzilla/>
@ 2010-11-01 11:22 ` redi at gcc dot gnu.org
  2010-11-01 12:29 ` loose at astron dot nl
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2010-11-01 11:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-11-01 11:22:26 UTC ---
This would also be solved by the "override control" features coming in C++0x

c.f. PR 17920, PR 31397, PR 36848


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

end of thread, other threads:[~2022-06-24 22:34 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-01  8:14 [Bug c++/20710] New: g++ should warn when hiding non-virtual method in base class loose at astron dot nl
2005-07-02  1:00 ` [Bug c++/20710] " pinskia at gcc dot gnu dot org
     [not found] <bug-20710-4@http.gcc.gnu.org/bugzilla/>
2010-11-01 11:22 ` redi at gcc dot gnu.org
2010-11-01 12:29 ` loose at astron dot nl
2010-11-01 12:36 ` redi at gcc dot gnu.org
2010-11-01 12:39 ` redi at gcc dot gnu.org
2010-11-01 12:54 ` loose at astron dot nl
2010-11-01 13:01 ` redi at gcc dot gnu.org
2022-06-24 22:34 ` jason 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).