Skip to content

C++ compiler should forbid throw move-only type #53224

Open
@fsb4000

Description

@fsb4000

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

#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&) {
  }
}

https://godbolt.org/z/q3cYGfneP

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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions