public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/58140] New: -Wnon-virtual-dtor shouldn't fire for classes declared final
@ 2013-08-12 17:48 tudorb at fb dot com
2013-08-12 17:51 ` [Bug c++/58140] " tudorb at fb dot com
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: tudorb at fb dot com @ 2013-08-12 17:48 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58140
Bug ID: 58140
Summary: -Wnon-virtual-dtor shouldn't fire for classes declared
final
Product: gcc
Version: 4.7.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: tudorb at fb dot com
Created attachment 30636
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30636&action=edit
Test case
In C++11, we can declare a class as "final" to indicate that it can't be
derived from. In that case, having a public non-virtual destructor is fine,
even if the class has virtual methods (no derived classes exist, so deleting an
instance via a pointer is always safe).
In the attached example, the warning should fire for NonFinalDerived, but not
for FinalDerived.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/58140] -Wnon-virtual-dtor shouldn't fire for classes declared final
2013-08-12 17:48 [Bug c++/58140] New: -Wnon-virtual-dtor shouldn't fire for classes declared final tudorb at fb dot com
@ 2013-08-12 17:51 ` tudorb at fb dot com
2013-08-12 19:17 ` redi at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: tudorb at fb dot com @ 2013-08-12 17:51 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58140
--- Comment #1 from Tudor Bosman <tudorb at fb dot com> ---
(Tested with gcc 4.7.1, compiled with -std=c++11 -Wnon-virtual-dtor
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/58140] -Wnon-virtual-dtor shouldn't fire for classes declared final
2013-08-12 17:48 [Bug c++/58140] New: -Wnon-virtual-dtor shouldn't fire for classes declared final tudorb at fb dot com
2013-08-12 17:51 ` [Bug c++/58140] " tudorb at fb dot com
@ 2013-08-12 19:17 ` redi at gcc dot gnu.org
2013-08-12 19:22 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2013-08-12 19:17 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58140
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2013-08-12
Ever confirmed|0 |1
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This should be pretty simple to fix, but why use -Wnon-virtual-dtor anyway,
when -Wdelete-non-virtual-dtor is more accurate and more useful?
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/58140] -Wnon-virtual-dtor shouldn't fire for classes declared final
2013-08-12 17:48 [Bug c++/58140] New: -Wnon-virtual-dtor shouldn't fire for classes declared final tudorb at fb dot com
2013-08-12 17:51 ` [Bug c++/58140] " tudorb at fb dot com
2013-08-12 19:17 ` redi at gcc dot gnu.org
@ 2013-08-12 19:22 ` redi at gcc dot gnu.org
2014-01-07 5:48 ` andrewjcg at gmail dot com
2014-01-07 9:46 ` redi at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2013-08-12 19:22 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58140
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Tudor Bosman from comment #0)
> In C++11, we can declare a class as "final" to indicate that it can't be
> derived from. In that case, having a public non-virtual destructor is fine,
> even if the class has virtual methods (no derived classes exist, so deleting
> an instance via a pointer is always safe).
N.B. this is only true if there's no base class with a public destructor, which
is true for your example, but not in general.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/58140] -Wnon-virtual-dtor shouldn't fire for classes declared final
2013-08-12 17:48 [Bug c++/58140] New: -Wnon-virtual-dtor shouldn't fire for classes declared final tudorb at fb dot com
` (2 preceding siblings ...)
2013-08-12 19:22 ` redi at gcc dot gnu.org
@ 2014-01-07 5:48 ` andrewjcg at gmail dot com
2014-01-07 9:46 ` redi at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: andrewjcg at gmail dot com @ 2014-01-07 5:48 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58140
Andrew Gallagher <andrewjcg at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |andrewjcg at gmail dot com
--- Comment #4 from Andrew Gallagher <andrewjcg at gmail dot com> ---
FWIW, I suppose one case where "-Wnon-virtual-dtor" is more useful than
"-Wdelete-non-virtual-dtor" is when the actual delete occurs in system
headers/libs. This seems to be case when using std::unique_ptr, where the
actual "-Wdelete-non-virtual-dtor" warning is muted unless "-Wsystem-headers"
is used, which might not be desirable:
#include <memory>
class A {
public:
virtual void a() {}
};
class B : public A {
public:
virtual void b() {}
};
int main(int argc, char ** argv) {
A *a = new B();
delete a; // triggers -Wdelete-non-virtual-dtor
std::unique_ptr<A> p(new B()); // doesn't
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/58140] -Wnon-virtual-dtor shouldn't fire for classes declared final
2013-08-12 17:48 [Bug c++/58140] New: -Wnon-virtual-dtor shouldn't fire for classes declared final tudorb at fb dot com
` (3 preceding siblings ...)
2014-01-07 5:48 ` andrewjcg at gmail dot com
@ 2014-01-07 9:46 ` redi at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2014-01-07 9:46 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58140
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
That's PR 58876, which I intend to fix
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-01-07 9:46 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-12 17:48 [Bug c++/58140] New: -Wnon-virtual-dtor shouldn't fire for classes declared final tudorb at fb dot com
2013-08-12 17:51 ` [Bug c++/58140] " tudorb at fb dot com
2013-08-12 19:17 ` redi at gcc dot gnu.org
2013-08-12 19:22 ` redi at gcc dot gnu.org
2014-01-07 5:48 ` andrewjcg at gmail dot com
2014-01-07 9:46 ` redi 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).