Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1726 Address review findings by simplifying ifdef…
Browse files Browse the repository at this point in the history
… thicket

Signed-off-by: Simon Hoinkis <[email protected]>
  • Loading branch information
mossmaurice committed Jan 10, 2023
1 parent 86e5520 commit e2bc578
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 62 deletions.
12 changes: 7 additions & 5 deletions iceoryx_platform/linux/include/iceoryx_platform/attributes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
#ifndef IOX_HOOFS_LINUX_PLATFORM_ATTRIBUTES_HPP
#define IOX_HOOFS_LINUX_PLATFORM_ATTRIBUTES_HPP

#define IOX_NO_DISCARD
/// @brief IOX_NO_DISCARD adds the [[nodiscard]] keyword
/// @note
// [[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)

#define IOX_NO_DISCARD [[nodiscard, gnu::warn_unused]]

/// @brief IOX_FALLTHROUGH adds the [[fallthrough]] keyword when it is available for the current compiler.
/// @note
Expand All @@ -34,12 +39,9 @@
#define IOX_FALLTHROUGH
#endif

/// @brief IOX_MAYBE_UNUSED adds the [[gnu::unused]] or [[maybe_unused]] attribute when it is available for the current
/// @brief IOX_MAYBE_UNUSED adds the [[gnu::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]]
#endif

#endif // IOX_HOOFS_LINUX_PLATFORM_ATTRIBUTES_HPP
30 changes: 1 addition & 29 deletions iceoryx_platform/mac/include/iceoryx_platform/attributes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,10 @@
#ifndef IOX_HOOFS_MAC_PLATFORM_ATTRIBUTES_HPP
#define IOX_HOOFS_MAC_PLATFORM_ATTRIBUTES_HPP

/// @brief IOX_NO_DISCARD adds the [[nodiscard]] keyword if it is available for the current compiler.
/// If additionally the keyword [[gnu::warn_unused]] is present it will be added as well.
/// @note
// [[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(__clang__)
#define IOX_NO_DISCARD [[nodiscard, gnu::warn_unused]]
#elif (defined(__clang__) && (__clang_major__ >= 4))
#define IOX_NO_DISCARD [[gnu::warn_unused]]
#elif (defined(__GNUC__) && (__GNUC__ >= 5))
#define IOX_NO_DISCARD [[nodiscard, gnu::warn_unused]]
#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(__clang__)
#define IOX_FALLTHROUGH [[fallthrough]]
#else
#define IOX_FALLTHROUGH
#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]]
#endif
#define IOX_MAYBE_UNUSED [[maybe_unused]]

#endif // IOX_HOOFS_MAC_PLATFORM_ATTRIBUTES_HPP
7 changes: 0 additions & 7 deletions iceoryx_platform/qnx/include/iceoryx_platform/attributes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,13 @@
/// @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 __cplusplus >= 201703L
#define IOX_FALLTHROUGH [[fallthrough]]
#else
#define IOX_FALLTHROUGH
#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]]
#endif

#endif // IOX_HOOFS_QNX_PLATFORM_ATTRIBUTES_HPP
21 changes: 1 addition & 20 deletions iceoryx_platform/unix/include/iceoryx_platform/attributes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,10 @@
#ifndef IOX_HOOFS_UNIX_PLATFORM_ATTRIBUTES_HPP
#define IOX_HOOFS_UNIX_PLATFORM_ATTRIBUTES_HPP

#define IOX_NO_DISCARD
#define IOX_NO_DISCARD [[nodiscard, gnu::warn_unused]]

/// @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 __cplusplus >= 201703L
// clang prints a warning therefore we exclude it here
#define IOX_FALLTHROUGH [[fallthrough]]
#elif (defined(__GNUC__) && (__GNUC__ >= 7)) && !defined(__clang__)
#define IOX_FALLTHROUGH [[gnu::fallthrough]]
#else
#define IOX_FALLTHROUGH
#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]]
#endif

#endif // IOX_HOOFS_UNIX_PLATFORM_ATTRIBUTES_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#ifndef IOX_HOOFS_WIN_PLATFORM_ATTRIBUTES_HPP
#define IOX_HOOFS_WIN_PLATFORM_ATTRIBUTES_HPP


#define IOX_NO_DISCARD [[nodiscard]]

#define IOX_FALLTHROUGH [[fallthrough]]
Expand Down

0 comments on commit e2bc578

Please sign in to comment.