https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117154
Bug ID: 117154
Summary: Aggregate initialization with protected destructor in
Base class: GCC vs Clang difference
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: carlosgalvezp at gmail dot com
Target Milestone: ---
Hi,
Consider this code:
struct Base
{
protected:
~Base() = default;
};
struct Derived : Base
{};
int main()
{
Derived d{};
}
https://godbolt.org/z/eh19eorGG
Compiled in C++17 mode, Clang rejects the code:
<source>:12:15: error: temporary of type 'Base' has protected destructor
12 | Derived d{};
| ^
<source>:4:5: note: declared protected here
4 | ~Base() = default;
| ^
While GCC is fine with it. This was filed as an issue to Clang, but the
response was that this was intended behavior:
https://github.com/llvm/llvm-project/issues/81089#issuecomment-1998568533
I'm curious to hear GCC's opinion on the matter, why doesn't GCC reject the
code? It'd be good if both compilers agreed on whether the code is ill-formed
or not.