clang defines __OPTIMIZE__ to 1 when optimizing, like GCC. Also, it's unlikely that when clang implements __attribute__((__warning__...)), it will exhibit the same bug as GCC <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>.
2020-08-06 Bruno Haible <br...@clisp.org> Consider that clang defines __OPTIMIZE__ like GCC does. * lib/streq.h: Define the inline functions also on clang. * lib/c-strcaseeq.h: Likewise. * lib/c++defs.h (_GL_CXXALIASWARN_2, _GL_CXXALIASWARN1_2): Don't enable the GCC workaround to clang. diff --git a/lib/c++defs.h b/lib/c++defs.h index 402cae4..75d6250 100644 --- a/lib/c++defs.h +++ b/lib/c++defs.h @@ -268,7 +268,7 @@ _GL_CXXALIASWARN_2 (func, namespace) /* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>, we enable the warning only when not optimizing. */ -# if !__OPTIMIZE__ +# if !(defined __GNUC__ && !defined __clang__ && __OPTIMIZE__) # define _GL_CXXALIASWARN_2(func,namespace) \ _GL_WARN_ON_USE (func, \ "The symbol ::" #func " refers to the system function. " \ @@ -296,7 +296,7 @@ _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace) /* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>, we enable the warning only when not optimizing. */ -# if !__OPTIMIZE__ +# if !(defined __GNUC__ && !defined __clang__ && __OPTIMIZE__) # define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \ _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \ "The symbol ::" #func " refers to the system function. " \ diff --git a/lib/c-strcaseeq.h b/lib/c-strcaseeq.h index 3c33b6e..897dc99 100644 --- a/lib/c-strcaseeq.h +++ b/lib/c-strcaseeq.h @@ -27,7 +27,7 @@ /* Help GCC to generate good code for string comparisons with immediate strings. */ -#if defined (__GNUC__) && defined (__OPTIMIZE__) +#if (defined __GNUC__ || defined __clang__) && defined __OPTIMIZE__ /* Case insensitive comparison of ASCII characters. */ # if C_CTYPE_ASCII diff --git a/lib/streq.h b/lib/streq.h index cf15c0d..978267b 100644 --- a/lib/streq.h +++ b/lib/streq.h @@ -29,7 +29,7 @@ /* Help GCC to generate good code for string comparisons with immediate strings. */ -#if defined (__GNUC__) && defined (__OPTIMIZE__) +#if (defined __GNUC__ || defined __clang__) && defined __OPTIMIZE__ static inline int streq9 (const char *s1, const char *s2)