<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/81089>81089</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang rejects valid code for incorrectly choosing protected destructor in list initilization
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
wangbo15
</td>
</tr>
</table>
<pre>
The following code should be valid accroding to C++ syntax, since the protected destructor of the `Base` class can be implicitly called through the calling of `Derived` class's dtor, which is public:
```c++
struct Base {
protected:
~Base() = default;
};
struct Derived : Base{
};
int main(){
Derived d{};
}
```
However we find it does not compile in `clang 17.0.1` and `clang-trunk`. It comes out that the compiler complains about the usage of protected base destructor. When we replace the statement `Derived d{};` with `Derived d;` in the function `main`, the code compiles well.
```
<source>:10:15: error: temporary of type 'Base' has protected destructor
10 | Derived d{};
| ^
<source>:3:5: note: declared protected here
3 | ~Base() = default;
| ^
1 error generated.
```
[https://godbolt.org/z/3nGbj15M3](https://godbolt.org/z/3nGbj15M3)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVMGO4zYM_RrlQowhS7EdH3yYTDZtD70V6FmWaFtbRTIkedLsod9eSM462e1gu4OB7VDU4yP5SBGCHi1iR6ojqU47scTJ-e4q7Ni7str1Tt26PyaEwRnjrtqOIJ1CCJNbjIIe4V0YrUBI6Z1Kx9HBG2FHwo4QbjaKvwl7g6CtRIgTwuxdRBlRgcIQ_SKj8-CGfEZqehQBSU1BGhECSGFTCH2ZjZY6mhtIYQwqiJN3yzjlW8mUArshAZzQ63dUGwZhTQAVnU80rpOWE-gA89IbLQl_JfRE6NdnTdd_ufJfrStJSMSANHfjlsUGAQDwT2bPDoS1QPgJFA5iMZHwI8A9RHMi_Pgc9A5_pw2Ev-ZQW6T_3tA2wkVouwbaHBOBrygqWZ8vNqfvUnwG_NVd8R09XBEGbRXoCMphAOsiSH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