Open philnik777 opened 1 month ago
Do you have a reproducer?
https://godbolt.org/z/vso3T86Me
namespace std {
template <class T>
T* launder(T* ptr) noexcept {
return __builtin_launder(ptr); // expected-error {{function pointer argument to '__builtin_launder' is not allowed}}
}
inline constexpr bool is_constant_evaluated() {
return __builtin_is_constant_evaluated();
}
}
void func();
auto test() {
std::launder(&func);
if constexpr (std::is_constant_evaluated()) {} // expected-warning {{'std::is_constant_evaluated' will always evaluate to 'true' in a manifestly constant-evaluated expression}}
}
Clang diagnoses erroneous uses of
__builtin_launder
, but doesn't produce nice diagnostics when it's used instd::launder
currently.__builtin_is_constant_evaluated
detects when it's used insidestd::is_constant_evaluated
to produce nicer diagnostics. It would be great if clang could do this too for__builtin_launder
, since it would allow us to remove a fewstatic_assert
s insidestd::launder
in libc++ to get some really nice diagnostics for this.