Bug 56191 - Destructor affects noexcept detection
Summary: Destructor affects noexcept detection
Status: RESOLVED DUPLICATE of bug 51452
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.2
: P3 normal
Target Milestone: 4.8.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-03 14:25 UTC by Antony Polukhin
Modified: 2013-02-04 07:29 UTC (History)
0 users

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 Antony Polukhin 2013-02-03 14:25:45 UTC
GCC 4.7.2 incorrectly detects noexcept specification in case of move constructor.
Here is an example:

struct descriptor_owner_movable {
    descriptor_owner_movable(descriptor_owner_movable&& ) noexcept {}

    // Without destructor it compiles correctly
    ~descriptor_owner_movable() {}
};

descriptor_owner_movable&& declval() noexcept;

int main() {
    static_assert(
        noexcept(descriptor_owner_movable(declval()))
    , "But it is nothrow!");
    return 0;
}
Comment 1 Jonathan Wakely 2013-02-03 17:02:59 UTC
It's the correct behaviour that the destructor affects noexcept detection, because the operand expression creates *and* destroys temporary objects.  G++ 4.7 does not apply the rule that destructors are noexcept, so you need to add an explicit noexcept specification on the destructor.  GCC 4.8 correctly makes the destructor noexcept as required by C++11.
Comment 2 Jonathan Wakely 2013-02-03 21:05:17 UTC
N.B. you don't need to CC yourself on bugs, the reporter always gets sent changes to the bug
Comment 3 Antony Polukhin 2013-02-04 07:27:33 UTC
Oh, thanks for clarification!  
Initially I was confused by the fact that std::is_nothrow_constructible checks for destructor, but I thought that it is a 'noexcept()' bug. Now I see that this issue is a duplicate for #51452.

(In reply to comment #2)
> N.B. you don't need to CC yourself on bugs, the reporter always gets sent
> changes to the bug

Thanks, next time I won't be so paranoid about mail notifications!

*** This bug has been marked as a duplicate of bug 5142 ***
Comment 4 Antony Polukhin 2013-02-04 07:28:04 UTC
Oh, thanks for clarification!  
Initially I was confused by the fact that std::is_nothrow_constructible checks for destructor, but I thought that it is a 'noexcept()' bug. Now I see that this issue is a duplicate for #51452.

(In reply to comment #2)
> N.B. you don't need to CC yourself on bugs, the reporter always gets sent
> changes to the bug

Thanks, next time I won't be so paranoid about mail notifications!
Comment 5 Antony Polukhin 2013-02-04 07:29:16 UTC

*** This bug has been marked as a duplicate of bug 51452 ***