Skip to content

Commit

Permalink
[libc++] Include "bits/alltypes.h" to provide mbstate_t when using mu…
Browse files Browse the repository at this point in the history
…sl libc

With D148542, we ran into the following libc++ build error when using musl libc.

```
.../musl/include/bits/alltypes.h:354:16:
error: definition of type '__mbstate_t' conflicts with typedef of the same name
typedef struct __mbstate_t { unsigned __opaque1, __opaque2; } mbstate_t;
               ^
.../sysroot/usr/include/bits/types/__mbstate_t.h:21:3: note: '__mbstate_t' declared here
} __mbstate_t;
  ^
1 error generated.
```
This is because the mbstate_t definition in musl libc conflicts with the one
from "bits/types/mbstate_t.h", and this patch attempts to fix this build issue
when musl libc is used.

Reviewed By: iana

Differential Revision: https://reviews.llvm.org/D151740
  • Loading branch information
pzhengqc committed May 31, 2023
1 parent 7a1077b commit fef23e8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion libcxx/include/__mbstate_t.h
Expand Up @@ -35,7 +35,11 @@
# define __CORRECT_ISO_CPP_WCHAR_H_PROTO
#endif

#if __has_include(<bits/types/mbstate_t.h>)
#if defined(_LIBCPP_HAS_MUSL_LIBC)
# define __NEED_mbstate_t
# include <bits/alltypes.h>
# undef __NEED_mbstate_t
#elif __has_include(<bits/types/mbstate_t.h>)
# include <bits/types/mbstate_t.h> // works on most Unixes
#elif __has_include(<sys/_types/_mbstate_t.h>)
# include <sys/_types/_mbstate_t.h> // works on Darwin
Expand Down

0 comments on commit fef23e8

Please sign in to comment.