[libcxx-commits] [libcxx] [libc++] Fix type confusion in hash_{, multi}map (PR #183223)
Peter Collingbourne via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Feb 24 18:13:14 PST 2026
pcc wrote:
With standard layout types the language provides the "common initial sequence" guarantee, which makes `std::pair<foo, bar>` and `std::pair<const foo, bar>` interchangeable if `foo` and `bar` are standard layout. See e.g. https://eel.is/c++draft/class.mem#general-27.4 (the example with A and B shows qualifiers specifically).
But with non-standard layout the compiler could in theory choose to use a different field ordering or do any other kind of transformation it wants to the field layout for the two types, which is the same freedom that PFP takes advantage of to detect type confusion.
Regarding strictness: this method of detecting type confusion has in practice had a very low false positive rate, so I'm not sure that we need to make any changes here.
https://github.com/llvm/llvm-project/pull/183223
More information about the libcxx-commits
mailing list