Issue 81089
Summary Clang rejects valid code for incorrectly choosing protected destructor in list initilization
Labels clang
Assignees
Reporter wangbo15
    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)

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to