[libcxx-commits] [libcxx] [libc++] Avoid type-punning between __value_type and pair (PR #134819)
Jorge Gorbe Moya via libcxx-commits
libcxx-commits at lists.llvm.org
Fri May 16 17:12:05 PDT 2025
slackito wrote:
The error referenced by @cmtice above should be reproducible with something like:
```
#include <set>
#include <utility>
void f() {
std::set<std::pair<int, int>> s1;
std::set<std::pair<int, int>> s2;
s2 = s1;
}
```
The error message looks like this:
```
In file included from experimental/users/jgorbe/libcxx-repro/a.cc:1:
In file included from third_party/stl/cxx17/set:4:
In file included from third_party/crosstool/v18/llvm_unstable/src/libcxx/include/set:537:
third_party/crosstool/v18/llvm_unstable/src/libcxx/include/__tree:1292:5: error: const_cast from 'int' to '__key_type &' (aka 'std::pair<int, int> &') is not allowed
1292 | const_cast<__key_type&>(__lhs.first) = const_cast<__copy_cvref_t<_From, __key_type>&&>(__rhs.first);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
third_party/crosstool/v18/llvm_unstable/src/libcxx/include/__tree:1441:7: note: in instantiation of function template specialization 'std::__tree<std::pair<int, int>, std::less<std::pair<int, int>>, std::allocator<std::pair<int, int>>>::__assign_value<const std::pair<int, int> &, 0>' requested here
1441 | __assign_value(__cache.__get()->__value_, *__first);
| ^
third_party/crosstool/v18/llvm_unstable/src/libcxx/include/__tree:1404:5: note: in instantiation of function template specialization 'std::__tree<std::pair<int, int>, std::less<std::pair<int, int>>, std::allocator<std::pair<int, int>>>::__assign_multi<std::__tree_const_iterator<std::pair<int, int>, std::__tree_node<std::pair<int, int>, void *> *, long>>' requested here
1404 | __assign_multi(__t.begin(), __t.end());
| ^
third_party/crosstool/v18/llvm_unstable/src/libcxx/include/set:666:13: note: in instantiation of member function 'std::__tree<std::pair<int, int>, std::less<std::pair<int, int>>, std::allocator<std::pair<int, int>>>::operator=' requested here
666 | __tree_ = __s.__tree_;
| ^
experimental/users/jgorbe/libcxx-repro/a.cc:8:6: note: in instantiation of member function 'std::set<std::pair<int, int>>::operator=' requested here
8 | s2 = s1;
| ^
1 error generated.
```
https://github.com/llvm/llvm-project/pull/134819
More information about the libcxx-commits
mailing list