[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

Mariya Podchishchaeva via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 11 03:55:36 PDT 2024


Fznamznon wrote:

Ok, now I looked at it a bit more, and I think this is expected due to the change and how clang behaved before this patch. After this patch implicit destructor of S, i.e. `~S` becomes `constexpr`. It used to be not `constexpr` because neither `P` nor `B` had `constexpr` destructors. clang defines and emits errors for constexpr defaulted members due to this bit here:
https://github.com/llvm/llvm-project/blob/0ef61ed54dca2e974928c55b2144b57d4c4ff621/clang/lib/Sema/SemaDeclCXX.cpp#L7225

So, once I manually change this example to force `~S()` to be `constexpr`, older clang produces the same error:
```
template<typename T> struct P {
    cosntexpr ~P() { p->f(); } // add constexpr
    T * p;
};
struct X;
struct B { virtual constexpr ~B(); }; // add constexpr
struct S: B { P<X> x; }; // now all bases and members have constexpr destructors, ~S() is constexpr
```
Demo https://godbolt.org/z/rT3bWMdqz (note I took 18.1.0 clang which doesn't have P2448R2 implementation). 

I'm not quite sure the error itself is correct, I've got to educate myself about standard matters a bit more to understand this, but no other compiler errors on this https://godbolt.org/z/Ehhn5sno7.

cc @AaronBallman , @cor3ntin, @zygoloid in case you can weigh in here

https://github.com/llvm/llvm-project/pull/77753


More information about the cfe-commits mailing list