source: tags/ms_r17q2/TEMPLATES/attributes.h

Last change on this file was 15513, checked in by westram, 8 years ago
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 KB
Line 
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 NULL
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// ------------------------------------------------------------
67//  temporary disable
68
69// #undef __ATTR__DEPRECATED
70// #undef __ATTR__USERESULT
71// #undef __ATTR__SENTINEL
72
73// ------------------------------------------------------------
74// now define undefined attributes empty :
75
76#ifndef __ATTR__SENTINEL
77# define __ATTR__SENTINEL
78#endif
79#ifndef __ATTR__USERESULT
80# define __ATTR__USERESULT
81#endif
82#ifndef __ATTR__DEPRECATED
83# define __ATTR__DEPRECATED(reason)
84#endif
85#ifndef __ATTR__DONT_SANITIZE
86# define __ATTR__DONT_SANITIZE
87#endif
88
89// ------------------------------------------------------------
90// quickly disable attributes
91
92#if defined(WARN_TODO)
93#define __ATTR__USERESULT_TODO           __ATTR__USERESULT
94#define __ATTR__DEPRECATED_TODO(reason)  __ATTR__DEPRECATED(reason)
95#else
96#define __ATTR__USERESULT_TODO
97#define __ATTR__DEPRECATED_TODO(reason)
98#endif
99
100// no warning now, but it's planned to get deprecated
101// -> just works as annotation and placeholder for __ATTR__DEPRECATED or __ATTR__DEPRECATED_TODO
102#define __ATTR__DEPRECATED_LATER(reason)
103
104// ------------------------------------------------------------
105// casting result to void does not help when a function is
106// declared with __ATTR__USERESULT. Use
107
108#ifdef __cplusplus
109template <typename T> void IGNORE_RESULT(const T&) {}
110#endif
111
112#else
113#error attributes.h included twice
114#endif // ATTRIBUTES_H
115
Note: See TracBrowser for help on using the repository browser.