safe-ctype.h: Fix building with latest libc++
Commit Message
Latest libc++[1] causes transitive include to <locale> when
<mutex> or <thread> header is included. This causes
gdb to not build[2] since <locale> defines isupper/islower etc.
functions that are explicitly macroed-out in safe-ctype.h to
prevent their use.
Use the suggestion from libc++ to include <locale> internally when
building in C++ mode to avoid build errors.
[1]: https://reviews.llvm.org/D144331
[2]: https://issuetracker.google.com/issues/277967395
---
include/safe-ctype.h | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
Comments
>>>>> Manoj Gupta via Gdb-patches <gdb-patches@sourceware.org> writes:
> Latest libc++[1] causes transitive include to <locale> when
> <mutex> or <thread> header is included. This causes
> gdb to not build[2] since <locale> defines isupper/islower etc.
> functions that are explicitly macroed-out in safe-ctype.h to
> prevent their use.
> Use the suggestion from libc++ to include <locale> internally when
> building in C++ mode to avoid build errors.
> [1]: https://reviews.llvm.org/D144331
> [2]: https://issuetracker.google.com/issues/277967395
> ---
> include/safe-ctype.h | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
This file is canonically maintained in gcc, so changes have to go there
first.
Alternatively you could perhaps change gdbsupport/gdb-safe-ctype.h,
though that might require fixing up the odd #include elsewhere.
Tom
@@ -117,9 +117,16 @@ extern const unsigned char _sch_tolower[256];
detecting that ctype.h has been included. But this was causing
trouble as ctype.h might get indirectly included as a result of
including another system header (for instance gnulib's stdint.h).
- So we include ctype.h here and then immediately redefine its macros. */
+ So we include ctype.h here and then immediately redefine its macros.
+ When compiling in C++ mode, aldo add <locale> which also defines
+ is* functions.
+*/
#include <ctype.h>
+#ifdef __cplusplus
+#include <locale>
+#endif
+
#undef isalpha
#define isalpha(c) do_not_use_isalpha_with_safe_ctype
#undef isalnum