This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/65748] New: [C++11][C++14]Invalid copy elision on operand of throw-exception
- From: "frankhb1989 at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 12 Apr 2015 13:04:08 +0000
- Subject: [Bug c++/65748] New: [C++11][C++14]Invalid copy elision on operand of throw-exception
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65748
Bug ID: 65748
Summary: [C++11][C++14]Invalid copy elision on operand of
throw-exception
Product: gcc
Version: 4.9.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: frankhb1989 at gmail dot com
Case:
struct E
{
E() = default;
E(const E&) = delete;
E(E&&) = default;
};
int main()
{
E e;
try
{
// E e; // Not here.
throw e;
}
catch(...)
{}
}
No diagnostics with g++ -std=c++14 -pedantic -Wall -Wextra. Same to -std=c++11.
It seems the move constructor is selected according to 12.8/32, which depends
on copy elision.
However, both ISO C++11 and C++14 forbid copy elision in this case, i.e. for
operand of throw-expression, it may be elided only when:
whose scope does not extend beyond the end of the innermost enclosing try-block
(if there is one)
as per 12.8/31.2.