[PATCH] safe-ctype.h: Fix building with latest libc++

Manoj Gupta manojgupta@google.com
Thu Apr 13 19:44:42 GMT 2023


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(-)

diff --git a/include/safe-ctype.h b/include/safe-ctype.h
index a3cb1858efc..843ba98571c 100644
--- a/include/safe-ctype.h
+++ b/include/safe-ctype.h
@@ -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
-- 
2.40.0.634.g4ca3ef3211-goog



More information about the Gdb-patches mailing list