public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/20423] Warning -Woverloaded-virtual triggers to often
[not found] <bug-20423-7559@http.gcc.gnu.org/bugzilla/>
@ 2005-11-24 2:23 ` gdr at gcc dot gnu dot org
2007-02-14 22:30 ` manu at gcc dot gnu dot org
` (7 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: gdr at gcc dot gnu dot org @ 2005-11-24 2:23 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from gdr at gcc dot gnu dot org 2005-11-24 02:23 -------
Agreed with the reporter's analysis
--
gdr at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2005-11-24 02:23:45
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20423
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/20423] Warning -Woverloaded-virtual triggers to often
[not found] <bug-20423-7559@http.gcc.gnu.org/bugzilla/>
2005-11-24 2:23 ` [Bug c++/20423] Warning -Woverloaded-virtual triggers to often gdr at gcc dot gnu dot org
@ 2007-02-14 22:30 ` manu at gcc dot gnu dot org
2007-02-16 10:01 ` manu at gcc dot gnu dot org
` (6 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-02-14 22:30 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from manu at gcc dot gnu dot org 2007-02-14 22:30 -------
I am looking at this but it is a bit hard to see how to make the distinction
between the two kinds. I don't want to introduce yet another loop in
warn_hidden but perhaps that is unavoidable. Any hints?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20423
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/20423] Warning -Woverloaded-virtual triggers to often
[not found] <bug-20423-7559@http.gcc.gnu.org/bugzilla/>
2005-11-24 2:23 ` [Bug c++/20423] Warning -Woverloaded-virtual triggers to often gdr at gcc dot gnu dot org
2007-02-14 22:30 ` manu at gcc dot gnu dot org
@ 2007-02-16 10:01 ` manu at gcc dot gnu dot org
2008-11-30 15:38 ` Woebbeking at web dot de
` (5 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-02-16 10:01 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from manu at gcc dot gnu dot org 2007-02-16 10:01 -------
A really wild-guess patch. Comments?
Index: gcc/cp/class.c
===================================================================
--- gcc/cp/class.c (revision 121953)
+++ gcc/cp/class.c (working copy)
@@ -2377,6 +2377,8 @@ warn_hidden (tree t)
tree binfo;
int j;
+ bool just_hidden = false;
+
/* All functions in this slot in the CLASSTYPE_METHOD_VEC will
have the same name. Figure out what name that is. */
name = DECL_NAME (OVL_CURRENT (fns));
@@ -2408,8 +2410,14 @@ warn_hidden (tree t)
/* If the method from the base class has the same
signature as the method from the derived class, it
has been overridden. */
- if (same_signature_p (fndecl, TREE_VALUE (*prev)))
- *prev = TREE_CHAIN (*prev);
+ if (same_signature_p (fndecl, TREE_VALUE (*prev)))
+ {
+ *prev = TREE_CHAIN (*prev);
+ /* If at least one method has the same signature,
+ the not overloaded variants are just
+ hidden. */
+ just_hidden = true;
+ }
else
prev = &TREE_CHAIN (*prev);
}
@@ -2419,9 +2427,17 @@ warn_hidden (tree t)
as they are hidden. */
while (base_fndecls)
{
- /* Here we know it is a hider, and no overrider exists. */
- warning (0, "%q+D was hidden", TREE_VALUE (base_fndecls));
- warning (0, " by %q+D", fns);
+ /* If Here we know it is a hider, and no overrider exists. */
+ if (just_hidden)
+ {
+ warning (OPT_Wpartial_overloaded_virtual, "%q+D was hidden",
TREE_VALUE (base_fndecls));
+ warning (OPT_Wpartial_overloaded_virtual, " by %q+D", fns);
+ }
+ else
+ {
+ warning (OPT_Woverloaded_virtual, "%q+D was hidden", TREE_VALUE
(base_fndecls));
+ warning (OPT_Woverloaded_virtual, " by %q+D", fns);
+ }
base_fndecls = TREE_CHAIN (base_fndecls);
}
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20423
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/20423] Warning -Woverloaded-virtual triggers to often
[not found] <bug-20423-7559@http.gcc.gnu.org/bugzilla/>
` (2 preceding siblings ...)
2007-02-16 10:01 ` manu at gcc dot gnu dot org
@ 2008-11-30 15:38 ` Woebbeking at web dot de
2009-07-17 10:01 ` jason at gcc dot gnu dot org
` (4 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Woebbeking at web dot de @ 2008-11-30 15:38 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from Woebbeking at web dot de 2008-11-30 15:36 -------
Any progress on this?
This warning could be really useful if only 1) would be handled. In its current
state I can't use it as I get too many "false" positives :-(
--
Woebbeking at web dot de changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |Woebbeking at web dot de
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20423
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/20423] Warning -Woverloaded-virtual triggers to often
[not found] <bug-20423-7559@http.gcc.gnu.org/bugzilla/>
` (3 preceding siblings ...)
2008-11-30 15:38 ` Woebbeking at web dot de
@ 2009-07-17 10:01 ` jason at gcc dot gnu dot org
2009-07-18 6:10 ` jason at gcc dot gnu dot org
` (3 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu dot org @ 2009-07-17 10:01 UTC (permalink / raw)
To: gcc-bugs
--
jason at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |jason at gcc dot gnu dot org
|dot org |
Status|NEW |ASSIGNED
Keywords| |patch
Last reconfirmed|2005-11-24 02:23:45 |2009-07-17 10:00:52
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20423
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/20423] Warning -Woverloaded-virtual triggers to often
[not found] <bug-20423-7559@http.gcc.gnu.org/bugzilla/>
` (4 preceding siblings ...)
2009-07-17 10:01 ` jason at gcc dot gnu dot org
@ 2009-07-18 6:10 ` jason at gcc dot gnu dot org
2009-07-21 17:36 ` jwakely dot gcc at gmail dot com
` (2 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu dot org @ 2009-07-18 6:10 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from jason at gcc dot gnu dot org 2009-07-18 06:10 -------
An old patch: http://gcc.gnu.org/ml/gcc-patches/1999-03n/msg00182.html
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20423
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/20423] Warning -Woverloaded-virtual triggers to often
[not found] <bug-20423-7559@http.gcc.gnu.org/bugzilla/>
` (5 preceding siblings ...)
2009-07-18 6:10 ` jason at gcc dot gnu dot org
@ 2009-07-21 17:36 ` jwakely dot gcc at gmail dot com
2009-08-11 14:24 ` jwakely dot gcc at gmail dot com
2010-02-19 21:23 ` jason at gcc dot gnu dot org
8 siblings, 0 replies; 15+ messages in thread
From: jwakely dot gcc at gmail dot com @ 2009-07-21 17:36 UTC (permalink / raw)
To: gcc-bugs
------- Comment #9 from jwakely dot gcc at gmail dot com 2009-07-21 17:36 -------
(In reply to comment #0)
>
> This is also not conforming to the "specification" in
> http://gcc.gnu.org/ml/gcc-bugs/1999-08n/msg01069.html
>
> Warn when a derived class function declaration may be an error in
> defining a virtual function. In a derived class, the definitions of
> virtual functions must match the type signature of a virtual
> function declared in the base class. With this option, the compiler
> warns when you define a function with the same name as a virtual
> function, but with a type signature that does not match any
> declarations from the base class.
But that's not what it does. The description in the manual describes the
current behaviour correctly, that description above doesn't.
(In reply to comment #6)
> A really wild-guess patch. Comments?
...
> + /* If at least one method has the same signature,
> + the not overloaded variants are just
> + hidden. */
> + just_hidden = true;
Shouldn't this say "not overridden variants" ?
I don't like the name -Wpartial-overloaded-virtual for the same reason. The
name should clearly distinguish whether it is triggered by overloading,
overriding or hiding.
-Woverloaded-virtual is a reasonable name for the current behaviour; it
triggers if there is an overload that hides a virtual (whether the overload is
itself virtual or not.) The proposed -Wpartial-overloaded-virtual name makes
no sense.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20423
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/20423] Warning -Woverloaded-virtual triggers to often
[not found] <bug-20423-7559@http.gcc.gnu.org/bugzilla/>
` (6 preceding siblings ...)
2009-07-21 17:36 ` jwakely dot gcc at gmail dot com
@ 2009-08-11 14:24 ` jwakely dot gcc at gmail dot com
2010-02-19 21:23 ` jason at gcc dot gnu dot org
8 siblings, 0 replies; 15+ messages in thread
From: jwakely dot gcc at gmail dot com @ 2009-08-11 14:24 UTC (permalink / raw)
To: gcc-bugs
------- Comment #10 from jwakely dot gcc at gmail dot com 2009-08-11 14:24 -------
as with bug 31937, there is overlap between this enhancement and the 'Explicit
Virtual Function Overrides' paper,
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2928.htm
the attributes proposed in that paper allow the derived class to explicitly
state whether a function should override or hide the same name in the base
class, making it ill-formed if there is unintended hiding
--
jwakely dot gcc at gmail dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jwakely dot gcc at gmail dot
| |com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20423
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/20423] Warning -Woverloaded-virtual triggers to often
[not found] <bug-20423-7559@http.gcc.gnu.org/bugzilla/>
` (7 preceding siblings ...)
2009-08-11 14:24 ` jwakely dot gcc at gmail dot com
@ 2010-02-19 21:23 ` jason at gcc dot gnu dot org
8 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu dot org @ 2010-02-19 21:23 UTC (permalink / raw)
To: gcc-bugs
------- Comment #11 from jason at gcc dot gnu dot org 2010-02-19 21:23 -------
Not working on this now.
--
jason at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|jason at gcc dot gnu dot org|unassigned at gcc dot gnu
| |dot org
Status|ASSIGNED |NEW
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20423
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/20423] Warning -Woverloaded-virtual triggers to often
[not found] <bug-20423-4@http.gcc.gnu.org/bugzilla/>
2022-06-24 22:20 ` jason at gcc dot gnu.org
2022-06-24 22:26 ` cvs-commit at gcc dot gnu.org
@ 2022-06-24 22:27 ` jason at gcc dot gnu.org
2 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu.org @ 2022-06-24 22:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=20423
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |13.0
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #13 from Jason Merrill <jason at gcc dot gnu.org> ---
For GCC 13 the requested semantics will be available in -Woverloaded-virtual=1
or -Wall.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/20423] Warning -Woverloaded-virtual triggers to often
[not found] <bug-20423-4@http.gcc.gnu.org/bugzilla/>
2022-06-24 22:20 ` jason at gcc dot gnu.org
@ 2022-06-24 22:26 ` cvs-commit at gcc dot gnu.org
2022-06-24 22:27 ` jason at gcc dot gnu.org
2 siblings, 0 replies; 15+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-06-24 22:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=20423
--- Comment #12 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:
https://gcc.gnu.org/g:113844d68e94f4e9c0e946db351ba7d3d4a1335a
commit r13-1262-g113844d68e94f4e9c0e946db351ba7d3d4a1335a
Author: Jason Merrill <jason@redhat.com>
Date: Fri Jun 24 14:40:12 2022 -0400
c++: Include -Woverloaded-virtual in -Wall [PR87729]
This seems like a good warning to have in -Wall, as requested. But as
pointed out in PR20423, some users want a warning only when a derived
function doesn't override any base function. So let's put that lesser
version in -Wall (and -Woverloaded-virtual=1) while leaving the semantics
for the existing option the same.
PR c++/87729
PR c++/20423
gcc/c-family/ChangeLog:
* c.opt (Woverloaded-virtual): Add levels, include in -Wall.
gcc/ChangeLog:
* doc/invoke.texi: Document changes.
gcc/cp/ChangeLog:
* class.cc (warn_hidden): Handle -Woverloaded-virtual=1.
gcc/testsuite/ChangeLog:
* g++.dg/warn/Woverloaded-virt1.C: New test.
* g++.dg/warn/Woverloaded-virt2.C: New test.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/20423] Warning -Woverloaded-virtual triggers to often
[not found] <bug-20423-4@http.gcc.gnu.org/bugzilla/>
@ 2022-06-24 22:20 ` jason at gcc dot gnu.org
2022-06-24 22:26 ` cvs-commit at gcc dot gnu.org
2022-06-24 22:27 ` jason at gcc dot gnu.org
2 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu.org @ 2022-06-24 22:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=20423
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at gcc dot gnu.org
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |jason at gcc dot gnu.org
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/20423] Warning -Woverloaded-virtual triggers to often
2005-03-11 10:34 [Bug c++/20423] New: " micis at gmx dot de
2005-03-11 15:12 ` [Bug c++/20423] " pinskia at gcc dot gnu dot org
2005-03-11 17:30 ` micis at gmx dot de
@ 2005-03-29 14:10 ` pinskia at gcc dot gnu dot org
2 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-03-29 14:10 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-03-29 14:10 -------
*** Bug 20683 has been marked as a duplicate of this bug. ***
--
What |Removed |Added
----------------------------------------------------------------------------
CC| |oliverst at online dot de
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20423
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/20423] Warning -Woverloaded-virtual triggers to often
2005-03-11 10:34 [Bug c++/20423] New: " micis at gmx dot de
2005-03-11 15:12 ` [Bug c++/20423] " pinskia at gcc dot gnu dot org
@ 2005-03-11 17:30 ` micis at gmx dot de
2005-03-29 14:10 ` pinskia at gcc dot gnu dot org
2 siblings, 0 replies; 15+ messages in thread
From: micis at gmx dot de @ 2005-03-11 17:30 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From micis at gmx dot de 2005-03-11 17:30 -------
I think there a two different situations:
1) in the derived class you define a method with the same name but
different parameters.
This is typically a serious bug in your program which can result in the
exectution of the code of the wrong (not overloaded) function.
2) in the derived class you define not all overloaded variants.
In that case the not overloaded variants are hidden but no run-time-error
occurs. If you try to call a hidden variant, the compiler complains.
If "-Woverloaded-virtual" only triggers in case 1, it could be enabled
with "-Wall" as it typically indicates a severe bug in your program.
If there would be a "-Wpartial-overloaded-virtual" you could enable if you like
it and you can. I have to work with a large existing code basis where I would
not enable it.
I think to give different messages like ICC is the way to go.
Michael Cieslinski
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20423
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/20423] Warning -Woverloaded-virtual triggers to often
2005-03-11 10:34 [Bug c++/20423] New: " micis at gmx dot de
@ 2005-03-11 15:12 ` pinskia at gcc dot gnu dot org
2005-03-11 17:30 ` micis at gmx dot de
2005-03-29 14:10 ` pinskia at gcc dot gnu dot org
2 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-03-11 15:12 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-03-11 15:11 -------
Hmm, ICC gives:
t.cc(7): warning #654: overloaded virtual function "Foo::Func" is only partially overridden in class "Baz"
class Baz: public Foo
^
t.cc(14): error #165: too few arguments in function call
b->Func(1);
^
compilation aborted for t.cc (code 2)
The warning is correct because Func(int) is still hidden in the supper class and you cannot use it:
class Foo
{
public: virtual void Func(int);
virtual void Func(int, int);
};
class Baz: public Foo
{
public: virtual void Func(int, int);
};
void g(Baz *b)
{
b->Func(1);
}
Maybe we should do the warning which ICC is giving instead of the one which we give right now.
--
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |minor
Keywords| |diagnostic
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20423
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2022-06-24 22:27 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-20423-7559@http.gcc.gnu.org/bugzilla/>
2005-11-24 2:23 ` [Bug c++/20423] Warning -Woverloaded-virtual triggers to often gdr at gcc dot gnu dot org
2007-02-14 22:30 ` manu at gcc dot gnu dot org
2007-02-16 10:01 ` manu at gcc dot gnu dot org
2008-11-30 15:38 ` Woebbeking at web dot de
2009-07-17 10:01 ` jason at gcc dot gnu dot org
2009-07-18 6:10 ` jason at gcc dot gnu dot org
2009-07-21 17:36 ` jwakely dot gcc at gmail dot com
2009-08-11 14:24 ` jwakely dot gcc at gmail dot com
2010-02-19 21:23 ` jason at gcc dot gnu dot org
[not found] <bug-20423-4@http.gcc.gnu.org/bugzilla/>
2022-06-24 22:20 ` jason at gcc dot gnu.org
2022-06-24 22:26 ` cvs-commit at gcc dot gnu.org
2022-06-24 22:27 ` jason at gcc dot gnu.org
2005-03-11 10:34 [Bug c++/20423] New: " micis at gmx dot de
2005-03-11 15:12 ` [Bug c++/20423] " pinskia at gcc dot gnu dot org
2005-03-11 17:30 ` micis at gmx dot de
2005-03-29 14:10 ` pinskia at gcc dot gnu dot 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).