[PATCH 1/2] Detect nonstring attribute via __has_attribute

Jussi Kivilinna <[email protected]> Thu, 23 Jul 2026 14:32:03 +0300
Newsgroups gmane.comp.encryption.gpg.libgcrypt.devel
Message-ID <[email protected]>
* src/gcrypt.h.in (_GCRY_GCC_ATTR_NONSTRING): Detect with
__has_attribute instead of GCC version check.
--

Clang reports __GNUC__ as 4, so _GCRY_GCC_VERSION >= 80000 check never
enabled nonstring attribute there, and clang 21 warns about unterminated
string initialization in byte arrays. Probe the attribute with
__has_attribute, which works on both GCC and clang regardless of
reported version.

Signed-off-by: Jussi Kivilinna <[email protected]>
---
 src/gcrypt.h.in | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/gcrypt.h.in b/src/gcrypt.h.in
index 8867b4e6..bb6f340d 100644
--- a/src/gcrypt.h.in
+++ b/src/gcrypt.h.in
@@ -98,8 +98,10 @@ extern "C" {
 #define _GCRY_GCC_ATTR_SENTINEL(a) __attribute__ ((sentinel(a)))
 #endif
 
-#if _GCRY_GCC_VERSION >= 80000
-#define _GCRY_GCC_ATTR_NONSTRING __attribute__((__nonstring__))
+#if defined __has_attribute
+#  if __has_attribute (__nonstring__)
+#    define _GCRY_GCC_ATTR_NONSTRING __attribute__((__nonstring__))
+#  endif
 #endif
 
 #endif /*__GNUC__*/
-- 
2.53.0