This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/65748] New: [C++11][C++14]Invalid copy elision on operand of throw-exception


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]