source: branches/profile/TEMPLATES/attributes.h

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