]>
Commit | Line | Data |
---|---|---|
de1a880c DL |
1 | /* |
2 | * Copyright (c) 2015-2017 David Lamparter, for NetDEF, Inc. | |
3 | * | |
4 | * Permission to use, copy, modify, and distribute this software for any | |
5 | * purpose with or without fee is hereby granted, provided that the above | |
6 | * copyright notice and this permission notice appear in all copies. | |
7 | * | |
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
15 | */ | |
16 | ||
17 | #ifndef _FRR_COMPILER_H | |
18 | #define _FRR_COMPILER_H | |
19 | ||
5e244469 RW |
20 | #ifdef __cplusplus |
21 | extern "C" { | |
22 | #endif | |
23 | ||
de1a880c DL |
24 | /* function attributes, use like |
25 | * void prototype(void) __attribute__((_CONSTRUCTOR(100))); | |
26 | */ | |
27 | #if defined(__clang__) | |
996c9314 | 28 | #if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 5) |
de1a880c | 29 | # define _RET_NONNULL , returns_nonnull |
996c9314 | 30 | #endif |
bd27ea43 DL |
31 | #if __has_attribute(fallthrough) |
32 | # define _FALLTHROUGH __attribute__((fallthrough)); | |
33 | #endif | |
de1a880c DL |
34 | # define _CONSTRUCTOR(x) constructor(x) |
35 | #elif defined(__GNUC__) | |
996c9314 | 36 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9) |
de1a880c | 37 | # define _RET_NONNULL , returns_nonnull |
996c9314 LB |
38 | #endif |
39 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) | |
de1a880c DL |
40 | # define _CONSTRUCTOR(x) constructor(x) |
41 | # define _DESTRUCTOR(x) destructor(x) | |
42 | # define _ALLOC_SIZE(x) alloc_size(x) | |
996c9314 | 43 | #endif |
bd27ea43 DL |
44 | #if __GNUC__ >= 7 |
45 | # define _FALLTHROUGH __attribute__((fallthrough)); | |
46 | #endif | |
de1a880c DL |
47 | #endif |
48 | ||
49 | #ifdef __sun | |
50 | /* Solaris doesn't do constructor priorities due to linker restrictions */ | |
996c9314 LB |
51 | #undef _CONSTRUCTOR |
52 | #undef _DESTRUCTOR | |
de1a880c DL |
53 | #endif |
54 | ||
55 | /* fallback versions */ | |
56 | #ifndef _RET_NONNULL | |
57 | # define _RET_NONNULL | |
58 | #endif | |
59 | #ifndef _CONSTRUCTOR | |
60 | # define _CONSTRUCTOR(x) constructor | |
61 | #endif | |
62 | #ifndef _DESTRUCTOR | |
63 | # define _DESTRUCTOR(x) destructor | |
64 | #endif | |
65 | #ifndef _ALLOC_SIZE | |
66 | # define _ALLOC_SIZE(x) | |
67 | #endif | |
bd27ea43 DL |
68 | #ifndef _FALLTHROUGH |
69 | #define _FALLTHROUGH | |
70 | #endif | |
de1a880c DL |
71 | |
72 | /* | |
73 | * for warnings on macros, put in the macro content like this: | |
74 | * #define MACRO BLA CPP_WARN("MACRO has been deprecated") | |
75 | */ | |
76 | #define CPP_STR(X) #X | |
77 | ||
78 | #if defined(__ICC) | |
79 | #define CPP_NOTICE(text) _Pragma(CPP_STR(message __FILE__ ": " text)) | |
80 | #define CPP_WARN(text) CPP_NOTICE(text) | |
81 | ||
82 | #elif (defined(__GNUC__) \ | |
83 | && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))) \ | |
84 | || (defined(__clang__) \ | |
85 | && (__clang_major__ >= 4 \ | |
86 | || (__clang_major__ == 3 && __clang_minor__ >= 5))) | |
87 | #define CPP_WARN(text) _Pragma(CPP_STR(GCC warning text)) | |
88 | #define CPP_NOTICE(text) _Pragma(CPP_STR(message text)) | |
89 | ||
90 | #else | |
91 | #define CPP_WARN(text) | |
ec40eaf9 | 92 | #define CPP_NOTICE(text) |
de1a880c DL |
93 | #endif |
94 | ||
5e244469 RW |
95 | #ifdef __cplusplus |
96 | } | |
97 | #endif | |
98 | ||
de1a880c | 99 | #endif /* _FRR_COMPILER_H */ |