Bug 53613 - Cannot override a inline "= default" virtual destructor.
Summary: Cannot override a inline "= default" virtual destructor.
Status: RESOLVED DUPLICATE of bug 50043
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-06-08 11:12 UTC by Kirby Zhou
Modified: 2012-06-12 10:47 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kirby Zhou 2012-06-08 11:12:33 UTC
[root@djt-17-109-v06 tmp]# cat tover.cpp 
struct __cook {
        virtual ~__cook() = default;
};

struct __cook1: public __cook {
        virtual ~__cook1() = default;
};

struct __cook2: public __cook {
        virtual ~__cook2();
};
__cook2::~__cook2() {};

struct __cook3: public __cook {
        virtual ~__cook3();
};
__cook3::~__cook3() = default;

[root@djt-17-109-v06 tmp]# g++47 -c -std=gnu++11 tover.cpp 
tover.cpp:6:10: error: looser throw specifier for 'virtual __cook1::~__cook1()'
tover.cpp:2:10: error:   overriding 'virtual __cook::~__cook() noexcept (true)'
tover.cpp:10:10: error: looser throw specifier for 'virtual __cook2::~__cook2()'
tover.cpp:2:10: error:   overriding 'virtual __cook::~__cook() noexcept (true)'
tover.cpp:15:10: error: looser throw specifier for 'virtual __cook3::~__cook3()'
tover.cpp:2:10: error:   overriding 'virtual __cook::~__cook() noexcept (true)
'
[root@djt-17-109-v06 tmp]# g++ -c -std=gnu++0x tover.cpp 
# g++ 4.4.6 works

Workaround: define parent destructor outside the class definition.

[root@djt-17-109-v06 tmp]# cat tover.cpp 
struct __cook {
                virtual ~__cook();
};
__cook::~__cook() = default;
/*...*/
Comment 1 Jonathan Wakely 2012-06-08 11:16:47 UTC
Fixed on trunk by patch for PR 50043
Comment 2 Jonathan Wakely 2012-06-08 11:18:47 UTC
(In reply to comment #0)
> Workaround: define parent destructor outside the class definition.

Or add explicit 'noexcept' specifiers to the derived destructors.
Comment 3 Kirby Zhou 2012-06-11 10:15:58 UTC
(In reply to comment #1)
> Fixed on trunk by patch for PR 50043

Did this patch apply to 4.7 branch?
I retested with 4.7 branch 20120610, The bug is still exist.
Comment 4 Jonathan Wakely 2012-06-11 10:28:40 UTC
(In reply to comment #3)
> (In reply to comment #1)
> > Fixed on trunk by patch for PR 50043
> 
> Did this patch apply to 4.7 branch?

PR 50043 shows a single commit to trunk and has Target Milestone 4.8.0, so no, it's only fixed on trunk.

> I retested with 4.7 branch 20120610, The bug is still exist.

Yes, and it probably won't be fixed on the release branch as it's not a regression.  New features are not usually added to released versions.

In any case, there's a simple workaround of adding explicit 'noexcept' specifiers, which will still work with 4.8

I'm marking this as a dup of PR 50043 as the failure to compile is a direct consequence of not implementing DR 1123

*** This bug has been marked as a duplicate of bug 50043 ***
Comment 5 Kirby Zhou 2012-06-12 02:39:44 UTC
It is a BAD NEWS about no fix on the 4.7.X branch, and "it's not a regression."

The bug breaks a lot of already exist oode which is workable with GCC-4.4.X release. 

(In reply to comment #4)
> (In reply to comment #3)
> > (In reply to comment #1)
> > > Fixed on trunk by patch for PR 50043
> > 
> > Did this patch apply to 4.7 branch?
> PR 50043 shows a single commit to trunk and has Target Milestone 4.8.0, so no,
> it's only fixed on trunk.
> > I retested with 4.7 branch 20120610, The bug is still exist.
> Yes, and it probably won't be fixed on the release branch as it's not a
> regression.  New features are not usually added to released versions.
> In any case, there's a simple workaround of adding explicit 'noexcept'
> specifiers, which will still work with 4.8
> I'm marking this as a dup of PR 50043 as the failure to compile is a direct
> consequence of not implementing DR 1123
> *** This bug has been marked as a duplicate of bug 50043 ***
Comment 6 Jonathan Wakely 2012-06-12 06:27:42 UTC
As I said, there's a simple workaround.
Comment 7 Jakub Jelinek 2012-06-12 07:24:07 UTC
As the testcase compiles with 4.4.x and trunk, but doesn't in 4.6.x and 4.7.x,
I'd call this a 4.6/4.7 Regression (unless what 4.4.x compiled it into was completely broken).  The question is if the patch is safely backportable though.
Comment 8 Jonathan Wakely 2012-06-12 10:47:58 UTC
I think it compiles with 4.4 because __cook::~__cook is not noexcept, because 4.4 doesn't infer an empty throw spec for a trivial destructor.

If you add throw() to ~__cook you get the same errors about looser throw specifiers.  So 4.4 was generating different code, but in this example it makes no practical difference because you can't use the noexcept operator in 4.4 to test whether something has an empty exception specifier anyway.