[PATCH v1 20/35] Assume #pragma GCC diagnostic is supported by the compiler

Alejandro Colomar alx@kernel.org
Sun Nov 9 21:53:37 GMT 2025


We already assume that GCC is at least GCC 5,
and we also assume that Clang is at least Clang 4.

Clang added support for this pragma in Clang 2.6:

llvm.git 504af1177d9c (2009-04-19; "implement "#pragma GCC diagnostic".")

	$ git describe --contains 504af1177d9c
	llvmorg-2.6.0~8194

Also, Clang added support for -Wcast-qual in Clang 3.6:

llvm.git d5178014938d (2014-11-21; "Implement -Wcast-qual, fixing #13772.")

	$ git describe --contains d5178014938d
	llvmorg-3.6.0-rc1~3098

Also, Clang added support for -Wvla in Clang 2.8:

llvm.git 4b636a70d93d (2010-05-23; "Put the VLA-is-an-extension warning into its own warning group (-Wvla) so that it can be selectively enabled/disabled.")

	$ git describe --contains 4b636a70d93d
	llvmorg-2.8.0-rc0~6649

Signed-off-by: Alejandro Colomar <alx@kernel.org>
---
 bits/stdlib-bsearch.h | 4 ----
 posix/regex.c         | 2 +-
 posix/regex.h         | 4 ----
 3 files changed, 1 insertion(+), 9 deletions(-)

diff --git a/bits/stdlib-bsearch.h b/bits/stdlib-bsearch.h
index 5ca67857e5..aa3ea53b21 100644
--- a/bits/stdlib-bsearch.h
+++ b/bits/stdlib-bsearch.h
@@ -29,14 +29,10 @@ bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size,
       __comparison = (*__compar) (__key, __p);
       if (__comparison == 0)
 	{
-#if __GNUC_PREREQ(4, 6)
 # pragma GCC diagnostic push
 # pragma GCC diagnostic ignored "-Wcast-qual"
-#endif
 	  return (void *) __p;
-#if __GNUC_PREREQ(4, 6)
 # pragma GCC diagnostic pop
-#endif
 	}
       if (__comparison > 0)
 	{
diff --git a/posix/regex.c b/posix/regex.c
index f5f6552670..9655785953 100644
--- a/posix/regex.c
+++ b/posix/regex.c
@@ -24,8 +24,8 @@
 
 # if __GNUC_PREREQ (4, 6)
 #  pragma GCC diagnostic ignored "-Wsuggest-attribute=pure"
-#  pragma GCC diagnostic ignored "-Wvla"
 # endif
+# pragma GCC diagnostic ignored "-Wvla"
 #endif
 
 /* Make sure no one compiles this code with a C++ compiler.  */
diff --git a/posix/regex.h b/posix/regex.h
index f33368562a..cd6596c0f7 100644
--- a/posix/regex.h
+++ b/posix/regex.h
@@ -531,10 +531,8 @@ typedef struct
 # endif
 #endif
 
-#if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
 # pragma GCC diagnostic push
 # pragma GCC diagnostic ignored "-Wvla"
-#endif
 
 #ifndef _Attr_access_
 # ifdef __attr_access
@@ -664,9 +662,7 @@ extern size_t regerror (int __errcode, const regex_t *__restrict __preg,
 
 extern void regfree (regex_t *__preg);
 
-#if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
 # pragma GCC diagnostic pop
-#endif
 
 #ifdef __cplusplus
 }
-- 
2.51.0



More information about the Libc-alpha mailing list