Catching an exception by value - gcc and clang disagree

Viewed 200

Consider this short snippet:

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

struct D : B { };

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

gcc accepts this code, clang considers it ill-formed with:

main.cpp:17:13: error: no matching constructor for initialization of 'B'
    catch(B ) {
            ^

Who's right?

1 Answers
Related