XRTraits C++ OpenXR Utilities
Attributes.h
Go to the documentation of this file.
1 // Copyright 2018-2019, Collabora, Ltd.
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4  * @file
5  * @brief Header defining macros corresponding to various C++ attributes
6  * @author Ryan Pavlik <ryan.pavlik@collabora.com>
7  */
8 
9 #pragma once
10 
11 // Internal Includes
12 // - none
13 
14 // Library Includes
15 // - none
16 
17 // Standard Includes
18 // - none
19 
20 #ifdef XRTRAITS_DOXYGEN
21 //! Compatibility wrapper for `[[fallthrough]]`
22 #define XRTRAITS_FALLTHROUGH [[fallthrough]]
23 //! Compatibility wrapper for `[[nodiscard]]`
24 #define XRTRAITS_NODISCARD [[nodiscard]]
25 //! Compatibility wrapper for `[[maybe_unused]]`
26 #define XRTRAITS_MAYBE_UNUSED [[maybe_unused]]
27 //! Portability wrapper for indicating that a type may alias other types.
28 #define XRTRAITS_MAY_ALIAS __attribute__((__may_alias__))
29 #else // XRTRAITS_DOXYGEN
30 
31 #ifndef __has_cpp_attribute
32 #define __has_cpp_attribute(X) 0
33 #endif // !__has_cpp_attribute
34 
35 #if __has_cpp_attribute(fallthrough)
36 #define XRTRAITS_FALLTHROUGH [[fallthrough]]
37 #elif __has_cpp_attribute(clang::fallthrough)
38 #define XRTRAITS_FALLTHROUGH [[clang::fallthrough]]
39 #else
40 #define XRTRAITS_FALLTHROUGH
41 #endif
42 
43 #if __has_cpp_attribute(nodiscard)
44 #define XRTRAITS_NODISCARD [[nodiscard]]
45 #elif __has_cpp_attribute(gnu::warn_unused_result)
46 #define XRTRAITS_NODISCARD [[gnu::warn_unused_result]]
47 #else
48 #define XRTRAITS_NODISCARD
49 #endif
50 
51 #if __has_cpp_attribute(maybe_unused)
52 #define XRTRAITS_MAYBE_UNUSED [[maybe_unused]]
53 #elif __has_cpp_attribute(gnu::unused)
54 #define XRTRAITS_MAYBE_UNUSED [[gnu::unused]]
55 #else
56 #define XRTRAITS_MAYBE_UNUSED
57 #endif
58 
59 #if defined(__clang__) || defined(__GNUC__)
60 #define XRTRAITS_MAY_ALIAS __attribute__((__may_alias__))
61 #else
62 #define XRTRAITS_MAY_ALIAS
63 #endif
64 
65 #endif // XRTRAITS_DOXYGEN