iceoryx_doc  1.0.1
attributes.hpp
1 // Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // SPDX-License-Identifier: Apache-2.0
16 #ifndef IOX_UTILS_CXX_ATTRIBUTES_HPP
17 #define IOX_UTILS_CXX_ATTRIBUTES_HPP
18 
19 namespace iox
20 {
21 namespace cxx
22 {
30 #define IOX_DISCARD_RESULT(expr) static_cast<void>(expr) // NOLINT
31 
35 // [[nodiscard]], [[gnu::warn_unused]] supported since gcc 4.8 (https://gcc.gnu.org/projects/cxx-status.html)
38 #if (defined(__GNUC__) && __GNUC__ >= 5) || (defined(__clang__) && __clang_major >= 4)
39 #define IOX_NO_DISCARD [[nodiscard, gnu::warn_unused]] // NOLINT
40 #else
41 // On WIN32 we are using C++17 which makes the keyword [[nodiscard]] available
42 #if defined(_WIN32)
43 #define IOX_NO_DISCARD [[nodiscard]] // NOLINT
44 // on an unknown platform we use for now nothing since we do not know what is supported there
45 #else
46 #define IOX_NO_DISCARD
47 #endif
48 #endif
49 
52 // [[fallthrough]] supported since gcc 7 (https://gcc.gnu.org/projects/cxx-status.html)
55 #if (defined(__GNUC__) && __GNUC__ >= 7) || (defined(__clang__) && __clang_major >= 4)
56 #define IOX_FALLTHROUGH [[fallthrough]] // NOLINT
57 #else
58 // On WIN32 we are using C++17 which makes the keyword [[fallthrough]] available
59 #if defined(_WIN32)
60 #define IOX_FALLTHROUGH [[fallthrough]] // NOLINT
61 // on an unknown platform we use for now nothing since we do not know what is supported there
62 #else
63 #define IOX_FALLTHROUGH
64 #endif
65 #endif
66 
71 #if defined(__GNUC__) || defined(__clang__)
72 #define IOX_MAYBE_UNUSED [[gnu::unused]] // NOLINT
73 #else
74 // On WIN32 we are using C++17 which makes the attribute [[maybe_unused]] available
75 #if defined(_WIN32)
76 #define IOX_MAYBE_UNUSED [[maybe_unused]] // NOLINT
77 // on an unknown platform we use for now nothing since we do not know what is supported there
78 #else
79 #define IOX_MAYBE_UNUSED
80 #endif
81 #endif
82 
83 
84 } // namespace cxx
85 } // namespace iox
86 
87 #endif
88 
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:28