ARB
attributes.h
Go to the documentation of this file.
1 // ==================================================================== //
2 // //
3 // File : attributes.h //
4 // Purpose : declare attribute macros //
5 // //
6 // Coded by Ralf Westram (coder@reallysoft.de) in June 2005 //
7 // Copyright Department of Microbiology (Technical University Munich) //
8 // //
9 // Visit our web site at: http://www.arb-home.de/ //
10 // //
11 // ==================================================================== //
12 #ifndef ATTRIBUTES_H
13 #define ATTRIBUTES_H
14 
15 #ifndef GCCVER_H
16 #include "gccver.h"
17 #endif
18 
19 // ------------------------------------------------------------
20 // short description of attributes defined:
21 //
22 // __ATTR__FORMAT(p) used for printf-like functions. 'p' is the position of the format string, args follow directly
23 // __ATTR__VFORMAT(p) used for vprintf-like functions. 'p' is the position of the format string, args are NOT checked
24 // __ATTR__SENTINEL used for function that expect a parameter list terminated by NULp
25 // __ATTR__NORETURN used for functions which do NEVER return
26 // __ATTR__DEPRECATED used for deprecated functions (useful for redesign)
27 // __ATTR__USERESULT warn if result of function is unused
28 //
29 // __ATTR__FORMAT_MEMBER(p) same as __ATTR__FORMAT for member functions
30 // __ATTR__VFORMAT_MEMBER(p) same as __ATTR__VFORMAT for member functions
31 //
32 // ------------------------------------------------------------
33 // Note: consider defining new attributes in ../SOURCE_TOOLS/etags_ignore.lst@__ATTR
34 // ------------------------------------------------------------
35 
36 #if (GCC_PATCHLEVEL_CODE >= 40502) // gcc 4.5.2 and higher
37 # define __ATTR__DEPRECATED(reason) __attribute__((deprecated(reason)))
38 #endif
39 
40 #if (GCC_VERSION_CODE >= 409) // gcc 4.9.x or higher
41 # define __ATTR__DONT_SANITIZE __attribute__((no_sanitize_address))
42 #endif
43 
44 // ------------------------------------------------------------
45 // helper macro to declare attributes for function-pointers
46 
47 #define FUNCTION_TYPE_ATTR(x) x
48 
49 // ------------------------------------------------------------
50 // valid for any gcc above 4.3
51 
52 #ifndef __ATTR__DEPRECATED
53 # define __ATTR__DEPRECATED(reason) __attribute__((deprecated))
54 #endif
55 
56 #define __ATTR__NORETURN __attribute__((noreturn))
57 #define __ATTR__SENTINEL __attribute__((sentinel))
58 #define __ATTR__USERESULT __attribute__((warn_unused_result))
59 
60 #define __ATTR__FORMAT(pos) __attribute__((format(__printf__, pos, (pos)+1)))
61 #define __ATTR__VFORMAT(pos) __attribute__((format(__printf__, pos, 0)))
62 #define __ATTR__FORMAT_MEMBER(pos) __attribute__((format(__printf__, (pos)+1, (pos)+2)))
63 #define __ATTR__VFORMAT_MEMBER(pos) __attribute__((format(__printf__, (pos)+1, 0)))
64 // when used for member functions, start with pos+1 (pos = 1 seems to be the this-pointer!?)
65 
66 #define __ATTR__OPTIMIZE(optiflag) __attribute__((optimize(optiflag)))
67 #define __ATTR__DONT_VECTORIZE __ATTR__OPTIMIZE("no-tree-vectorize")
68 // see also ../UNIT_TESTER/test_unit.h@__ATTR__REDUCED_OPTIMIZE
69 
70 // ------------------------------------------------------------
71 // temporary disable
72 
73 // #undef __ATTR__DEPRECATED
74 // #undef __ATTR__USERESULT
75 // #undef __ATTR__SENTINEL
76 
77 // ------------------------------------------------------------
78 // now define undefined attributes empty :
79 
80 #ifndef __ATTR__SENTINEL
81 # define __ATTR__SENTINEL
82 #endif
83 #ifndef __ATTR__USERESULT
84 # define __ATTR__USERESULT
85 #endif
86 #ifndef __ATTR__DEPRECATED
87 # define __ATTR__DEPRECATED(reason)
88 #endif
89 #ifndef __ATTR__DONT_SANITIZE
90 # define __ATTR__DONT_SANITIZE
91 #endif
92 #ifndef __ATTR__DONT_VECTORIZE
93 # define __ATTR__DONT_VECTORIZE
94 #endif
95 
96 // ------------------------------------------------------------
97 // quickly disable attributes
98 
99 #if defined(WARN_TODO)
100 #define __ATTR__USERESULT_TODO __ATTR__USERESULT
101 #define __ATTR__DEPRECATED_TODO(reason) __ATTR__DEPRECATED(reason)
102 #else
103 #define __ATTR__USERESULT_TODO
104 #define __ATTR__DEPRECATED_TODO(reason)
105 #endif
106 
107 // no warning now, but it's planned to get deprecated
108 // -> just works as annotation and placeholder for __ATTR__DEPRECATED or __ATTR__DEPRECATED_TODO
109 #define __ATTR__DEPRECATED_LATER(reason)
110 
111 // ------------------------------------------------------------
112 // casting result to void does not help when a function is
113 // declared with __ATTR__USERESULT. Use
114 
115 #ifdef __cplusplus
116 template <typename T> void IGNORE_RESULT(const T&) {}
117 #endif
118 
119 #else
120 #error attributes.h included twice
121 #endif // ATTRIBUTES_H
122 
Definition: trnsprob.h:20