[Bug c++/104046] New: C++ compiler should forbid throw move-only type

fsb4000 at yandex dot ru gcc-bugzilla@gcc.gnu.org
Sun Jan 16 07:09:31 GMT 2022


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

            Bug ID: 104046
           Summary: C++ compiler should forbid throw move-only type
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fsb4000 at yandex dot ru
  Target Milestone: ---

Hello.
We were reported a bug: https://github.com/microsoft/STL/issues/2466
But we think that the report is wrong.

Code:

#include <exception>
#include <string>
using namespace std;

class C {
public:
  C() = default;
  C(const C&) = delete;
  C& operator=(const C&) = delete;
  C(C&&) = default;
  C& operator=(C&&) = default;

private:
  string m;
};

int main() {
  exception_ptr eptr;
  try {
    throw C();
  } catch (const C&) {
    eptr = std::current_exception();
  }
  try {
    rethrow_exception(eptr);
  } catch (const C&) {
  }
}

godbolt: https://godbolt.org/z/GKTGbjbvK


We think that C++ compiler should reject the program because the program
violates [except.throw]/5: https://eel.is/c++draft/except.throw#5

Quote: "When the thrown object is a class object, the constructor selected for
the copy-initialization as well as the constructor selected for a
copy-initialization considering the thrown object as an lvalue shall be
non-deleted and accessible, even if the copy/move operation is elided"

We decided to notify developers of other C++ compilers too.


More information about the Gcc-bugs mailing list