Issue 91601
Summary [libc++] std::map<> with const key doesn't compile
Labels libc++
Assignees
Reporter JamiKettunen
    With clang++ 18.1.4 using libc++ the following doesn't compile (as originally seen in https://github.com/canonical/mir/issues/3383)
```cpp
#include <map>

using map=std::map<int const, int>;

int main() {
  map a, b;
  a = b;
}
```
```
$ clang++ -v test.cpp
clang version 18.1.4
Target: x86_64-chimera-linux-musl
Thread model: posix
InstalledDir: /usr/bin
System configuration file directory: /etc/clang
 "/usr/bin/clang-18" -cc1 -triple x86_64-chimera-linux-musl -emit-obj -mrelax-all -dumpdir a- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/home/deathmist -v -fcoverage-compilation-dir=/home/deathmist -resource-dir /usr/lib/clang/18 -internal-isystem /usr/bin/../include/c++/v1 -internal-isystem /usr/local/include -internal-externc-isystem /usr/include/fortify -internal-externc-isystem /usr/include -internal-isystem /usr/lib/clang/18/include -include stdc-predef.h -fdeprecated-macro -ferror-limit 19 -stack-protector 2 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/test-fdefa8.o -x c++ test.cpp
clang -cc1 version 18.1.4 based upon LLVM 18.1.4 default target x86_64-chimera-linux-musl
#include "..." search starts here:
#include <...> search starts here:
 /usr/bin/../include/c++/v1
 /usr/local/include
 /usr/include/fortify
 /usr/include
 /usr/lib/clang/18/include
End of search list.
In file included from test.cpp:1:
/usr/bin/../include/c++/v1/map:797:13: error: no viable overloaded '='
  797 |     __ref() = __v.__get_value();
      | ~~~~~~~ ^ ~~~~~~~~~~~~~~~~~
/usr/bin/../include/c++/v1/__tree:1435:33: note: in instantiation of member function 'std::__value_type<const int, int>::operator=' requested here
 1435 |       __cache.__get()->__value_ = *__first;
      | ^
/usr/bin/../include/c++/v1/__tree:1398:5: note: in instantiation of function template specialization 'std::__tree<std::__value_type<const int, int>, std::__map_value_compare<const int, std::__value_type<const int, int>, std::less<const int>>, std::allocator<std::__value_type<const int, int>>>::__assign_multi<std::__tree_const_iterator<std::__value_type<const int, int>, std::__tree_node<std::__value_type<const int, int>, void *> *, long>>' requested here
 1398 |     __assign_multi(__t.begin(), __t.end());
      |     ^
/usr/bin/../include/c++/v1/map:1082:13: note: in instantiation of member function 'std::__tree<std::__value_type<const int, int>, std::__map_value_compare<const int, std::__value_type<const int, int>, std::less<const int>>, std::allocator<std::__value_type<const int, int>>>::operator=' requested here
 1082 |     __tree_ = __m.__tree_;
 |             ^
test.cpp:7:5: note: in instantiation of member function 'std::map<const int, int>::operator=' requested here
    7 |   a = b;
 |     ^
/usr/bin/../include/c++/v1/__utility/pair.h:289:3: note: candidate function not viable: no known conversion from 'const value_type' (aka 'const pair<const int, int>') to 'const __conditional_t<is_copy_assignable<first_type>::value && is_copy_assignable<second_type>::value, pair<const int &, int &>, __nat>' (aka 'const std::__nat') for 1st argument
  289 | operator=(__conditional_t< is_copy_assignable<first_type>::value && is_copy_assignable<second_type>::value,
      |   ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 290 |                              pair,
      | ~~~~~
  291 |                              __nat> const& __p)
 | ~~~~~~~~~~~~~~~~~
/usr/bin/../include/c++/v1/__utility/pair.h:298:61: note: candidate function not viable: no known conversion from 'const value_type' (aka 'const pair<const int, int>') to '__conditional_t<is_move_assignable<first_type>::value && is_move_assignable<second_type>::value, pair<const int &, int &>, __nat>' (aka 'std::__nat') for 1st argument
  298 |   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair& operator=(
      | ^
  299 |       __conditional_t< is_move_assignable<first_type>::value && is_move_assignable<second_type>::value, pair, __nat>&&
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 300 |           __p)
      | ~~~
/usr/bin/../include/c++/v1/__utility/pair.h:311:61: note: candidate template ignored: requirement 'is_assignable<const int &, const int &>::value' was not satisfied [with _U1 = const int, _U2 = int]
  311 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair& operator=(pair<_U1, _U2> const& __p) {
      | ^
/usr/bin/../include/c++/v1/__utility/pair.h:321:61: note: candidate template ignored: requirement 'is_assignable<const int &, const int>::value' was not satisfied [with _U1 = const int, _U2 = int]
  321 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair& operator=(pair<_U1, _U2>&& __p) {
      | ^
/usr/bin/../include/c++/v1/__utility/pair.h:422:61: note: candidate template ignored: could not match 'tuple' against 'pair'
  422 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair& operator=(tuple<_U1, _U2> const& __p) {
      | ^
/usr/bin/../include/c++/v1/__utility/pair.h:431:61: note: candidate template ignored: could not match 'tuple' against 'pair'
  431 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair& operator=(tuple<_U1, _U2>&& __p) {
      | ^
/usr/bin/../include/c++/v1/__utility/pair.h:463:61: note: candidate template ignored: could not match 'array' against 'pair'
  463 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair& operator=(array<_Up, 2> const& __p) {
      | ^
/usr/bin/../include/c++/v1/__utility/pair.h:470:61: note: candidate template ignored: could not match 'array' against 'pair'
  470 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair& operator=(array<_Up, 2>&& __p) {
      | ^
/usr/bin/../include/c++/v1/__utility/pair.h:80:29: note: candidate function (the implicit copy assignment operator) not viable: no known conversion from 'const pair<const key_type, mapped_type>' to 'const pair<const int &, int &>' for 1st argument
   80 | struct _LIBCPP_TEMPLATE_VIS pair
      |                             ^~~~
1 error generated.
```
Switching line 3 of the example with `using map=std::map<int, int>;` does compile fwiw.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to