以下代码在 gcc 9.1 godbolt中编译,但在 clang 8 godbolt中编译:
class A {
protected:
~A() = default;
};
class B final : public A {
};
int main() {
auto b = B{};
}
Clang的错误:
<source>:10:16: error: temporary of type 'A' has protected destructor
auto b = B{};
^
<source>:3:5: note: declared protected here
~A() = default;
^
哪个是正确的,为什么?