Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fsb4000 opened this issue Jan 16, 2022 · 3 comments
Open

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

fsb4000 opened this issue Jan 16, 2022 · 3 comments
Labels
c++ clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@fsb4000
Copy link
Member

fsb4000 commented Jan 16, 2022

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.

@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed new issue labels Jan 16, 2022
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 16, 2022

@llvm/issue-subscribers-clang-frontend

@Quuxplusone
Copy link
Contributor

This is https://quuxplusone.github.io/blog/2019/05/11/msvc-what-are-you-doing/ Basically, MSVC's ABI can't handle move-only exception types, but every other ABI in the world can. I would bet that it's not possible to forbid move-only exception types in Clang (because I bet some non-Windows customers rely on it), but it could certainly be made into a warning diagnostic, enabled with -Wall and/or -pedantic.

@Quuxplusone Quuxplusone added the clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer label Jan 17, 2022
@Endilll Endilll added c++ and removed clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer labels Jan 20, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 20, 2024

@llvm/issue-subscribers-c-1

Author: Igor Zhukov (fsb4000)

Hello. We were reported a bug: https://github.com/microsoft/STL/issues/2466 But we think that the report is wrong.
#include &lt;exception&gt;
#include &lt;string&gt;
using namespace std;

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

private:
  string m;
};

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

5 participants