This fixes -Wunused-but-set-variable warnings on clang msvc targets. Commit
a166d5450e3f47587b98f6005f9f5627dbe21a5b fixed those warnings in most cases,
but currently YY_ATTRIBUTE_UNUSED is defined only when __GNUC__ is defined.
When using clang in msvc mode, it's not defined, but __unused__ attribute
is still available.


In my use case, it fixes warnings when building the Wine project with clang as

a cross compiler.
From 3846adf174558ff21c784d932f531b00c3cf85e3 Mon Sep 17 00:00:00 2001
From: Jacek Caban <[email protected]>
Date: Fri, 24 Nov 2023 15:06:32 +0100
Subject: [PATCH] c.m4: Use __has_attribute to check for attribute
 availability.

This fixes -Wunused-but-set-variable warnings on clang msvc targets. Commit
a166d5450e3f47587b98f6005f9f5627dbe21a5b fixed those warnings in most cases,
but currently YY_ATTRIBUTE_UNUSED is defined only when __GNUC__ is defined.
When using clang in msvc mode, it's not defined, but __unused__ attribute
is still available.
---
 data/skeletons/c.m4 | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/data/skeletons/c.m4 b/data/skeletons/c.m4
index 6f90ebe8..ad41640c 100644
--- a/data/skeletons/c.m4
+++ b/data/skeletons/c.m4
@@ -363,7 +363,8 @@ m4_define([b4_table_value_equals],
 # _Noreturn.
 m4_define([b4_attribute_define],
 [[#ifndef YY_ATTRIBUTE_PURE
-# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
+# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) \
+      || (defined __has_attribute && __has_attribute(__pure__))
 #  define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
 # else
 #  define YY_ATTRIBUTE_PURE
@@ -371,7 +372,8 @@ m4_define([b4_attribute_define],
 #endif
 
 #ifndef YY_ATTRIBUTE_UNUSED
-# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
+# if (defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)) \
+      || (defined __has_attribute && __has_attribute(__unused__))
 #  define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
 # else
 #  define YY_ATTRIBUTE_UNUSED
-- 
2.41.0

Reply via email to