diff --git a/iceoryx_utils/README.md b/iceoryx_utils/README.md index ef3d265b99..be209e15a2 100644 --- a/iceoryx_utils/README.md +++ b/iceoryx_utils/README.md @@ -40,9 +40,10 @@ dynamic memory. In these cases we adjusted the API to our use case. Most of the headers are providing some example code on how the class should be used. -| class | internal | maybe obsolete | description | +| class/file | internal | maybe obsolete | description | |:-----------------------:|:--------:|:--------------:|:------------| |`algorithm` | | | Implements `min` and `max` for an arbitrary number of values of the same type. For instance `min(1,2,3,4,5);` | +|`attributes` | | | C++17 and C++20 attributes are sometimes available through compiler extensions. The attribute macros defined in here (like `IOX_FALLTHROUGH`, `IOX_MAYBE_UNUSED` ... ) make sure that we are able to use them if the compiler supports it. | |`convert` | | | Converting a number into a string is easy, converting it back can be hard. You can use functions like `strtoll` but you still have to handle errors like under- and overflow, or converting invalid strings into number. Here we abstract all the error handling so that you can convert strings into numbers safely. | |`expected` | | | Our base class used in error handling. Every function which can fail should return an expected. With this the user knows that this function can fail and that they have to do some kind of error handling. We got inspired by the [C++ expected proposal]( http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0323r7.html) and by the [rust error handling concept](https://doc.rust-lang.org/std/result/enum.Result.html). | |`forward_list` | | | Heap and exception free, relocatable implementation of `std::forward_list` | diff --git a/iceoryx_utils/include/iceoryx_utils/cxx/attributes.hpp b/iceoryx_utils/include/iceoryx_utils/cxx/attributes.hpp index 41eaffb384..4755ac15b1 100644 --- a/iceoryx_utils/include/iceoryx_utils/cxx/attributes.hpp +++ b/iceoryx_utils/include/iceoryx_utils/cxx/attributes.hpp @@ -35,34 +35,39 @@ namespace cxx // [[nodiscard]], [[gnu::warn_unused]] supported since gcc 4.8 (https://gcc.gnu.org/projects/cxx-status.html) /// [[nodiscard]], [[gnu::warn_unused]] supported since clang 3.9 (https://clang.llvm.org/cxx_status.html) /// activate keywords for gcc>=5 or clang>=4 -#if (defined(__GNUC__) && __GNUC__ >= 5) || (defined(__clang__) && __clang_major >= 4) -#define IOX_NO_DISCARD [[nodiscard, gnu::warn_unused]] // NOLINT -#else -// On WIN32 we are using C++17 which makes the keyword [[nodiscard]] available #if defined(_WIN32) +// On WIN32 we are using C++17 which makes the keyword [[nodiscard]] available #define IOX_NO_DISCARD [[nodiscard]] // NOLINT -// on an unknown platform we use for now nothing since we do not know what is supported there +#elif defined(__APPLE__) && defined(__clang__) +// On APPLE we are using C++17 which makes the keyword [[nodiscard]] available +#define IOX_NO_DISCARD [[nodiscard, gnu::warn_unused]] // NOLINT +#elif (defined(__clang__) && __clang_major__ >= 4) +#define IOX_NO_DISCARD [[gnu::warn_unused]] // NOLINT +#elif (defined(__GNUC__) && __GNUC__ >= 5) +#define IOX_NO_DISCARD [[nodiscard, gnu::warn_unused]] // NOLINT #else +// on an unknown platform we use for now nothing since we do not know what is supported there #define IOX_NO_DISCARD #endif -#endif /// @brief IOX_FALLTHROUGH adds the [[fallthrough]] keyword when it is available for the current compiler. /// @note // [[fallthrough]] supported since gcc 7 (https://gcc.gnu.org/projects/cxx-status.html) /// [[fallthrough]] supported since clang 3.9 (https://clang.llvm.org/cxx_status.html) /// activate keywords for gcc>=7 or clang>=4 -#if (defined(__GNUC__) && __GNUC__ >= 7) || (defined(__clang__) && __clang_major >= 4) -#define IOX_FALLTHROUGH [[fallthrough]] // NOLINT -#else -// On WIN32 we are using C++17 which makes the keyword [[fallthrough]] available #if defined(_WIN32) +// On WIN32 we are using C++17 which makes the keyword [[fallthrough]] available +#define IOX_FALLTHROUGH [[fallthrough]] // NOLINT +#elif defined(__APPLE__) && defined(__clang__) +// On APPLE we are using C++17 which makes the keyword [[fallthrough]] available +#define IOX_FALLTHROUGH [[fallthrough]] // NOLINT +#elif (defined(__GNUC__) && __GNUC__ >= 7) && !defined(__clang__) +// clang prints a warning therefore we exclude it here #define IOX_FALLTHROUGH [[fallthrough]] // NOLINT -// on an unknown platform we use for now nothing since we do not know what is supported there #else +// on an unknown platform we use for now nothing since we do not know what is supported there #define IOX_FALLTHROUGH #endif -#endif /// @brief IOX_MAYBE_UNUSED adds the [[gnu::unused]] or [[maybe_unused]] attribute when it is available for the current /// compiler. @@ -70,15 +75,13 @@ namespace cxx /// activate attribute for gcc or clang #if defined(__GNUC__) || defined(__clang__) #define IOX_MAYBE_UNUSED [[gnu::unused]] // NOLINT -#else +#elif defined(_WIN32) // On WIN32 we are using C++17 which makes the attribute [[maybe_unused]] available -#if defined(_WIN32) #define IOX_MAYBE_UNUSED [[maybe_unused]] // NOLINT // on an unknown platform we use for now nothing since we do not know what is supported there #else #define IOX_MAYBE_UNUSED #endif -#endif } // namespace cxx