The following code compiles in gcc 9.1 godbolt but not clang 8 godbolt:
class A {
protected:
~A() = default;
};
class B final : public A {
};
int main() {
auto b = B{};
}
Run Code Online (Sandbox Code Playgroud)
Clang's error:
<source>:10:16: error: temporary of type 'A' has protected destructor
auto b = B{};
^
<source>:3:5: note: declared protected here
~A() = default;
^
Run Code Online (Sandbox Code Playgroud)
Which is correct and why?