http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58629

            Bug ID: 58629
           Summary: Do not implicit move instance for throw operator
           Product: gcc
           Version: 4.7.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dmitriy-hshg at mail dot ru

Created attachment 30959
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30959&action=edit
Example

It is good idea to use move semantics for throw operator: 

    std::runtime_error error("message");
    ...
    throw error; // execution of this block ends => we can implicit move
'error'.

but it may be used only for instances (variables) defined in try {} block. For
other instances a copy semantics must be applied:

    std::runtime_error error("message");
    ...
    try {
        ...
        throw error; // we can return to outside block and get access to
'error' again => we must copy 'error' 
    } catch (std::runtime_error &e) {
        std::cout << error.what(); // It must be OK!
    }

I have attached an example of code. In GCC instance is always implicity moved.



Expected result:

'error' must be valid in catch(){} block

Actual result:

'error' is invalid in catch(){} block because it is moved in throw error;

Reply via email to