[Bug c++/106812] Throwing a non-copyable exception

chgros at coverity dot com gcc-bugzilla@gcc.gnu.org
Fri Oct 14 18:18:35 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106812

Charles-Henri Gros <chgros at coverity dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |chgros at coverity dot com

--- Comment #4 from Charles-Henri Gros <chgros at coverity dot com> ---
It's worse than this, "throw" will even move a non-movable value in the absence
of a copy constructor:

#include <iostream>
#include <memory>

using namespace std;

int main(int argc, char const * const *argv)
{
    unique_ptr<int> u(new int);
    cout << "u.get() first: " << (void*)u.get() << endl;
    try {
        throw u;
    } catch(...) {
    }
    cout << "u.get() after throw: " << (void*)u.get() << endl;
}


More information about the Gcc-bugs mailing list