]> Savannah Git Hosting - gnulib.git/commitdiff
Improve support for clang on Windows.
authorBruno Haible <bruno@clisp.org>
Tue, 27 Aug 2024 19:40:15 +0000 (21:40 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 17 Sep 2024 10:59:05 +0000 (12:59 +0200)
* lib/c++defs.h (_GL_CXXALIASWARN_2): Treat clang like gcc 4.2.
* lib/stdio.in.h (fwrite, fwrite_unlocked): Likewise.
* lib/warn-on-use.h (_GL_WARN_ON_USE, _GL_WARN_ON_USE_CXX): Likewise.
* lib/libc-config.h (__GNUC_PREREQ): Override glibc's definition to
handle clang in disguise.

ChangeLog
lib/c++defs.h
lib/libc-config.h
lib/stdio.in.h
lib/warn-on-use.h

index e84f67b639e5ac1254c9ad8a3673d9badb323692..1a77d4e518c8b0054b3ada5d1bc248f6219bb8c6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-08-27  Bruno Haible  <bruno@clisp.org>
+
+       Improve support for clang on Windows.
+       * lib/c++defs.h (_GL_CXXALIASWARN_2): Treat clang like gcc 4.2.
+       * lib/stdio.in.h (fwrite, fwrite_unlocked): Likewise.
+       * lib/warn-on-use.h (_GL_WARN_ON_USE, _GL_WARN_ON_USE_CXX): Likewise.
+       * lib/libc-config.h (__GNUC_PREREQ): Override glibc's definition to
+       handle clang in disguise.
+
 2024-08-27  Bruno Haible  <bruno@clisp.org>
 
        Explicitly exclude clang when we test for a GCC version >= 4.3.
index eb66967b09be29a360fd3a65c937b1ea4501cc34..5d15e70d6f913b1755cb618ae441f53c4cc7d4f0 100644 (file)
     _GL_WARN_ON_USE (func, \
                      "The symbol ::" #func " refers to the system function. " \
                      "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# elif (__GNUC__ >= 3 || defined __clang__) && GNULIB_STRICT_CHECKING
 #  define _GL_CXXALIASWARN_2(func,namespace) \
      extern __typeof__ (func) func
 # else
index 70114608fb15aae9905f5b5f1bcff578dce0d4cb..33bdb73660cd3437b16e155e62be2b5afc84b467 100644 (file)
 
 /* From glibc <features.h>.  */
 
+#if defined __clang__
+  /* clang really only groks GNU C 4.2, regardless of its value of __GNUC__.  */
+# undef __GNUC_PREREQ
+# define __GNUC_PREREQ(maj, min) ((maj) < 4 + ((min) <= 2))
+#endif
 #ifndef __GNUC_PREREQ
 # if defined __GNUC__ && defined __GNUC_MINOR__
 #  define __GNUC_PREREQ(maj, min) ((maj) < __GNUC__ + ((min) <= __GNUC_MINOR__))
index 08cae187efccb811063661de2335550ae2f96791..2462c29a3ea91589720e734daaddc2c4cbfdeecc 100644 (file)
@@ -942,9 +942,9 @@ _GL_CXXALIAS_SYS (fwrite, size_t,
    which sometimes causes an unwanted diagnostic for fwrite calls.
    This affects only function declaration attributes under certain
    versions of gcc and clang, and is not needed for C++.  */
-#  if (0 < __USE_FORTIFY_LEVEL                                          \
+#  if (0 < __USE_FORTIFY_LEVEL                                            \
        && __GLIBC__ == 2 && 4 <= __GLIBC_MINOR__ && __GLIBC_MINOR__ <= 15 \
-       && 3 < __GNUC__ + (4 <= __GNUC_MINOR__)                          \
+       && (3 < __GNUC__ + (4 <= __GNUC_MINOR__) || defined __clang__)     \
        && !defined __cplusplus)
 #   undef fwrite
 #   undef fwrite_unlocked
index e3b1fefe50126855482ed6f93d37d0f47c8988fb..73c439714aba4d35a704d9a18400cd610f71399f 100644 (file)
@@ -98,7 +98,7 @@ _GL_WARN_EXTERN_C __typeof__ (function) function \
   __attribute__ ((__diagnose_if__ (1, message, "warning")))
 #  define _GL_WARN_ON_USE_ATTRIBUTE(message) \
   __attribute__ ((__diagnose_if__ (1, message, "warning")))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# elif (__GNUC__ >= 3 || defined __clang__) && GNULIB_STRICT_CHECKING
 /* Verify the existence of the function.  */
 #  define _GL_WARN_ON_USE(function, message) \
 _GL_WARN_EXTERN_C __typeof__ (function) function
@@ -131,7 +131,7 @@ extern rettype_gcc function parameters_and_attributes \
 #   define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
 extern rettype_clang function parameters_and_attributes \
   __attribute__ ((__diagnose_if__ (1, msg, "warning")))
-#  elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+#  elif (__GNUC__ >= 3 || defined __clang__) && GNULIB_STRICT_CHECKING
 /* Verify the existence of the function.  */
 #   define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
 extern rettype_gcc function parameters_and_attributes