https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126278
Bug ID: 126278
Summary: constexpr cast to void* is overly permissive
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ryan.keane051 at gmail dot com
Target Milestone: ---
```
struct A {};
struct B {};
struct C : B, A {};
static_assert([] {
C c{};
void* v = &c;
auto* b = static_cast<B*>(v);
return true;
}());
```
constexpr cast to void* should only allow casting directly back to C, but this
code currently compiles on Compiler Explorer. For reference, clang-trunk says:
cast from 'void *' is not allowed in a constant expression because the pointed
object type 'C' is not similar to the target type 'B'
11 | auto* b = static_cast<B*>(v);
https://godbolt.org/z/Wanvjq3zd