Skip to content

Commit

Permalink
Merge pull request #747 from ApexAI/iox-#743-add-attribute-docu-in-ut…
Browse files Browse the repository at this point in the history
…ils-overview

iox-#743 added attributes.hpp documentation in utils overview
  • Loading branch information
elfenpiff authored Apr 21, 2021
2 parents 4ce5310 + 09de1c3 commit 73a07a4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
3 changes: 2 additions & 1 deletion iceoryx_utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
33 changes: 18 additions & 15 deletions iceoryx_utils/include/iceoryx_utils/cxx/attributes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,50 +35,53 @@ 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.
/// @note
/// 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
Expand Down

0 comments on commit 73a07a4

Please sign in to comment.