changeset 2163:98db0e81a514

Rewrite the Compiler detection tests for deprecation and unused. Simplify and make more safe, clang or compilers supporting __has_extension() and __has_attribute() should work perfectly. There are now GCC version tests for all these features, however there seems to be some disagreement online about which GCC versions introduced these features, so I picked the versions that I felt had the highest consensus. Can revisit the specific versions if new information is available: unused attribute: GCC 3.1 (BSD seems to think 2.7) deprecated attribute: GCC 3.2 (Hedley seems to think 4.0) deprecated with message attribute: GCC 4.5
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 30 Sep 2020 19:34:17 +0000
parents a3f105431028
children 05dd5189099f
files dw.h
diffstat 1 files changed, 24 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/dw.h	Wed Sep 30 05:53:45 2020 +0000
+++ b/dw.h	Wed Sep 30 19:34:17 2020 +0000
@@ -15,8 +15,24 @@
 #define DW_HOME_URL "http://dwindows.netlabs.org"
 
 /* Support for API deprecation in supported compilers */
-#if defined(__has_feature) && !defined(__has_extension)
-#define __has_extension __has_feature
+#ifndef __has_attribute
+# define __has_attribute(x) 0
+#endif
+
+#ifndef __has_extension
+# define __has_extension __has_feature
+#endif
+    
+#ifndef __has_feature
+# define __has_feature(x) 0
+#endif
+    
+#ifndef __GNUC_PREREQ
+# if defined(__GNUC__) && defined(__GNUC_MINOR__)
+#  define __GNUC_PREREQ(maj, min) ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
+# else
+#  define __GNUC_PREREQ(maj, min) 0
+# endif
 #endif
 
 /* Visual C */
@@ -24,20 +40,11 @@
 #  if _MSC_VER >= 1400
 #  define DW_DEPRECATED(func, message) __declspec(deprecated(message)) func
 #  endif
-/* Clang */
-#elif defined(__clang__) && defined(__has_extension)
-#  if __has_extension(attribute_deprecated_with_message)
-#  define DW_DEPRECATED(func, message) func __attribute__ ((deprecated (message)))
-#  else
-#  define DW_DEPRECATED(func, message) func __attribute__ ((deprecated))
-#  endif
-/* GCC */
-#elif defined(__GNUC__)
-#  if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 40500
-#  define DW_DEPRECATED(func, message) func __attribute__ ((deprecated (message)))
-#  else
-#  define DW_DEPRECATED(func, message) func __attribute__ ((deprecated))
-#  endif
+/* Clang or GCC */
+#elif __has_extension(attribute_deprecated_with_message) || __GNUC_PREREQ(4, 5)
+#  define DW_DEPRECATED(func, message) func __attribute__((deprecated (message)))
+#elif __has_extension(attribute_deprecated) || __GNUC_PREREQ(3, 2)
+#  define DW_DEPRECATED(func, message) func __attribute__((deprecated))
 #endif
 
 /* Compiler without deprecation support */
@@ -46,7 +53,7 @@
 #endif
 
 /* Support for unused variables in supported compilers */
-#if defined(__GNUC__) || (defined(__clang__) && defined(__has_extension))
+#if __has_attribute(unused) || __GNUC_PREREQ(3, 1)
 #define DW_UNUSED(x) x __attribute__((__unused__))
 #else
 #define DW_UNUSED(x) x