Mercurial > dwindows
comparison dw.h @ 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 | 48172881415c |
children | f98cecae5402 |
comparison
equal
deleted
inserted
replaced
2162:a3f105431028 | 2163:98db0e81a514 |
---|---|
13 #define DW_SUB_VERSION 0 | 13 #define DW_SUB_VERSION 0 |
14 | 14 |
15 #define DW_HOME_URL "http://dwindows.netlabs.org" | 15 #define DW_HOME_URL "http://dwindows.netlabs.org" |
16 | 16 |
17 /* Support for API deprecation in supported compilers */ | 17 /* Support for API deprecation in supported compilers */ |
18 #if defined(__has_feature) && !defined(__has_extension) | 18 #ifndef __has_attribute |
19 #define __has_extension __has_feature | 19 # define __has_attribute(x) 0 |
20 #endif | |
21 | |
22 #ifndef __has_extension | |
23 # define __has_extension __has_feature | |
24 #endif | |
25 | |
26 #ifndef __has_feature | |
27 # define __has_feature(x) 0 | |
28 #endif | |
29 | |
30 #ifndef __GNUC_PREREQ | |
31 # if defined(__GNUC__) && defined(__GNUC_MINOR__) | |
32 # define __GNUC_PREREQ(maj, min) ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) | |
33 # else | |
34 # define __GNUC_PREREQ(maj, min) 0 | |
35 # endif | |
20 #endif | 36 #endif |
21 | 37 |
22 /* Visual C */ | 38 /* Visual C */ |
23 #if defined(_MSC_VER) | 39 #if defined(_MSC_VER) |
24 # if _MSC_VER >= 1400 | 40 # if _MSC_VER >= 1400 |
25 # define DW_DEPRECATED(func, message) __declspec(deprecated(message)) func | 41 # define DW_DEPRECATED(func, message) __declspec(deprecated(message)) func |
26 # endif | 42 # endif |
27 /* Clang */ | 43 /* Clang or GCC */ |
28 #elif defined(__clang__) && defined(__has_extension) | 44 #elif __has_extension(attribute_deprecated_with_message) || __GNUC_PREREQ(4, 5) |
29 # if __has_extension(attribute_deprecated_with_message) | 45 # define DW_DEPRECATED(func, message) func __attribute__((deprecated (message))) |
30 # define DW_DEPRECATED(func, message) func __attribute__ ((deprecated (message))) | 46 #elif __has_extension(attribute_deprecated) || __GNUC_PREREQ(3, 2) |
31 # else | 47 # define DW_DEPRECATED(func, message) func __attribute__((deprecated)) |
32 # define DW_DEPRECATED(func, message) func __attribute__ ((deprecated)) | |
33 # endif | |
34 /* GCC */ | |
35 #elif defined(__GNUC__) | |
36 # if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 40500 | |
37 # define DW_DEPRECATED(func, message) func __attribute__ ((deprecated (message))) | |
38 # else | |
39 # define DW_DEPRECATED(func, message) func __attribute__ ((deprecated)) | |
40 # endif | |
41 #endif | 48 #endif |
42 | 49 |
43 /* Compiler without deprecation support */ | 50 /* Compiler without deprecation support */ |
44 #ifndef DW_DEPRECATED | 51 #ifndef DW_DEPRECATED |
45 #define DW_DEPRECATED(func, message) func | 52 #define DW_DEPRECATED(func, message) func |
46 #endif | 53 #endif |
47 | 54 |
48 /* Support for unused variables in supported compilers */ | 55 /* Support for unused variables in supported compilers */ |
49 #if defined(__GNUC__) || (defined(__clang__) && defined(__has_extension)) | 56 #if __has_attribute(unused) || __GNUC_PREREQ(3, 1) |
50 #define DW_UNUSED(x) x __attribute__((__unused__)) | 57 #define DW_UNUSED(x) x __attribute__((__unused__)) |
51 #else | 58 #else |
52 #define DW_UNUSED(x) x | 59 #define DW_UNUSED(x) x |
53 #endif | 60 #endif |
54 | 61 |