Bug 121579 - static_cast involving pointers to members is too loose during constant evaluation
Summary: static_cast involving pointers to members is too loose during constant evalua...
Status: RESOLVED DUPLICATE of bug 109243
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 16.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2025-08-17 23:52 UTC by Halalaluyafail3
Modified: 2025-08-18 00:00 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Halalaluyafail3 2025-08-17 23:52:59 UTC
GCC incorrectly allows the following program:

consteval int foo(){
    struct A{char x;};
    struct B{char y;};
    struct C:A,B{};
    char C::*p=&A::x;
    char B::*q=static_cast<char B::*>(p);
    C c{};
    return((B&)c).*q;
}
int main(){
    return foo();
}

This program should be rejected since the static_cast has undefined behavior. The member x is neither in B, nor a class derived from B.
Comment 1 Drea Pinski 2025-08-18 00:00:31 UTC
Almost an exact Dup.

*** This bug has been marked as a duplicate of bug 109243 ***