[libcxx-commits] [PATCH] D150015: [libc++] Consistently enable __CORRECT_ISO_CPP_WCHAR_H_PROTO in mbstate.
Fangrui Song via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Sat May 6 16:53:58 PDT 2023
MaskRay added a comment.
glibc before 2.26 did not provide [`bits/types/mbstate_t.h`](https://sourceware.org/git/?p=glibc.git;a=commit;h=199fc19d3aaaf57944ef036e15904febe877fc93).
If we include `iosfwd` before `cwchar`, we will include glibc `wchar.h` without defining `__CORRECT_ISO_CPP_WCHAR_H_PROTO` and will get the "incorrect" declarations.
#ifdef X
#include <iosfwd>
#include <cwchar>
#else
#include <cwchar>
#include <iosfwd>
#endif
int main() {
wchar_t *v1;
const wchar_t *cv2 = L"/";
v1 = wcsstr(cv2, L"/"); // should fail
}
% clang --sysroot=glibc-2.25 -stdlib=libc++ -c test.cc
test.cc:11:8: error: assigning to 'wchar_t *' from 'const wchar_t *' discards qualifiers
v1 = wcsstr (cv2, L"/");
^~~~~~~~~~~~~~~~~~
1 error generated.
% clang --sysroot=glibc-2.25 -stdlib=libc++ -c test.cc -DX # no error
---
If we change the libc++ `module.modulemap` file (in my build, `/tmp/Rel/include/c++/v1/module.modulemap`) to be a textual header, or just remove the entry from the modulemap file,
module __mbstate_t { private textual header "__mbstate_t.h" export * }
the following command will fail. (Yes, we use `-x c++` even when compiling a modulemap file, otherwise Clang will consider the modulemap file an object file for linking.)
% clang --sysroot=glibc-2.25 -stdlib=libc++ -c -Xclang -emit-module -fmodules -fmodule-name=std -Xclang=-fmodules-local-submodule-visibility -xc++ /tmp/Rel/include/c++/v1/module.modulemap -o std.pcm
...
In file included from /tmp/Rel/bin/../include/c++/v1/__mbstate_t.h:35:
glibc-2.25/include/wchar.h:227:17: error: functions that differ only in their return type cannot be overloaded
extern wchar_t *wcschr (const wchar_t *__wcs, wchar_t __wc)
~~~~~~~~~^
glibc-2.25/include/wchar.h:224:29: note: previous declaration is here
extern "C++" const wchar_t *wcschr (const wchar_t *__wcs, wchar_t __wc)
~~~~~~~~~^
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D150015/new/
https://reviews.llvm.org/D150015
More information about the libcxx-commits
mailing list