naev 0.10.4
attributes.h
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
4#pragma once
5
6#ifndef __has_attribute
7 #define __has_attribute( x ) 0
8#endif
9
10// Nullability
11#if __has_attribute( nonnull )
12 #define NONNULL( ... ) __attribute__( ( nonnull( __VA_ARGS__ ) ) )
13#else
14 #define NONNULL( ... )
15#endif
16
17#if __has_attribute( returns_nonnull )
18 #define RETURNS_NONNULL __attribute__( ( returns_nonnull ) )
19#else
20 #define RETURNS_NONNULL
21#endif
22
23// Function attributes
24#if __has_attribute( sentinel )
25 #define SENTINEL( n ) __attribute__( ( sentinel( n ) ) )
26#else
27 #define SENTINEL( n )
28#endif
29
30#if __has_attribute( noreturn )
31 #define NORETURN __attribute__( ( noreturn ) )
32#else
33 #define NORETURN
34#endif
35
36#if __has_attribute( format )
37 #define FORMAT( ... ) __attribute__( ( format ( __VA_ARGS__ ) ) )
38#else
39 #define FORMAT( ... )
40#endif
41
42#if __has_attribute( format_arg )
43 #define FORMAT_ARG( n ) __attribute__( ( format_arg ( n ) ) )
44#else
45 #define FORMAT_ARG( n )
46#endif
47
48#if __has_attribute( deprecated )
49 #define DEPRECATED( msg ) __attribute__( ( deprecated( msg ) ) )
50#else
51 #define DEPRECATED( msg )
52#endif
53
54#if __has_attribute( always_inline )
55 #define ALWAYS_INLINE __attribute__( ( always_inline ) )
56#else
57 #define ALWAYS_INLINE
58#endif
59
60// User defined diagnosis
61#if __has_attribute( diagnose_if )
62 #define WARN_IF( c, m ) __attribute__( ( diagnose_if( c, m, "warning" ) ) )
63 #define ERR_IF( c, m ) __attribute__( ( diagnose_if( c, m, "error" ) ) )
64#else
65 #define WARN_IF( c, m )
66 #define ERR_IF( c, m )
67#endif
68
69// Statement attributes
70#if __has_attribute( fallthrough )
71 #define FALLTHROUGH __attribute__( ( fallthrough ) )
72#else
73 #define FALLTHROUGH (void)0
74#endif