From: Bruno Haible Date: Tue, 27 Aug 2024 19:40:15 +0000 (+0200) Subject: Improve support for clang on Windows. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=9d6216a7e579e503f5cecafab7f7f78b2d3711ac;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index e84f67b639..1a77d4e518 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2024-08-27 Bruno Haible + + 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 Explicitly exclude clang when we test for a GCC version >= 4.3. diff --git a/lib/c++defs.h b/lib/c++defs.h index eb66967b09..5d15e70d6f 100644 --- a/lib/c++defs.h +++ b/lib/c++defs.h @@ -297,7 +297,7 @@ _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 diff --git a/lib/libc-config.h b/lib/libc-config.h index 70114608fb..33bdb73660 100644 --- a/lib/libc-config.h +++ b/lib/libc-config.h @@ -48,6 +48,11 @@ /* From glibc . */ +#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__)) diff --git a/lib/stdio.in.h b/lib/stdio.in.h index 08cae187ef..2462c29a3e 100644 --- a/lib/stdio.in.h +++ b/lib/stdio.in.h @@ -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 diff --git a/lib/warn-on-use.h b/lib/warn-on-use.h index e3b1fefe50..73c439714a 100644 --- a/lib/warn-on-use.h +++ b/lib/warn-on-use.h @@ -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