naev 0.12.5
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#if __has_attribute( warn_unused_result )
11#define USE_RESULT __attribute__( ( warn_unused_result ) )
12#else
13#define USE_RESULT
14#endif
15
16// Nullability
17#if __has_attribute( nonnull )
18#define NONNULL( ... ) __attribute__( ( nonnull( __VA_ARGS__ ) ) )
19#else
20#define NONNULL( ... )
21#endif
22
23#if __has_attribute( returns_nonnull )
24#define RETURNS_NONNULL __attribute__( ( returns_nonnull ) )
25#else
26#define RETURNS_NONNULL
27#endif
28
29// Function attributes
30#if __has_attribute( sentinel )
31#define SENTINEL( n ) __attribute__( ( sentinel( n ) ) )
32#else
33#define SENTINEL( n )
34#endif
35
36#if __has_attribute( noreturn )
37#define NORETURN __attribute__( ( noreturn ) )
38#else
39#define NORETURN
40#endif
41
42#if __has_attribute( format )
43#define FORMAT( ... ) __attribute__( ( format( __VA_ARGS__ ) ) )
44#else
45#define FORMAT( ... )
46#endif
47
48#if __has_attribute( format_arg )
49#define FORMAT_ARG( n ) __attribute__( ( format_arg( n ) ) )
50#else
51#define FORMAT_ARG( n )
52#endif
53
54#if __has_attribute( deprecated )
55#define DEPRECATED( msg ) __attribute__( ( deprecated( msg ) ) )
56#else
57#define DEPRECATED( msg )
58#endif
59
60#if __has_attribute( always_inline )
61#define ALWAYS_INLINE __attribute__( ( always_inline ) )
62#else
63#define ALWAYS_INLINE
64#endif
65
66// User defined diagnosis
67#if __has_attribute( diagnose_if )
68#define WARN_IF( c, m ) __attribute__( ( diagnose_if( c, m, "warning" ) ) )
69#define ERR_IF( c, m ) __attribute__( ( diagnose_if( c, m, "error" ) ) )
70#else
71#define WARN_IF( c, m )
72#define ERR_IF( c, m )
73#endif
74
75// Statement attributes
76#if __has_attribute( fallthrough )
77#define FALLTHROUGH __attribute__( ( fallthrough ) )
78#else
79#define FALLTHROUGH (void)0
80#endif