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

            Bug ID: 103048
           Summary: Mandatory copy elision used for catch-by-value
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: songyuanyao at qq dot com
  Target Milestone: ---

struct B {
    B() = default;
    B(const B&) = delete;
};

int main() {
    try {
        throw B{};
    }
    catch (B) {}
}

This code shouldn't compile according to [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
([class.copy.elision]).

Reply via email to