source: tags/ms_r16q2/TEMPLATES/attributes.h

Last change on this file was 13019, checked in by westram, 10 years ago
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 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
34#if (GCC_PATCHLEVEL_CODE >= 40502) // gcc 4.5.2 and higher
35# define __ATTR__DEPRECATED(reason) __attribute__((deprecated(reason)))
36#endif
37
38#if (GCC_VERSION_CODE >= 409) // gcc 4.9.x or higher
39# define __ATTR__DONT_SANITIZE __attribute__((no_sanitize_address))
40#endif
41
42// ------------------------------------------------------------
43// helper macro to declare attributes for function-pointers
44
45#define FUNCTION_TYPE_ATTR(x) x
46
47// ------------------------------------------------------------
48// valid for any gcc above 4.3
49
50#ifndef __ATTR__DEPRECATED
51# define __ATTR__DEPRECATED(reason) __attribute__((deprecated))
52#endif
53
54#define __ATTR__NORETURN  __attribute__((noreturn))
55#define __ATTR__SENTINEL  __attribute__((sentinel))
56#define __ATTR__USERESULT __attribute__((warn_unused_result))
57
58#define __ATTR__FORMAT(pos)         __attribute__((format(__printf__, pos, (pos)+1)))
59#define __ATTR__VFORMAT(pos)        __attribute__((format(__printf__, pos, 0)))
60#define __ATTR__FORMAT_MEMBER(pos)  __attribute__((format(__printf__, (pos)+1, (pos)+2)))
61#define __ATTR__VFORMAT_MEMBER(pos) __attribute__((format(__printf__, (pos)+1, 0)))
62// when used for member functions, start with pos+1 (pos = 1 seems to be the this-pointer!?)
63
64// ------------------------------------------------------------
65//  temporary disable
66
67// #undef __ATTR__DEPRECATED
68// #undef __ATTR__USERESULT
69// #undef __ATTR__SENTINEL
70
71// ------------------------------------------------------------
72// now define undefined attributes empty :
73
74#ifndef __ATTR__SENTINEL
75# define __ATTR__SENTINEL
76#endif
77#ifndef __ATTR__USERESULT
78# define __ATTR__USERESULT
79#endif
80#ifndef __ATTR__DEPRECATED
81# define __ATTR__DEPRECATED(reason)
82#endif
83#ifndef __ATTR__DONT_SANITIZE
84# define __ATTR__DONT_SANITIZE
85#endif
86
87// ------------------------------------------------------------
88// quickly disable attributes
89
90#if defined(WARN_TODO)
91#define __ATTR__USERESULT_TODO           __ATTR__USERESULT
92#define __ATTR__DEPRECATED_TODO(reason)  __ATTR__DEPRECATED(reason)
93#else
94#define __ATTR__USERESULT_TODO
95#define __ATTR__DEPRECATED_TODO(reason)
96#endif
97
98// no warning now, but it's planned to get deprecated
99// -> just works as annotation and placeholder for __ATTR__DEPRECATED or __ATTR__DEPRECATED_TODO
100#define __ATTR__DEPRECATED_LATER(reason)
101
102// ------------------------------------------------------------
103// casting result to void does not help when a function is
104// declared with __ATTR__USERESULT. Use
105
106#ifdef __cplusplus
107template <typename T> void IGNORE_RESULT(const T&) {}
108#endif
109
110#else
111#error attributes.h included twice
112#endif // ATTRIBUTES_H
113
Note: See TracBrowser for help on using the repository browser.