-
Notifications
You must be signed in to change notification settings - Fork 11.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clang rejects valid code for incorrectly choosing protected destructor in list initilization #81089
Comments
@llvm/issue-subscribers-clang-frontend Author: Bo Wang (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:
struct Base {
protected:
~Base() = default;
};
struct Derived : Base{
};
int main(){
Derived d{};
} However we find it does not compile in
|
I believe this is correct before C++20: https://reviews.llvm.org/D53860 I would have to look up the details to figure out where this changed. |
In C++17 onwards, |
Are there any updates on this issue? I just checked and GCC and MSVC handle this correctly. Btw here's a working link to CWG 2244: @shafik I see this is tagged as "C++20 in Clang", but shouldn't this be tagged as C++17? |
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 ofDerived
class's dtor, which is public:However we find it does not compile in
clang 17.0.1
andclang-trunk
. It comes out that the compiler complains about the usage of protected base destructor. When we replace the statementDerived d{};
withDerived d;
in the functionmain
, the code compiles well.https://godbolt.org/z/3nGbj15M3
The text was updated successfully, but these errors were encountered: