<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/148280>148280</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [libc++] const overload errors with musl
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            libc++
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          tbwLcFm5uXcAeQ
      </td>
    </tr>
</table>

<pre>
    Building [elfutils v0.193](https://sourceware.org/elfutils/ftp/0.193) with LLVM 20.1.7 (libcxx, libcxxabi, compiler-rt and libunwind are enabled by default) and musl (fresh build from master head) fails with a bunch of `wchar.h` and `string.h` const overload errors:

```
/pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/string.h:77:69: error: functions that differ only in their return type cannot be overloaded
 77 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const char* strchr(const char* __s, int __c) {
      | ~~~~~ ^
/pkg/musl/include/string.h:45:7: note: previous declaration is here
   45 | char *strchr (const char *, int);
 | ~~~~~~^
```

I couldn't find any reports about this matter; and considering the fact that these const overloads have been in place for 10 years, I wouldn't be surprised if there is an issue with my environment.

Full error:
```
clang++ -std=c++11 -D_GNU_SOURCE -DHAVE_CONFIG_H -DLOCALEDIR='"/pkg/.elfutils/v/0.193-1/share/locale"' -DDEBUGPRED=0 
-DSRCDIR=\"/pkg/.elfutils/src/src\" -DOBJDIR=\"/pkg/.elfutils/src/build/src\"   -iquote . -I../../src -I../../lib -I.. 
-I../../src/../libelf -I../../src/../libebl -I../../src/../libdw -I../../src/../libdwelf -I../../src/../libdwfl 
-I../../src/../libdwfl_stacktrace -I../../src/../libasm -I../debuginfod -std=c++11 -Wall -Wshadow -Werror -Wunused 
-Wextra -v -march=native -O3 -Wno-error -I/pkg/zlib/include -I/pkg/uargp/include -I/pkg/fts/include -I/pkg/obstack/include 
-L/pkg/zlib/lib -L/pkg/uargp/lib -L/pkg/fts/lib -L/pkg/obstack/lib -MT srcfiles.o -MD -MP -MF .deps/srcfiles.Tpo 
-c -o srcfiles.o ../../src/srcfiles.cxx

clang version 20.1.7
Target: x86_64-x-linux-musl
Thread model: posix
InstalledDir: /pkg/.llvm/v/20.1.7-3/bin
System configuration file directory: /pkg/.llvm/v/20.1.7-3/cfg
  /pkg/.llvm/v/20.1.7-3/bin/clang-20 -cc1 -triple x86_64-x-linux-musl -emit-obj -disable-free -clear-ast-before-backend 
 -disable-llvm-verifier -discard-value-names -main-file-name srcfiles.cxx -mrelocation-model pic -pic-level 2 -pic-is-pie 
  -mframe-pointer=none -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu skylake 
  -target-feature +prfchw -target-feature -cldemote -target-feature +avx -target-feature +aes -target-feature +sahf -target-feature +pclmul [...]
  -debugger-tuning=gdb -fdebug-compilation-dir=/pkg/.elfutils/src/build/src -v -fcoverage-compilation-dir=/pkg/.elfutils/src/build/src 
  -resource-dir /pkg/.llvm/v/20.1.7-3/lib/clang/20 -dependency-file .deps/srcfiles.Tpo -MT srcfiles.o -sys-header-deps -MP 
  -iquote . -D _GNU_SOURCE -D HAVE_CONFIG_H -D "LOCALEDIR=\"/pkg/.elfutils/v/0.193-1/share/locale\"" -D DEBUGPRED=0 
  -D "SRCDIR=\"/pkg/.elfutils/src/src\"" -D "OBJDIR=\"/pkg/.elfutils/src/build/src\"" -I ../../src -I ../../lib -I .. 
  -I ../../src/../libelf -I ../../src/../libebl -I ../../src/../libdw -I ../../src/../libdwelf -I ../../src/../libdwfl 
  -I ../../src/../libdwfl_stacktrace -I ../../src/../libasm -I ../debuginfod -I /pkg/zlib/include -I /pkg/uargp/include 
  -I /pkg/fts/include -I /pkg/obstack/include -c-isystem /pkg/linux/include -cxx-isystem /pkg/linux/include 
  -internal-isystem /pkg/.llvm/v/20.1.7-3/bin/../include/x86_64-x-linux-musl/c++/v1 -internal-isystem /pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1 
 -internal-isystem /pkg/musl/include -internal-isystem /pkg/.llvm/v/20.1.7-3/lib/clang/20/include -O3 -Wall -Wshadow -Werror -Wunused 
  -Wextra -Wno-error -std=c++11 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions 
  -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o srcfiles.o -x c++ ../../src/srcfiles.cxx
clang -cc1 version 20.1.7 based upon LLVM 20.1.7 default target x86_64-x-linux-musl
#include "..." search starts here:
 .
#include <...> search starts here:
 ../../src
 ../../lib
 ..
 ../../src/../libelf
 ../../src/../libebl
 ../../src/../libdw
 ../../src/../libdwelf
 ../../src/../libdwfl
 ../../src/../libdwfl_stacktrace
 ../../src/../libasm
 ../debuginfod
 /pkg/zlib/include
 /pkg/uargp/include
 /pkg/fts/include
 /pkg/obstack/include
 /pkg/linux/include
 /pkg/.llvm/v/20.1.7-3/bin/../include/x86_64-x-linux-musl/c++/v1
 /pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1
 /pkg/musl/include
 /pkg/.llvm/v/20.1.7-3/lib/clang/20/include
End of search list.
In file included from ../../src/srcfiles.cxx:37:
In file included from /pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/cstring:66:
/pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/string.h:77:69: error: functions that differ only in their return type cannot be overloaded
 77 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const char* strchr(const char* __s, int __c) {
      | ~~~~~ ^
/pkg/musl/include/string.h:45:7: note: previous declaration is here
   45 | char *strchr (const char *, int);
 | ~~~~~~^
In file included from ../../src/srcfiles.cxx:37:
In file included from /pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/cstring:66:
/pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/string.h:84:69: error: functions that differ only in their return type cannot be overloaded
 84 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const char* strpbrk(const char* __s1, const char* __s2) {
      | ~~~~~ ^
/pkg/musl/include/string.h:50:7: note: previous declaration is here
   50 | char *strpbrk (const char *, const char *);
      | ~~~~~~^
In file included from ../../src/srcfiles.cxx:37:
In file included from /pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/cstring:66:
/pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/string.h:91:69: error: functions that differ only in their return type cannot be overloaded
 91 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const char* strrchr(const char* __s, int __c) {
      | ~~~~~ ^
/pkg/musl/include/string.h:46:7: note: previous declaration is here
   46 | char *strrchr (const char *, int);
 | ~~~~~~^
In file included from ../../src/srcfiles.cxx:37:
In file included from /pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/cstring:66:
/pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/string.h:98:69: error: functions that differ only in their return type cannot be overloaded
 98 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const void* memchr(const void* __s, int __c, size_t __n) {
      | ~~~~~ ^
/pkg/musl/include/string.h:31:7: note: previous declaration is here
   31 | void *memchr (const void *, int, size_t);
      | ~~~~~~^
In file included from ../../src/srcfiles.cxx:37:
In file included from /pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/cstring:66:
/pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/string.h:105:69: error: functions that differ only in their return type cannot be overloaded
 105 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const char* strstr(const char* __s1, const char* __s2) {
      | ~~~~~ ^
/pkg/musl/include/string.h:51:7: note: previous declaration is here
   51 | char *strstr (const char *, const char *);
      | ~~~~~~^
In file included from ../../src/srcfiles.cxx:38:
In file included from /pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/set:519:
In file included from /pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/__algorithm/lexicographical_compare.h:30:
In file included from /pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/cwchar:117:
/pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/wchar.h:144:72: error: functions that differ only in their return type cannot be overloaded
 144 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const wchar_t* wcschr(const wchar_t* __s, wchar_t __c) {
      | ~~~~~~~~ ^
/pkg/musl/include/wchar.h:64:10: note: previous declaration is here
   64 | wchar_t *wcschr (const wchar_t *, wchar_t);
      | ~~~~~~~~~^
In file included from ../../src/srcfiles.cxx:38:
In file included from /pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/set:519:
In file included from /pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/__algorithm/lexicographical_compare.h:30:
In file included from /pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/cwchar:117:
/pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/wchar.h:155:1: error: functions that differ only in their return type cannot be overloaded
 154 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const wchar_t*
      | ~~~~~~~~
  155 | wcspbrk(const wchar_t* __s1, const wchar_t* __s2) {
 | ^
/pkg/musl/include/wchar.h:69:10: note: previous declaration is here
 69 | wchar_t *wcspbrk (const wchar_t *, const wchar_t *);
      | ~~~~~~~~~^
In file included from ../../src/srcfiles.cxx:38:
In file included from /pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/set:519:
In file included from /pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/__algorithm/lexicographical_compare.h:30:
In file included from /pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/cwchar:117:
/pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/wchar.h:165:72: error: functions that differ only in their return type cannot be overloaded
 165 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const wchar_t* wcsrchr(const wchar_t* __s, wchar_t __c) {
      | ~~~~~~~~ ^
/pkg/musl/include/wchar.h:65:10: note: previous declaration is here
   65 | wchar_t *wcsrchr (const wchar_t *, wchar_t);
      | ~~~~~~~~~^
In file included from ../../src/srcfiles.cxx:38:
In file included from /pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/set:519:
In file included from /pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/__algorithm/lexicographical_compare.h:30:
In file included from /pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/cwchar:117:
/pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/wchar.h:176:1: error: functions that differ only in their return type cannot be overloaded
 175 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const wchar_t*
      | ~~~~~~~~
  176 | wcsstr(const wchar_t* __s1, const wchar_t* __s2) {
 | ^
/pkg/musl/include/wchar.h:75:10: note: previous declaration is here
 75 | wchar_t *wcsstr (const wchar_t *__restrict, const wchar_t *__restrict);
      | ~~~~~~~~~^
In file included from ../../src/srcfiles.cxx:38:
In file included from /pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/set:519:
In file included from /pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/__algorithm/lexicographical_compare.h:30:
In file included from /pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/cwchar:117:
/pkg/.llvm/v/20.1.7-3/bin/../include/c++/v1/wchar.h:187:1: error: functions that differ only in their return type cannot be overloaded
 186 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const wchar_t*
      | ~~~~~~~~
  187 | wmemchr(const wchar_t* __s, wchar_t __c, size_t __n) {
 | ^
/pkg/musl/include/wchar.h:78:10: note: previous declaration is here
   78 | wchar_t *wmemchr (const wchar_t *, wchar_t, size_t);
      | ~~~~~~~~~^
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsW0lz4ziT_TXwJQMKEhS1HHyQTataE3a7xlXdnpsCBEEJbXAZA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