From 85cf7ac82d40a88e1251cfe6d9d910f634461796 Mon Sep 17 00:00:00 2001 From: Brett Dutro Date: Mon, 5 Feb 2024 14:53:07 -0800 Subject: [PATCH 1/4] Only use -Wno-gnu-zero-variadic-macro-arguments if we're compiling with Clang - Otherwise GCC complains with a warning message --- cmake/stf-config.cmake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmake/stf-config.cmake b/cmake/stf-config.cmake index 6648e8b..4b8502b 100644 --- a/cmake/stf-config.cmake +++ b/cmake/stf-config.cmake @@ -25,7 +25,11 @@ include(stf_linker_setup) setup_stf_linker(true) -add_compile_options(-Werror -std=c++17 -fPIC -Wall -Wextra -pedantic -Wconversion -Wno-unused-parameter -Wno-unused-function -Wno-gnu-zero-variadic-macro-arguments -pipe) +add_compile_options(-Werror -std=c++17 -fPIC -Wall -Wextra -pedantic -Wconversion -Wno-unused-parameter -Wno-unused-function -pipe) + +if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wno-gnu-zero-variadic-macro-arguments) +endif() if (CMAKE_BUILD_TYPE MATCHES "^[Rr]elease") if(NOT DISABLE_STF_DOXYGEN) From 3f18b0e574caa253db7a4d553a8eb119716fb0c2 Mon Sep 17 00:00:00 2001 From: Brett Dutro Date: Mon, 5 Feb 2024 14:54:56 -0800 Subject: [PATCH 2/4] Add type_utils::are_pod to determine if all types in a variadic template pack are POD --- stf-inc/type_utils.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/stf-inc/type_utils.hpp b/stf-inc/type_utils.hpp index 834a8c2..9d1a5cf 100644 --- a/stf-inc/type_utils.hpp +++ b/stf-inc/type_utils.hpp @@ -22,6 +22,12 @@ namespace stf { template inline constexpr bool are_trivially_copyable_v = are_trivially_copyable::value; + template + struct are_pod : std::conjunction>...> {}; + + template + inline constexpr bool are_pod_v = are_pod::value; + template struct is_iterable : std::false_type {}; From 6aeca28e329c0e31c885fb7df6328a4c83fc93ae Mon Sep 17 00:00:00 2001 From: Brett Dutro Date: Mon, 5 Feb 2024 14:55:42 -0800 Subject: [PATCH 3/4] Use type_utils::are_pod instead of type_utils::are_trivially_copyable to determine if types are eligible for use with PackedContainer --- stf-inc/stf_object.hpp | 8 ++++---- stf-inc/stf_packed_container.hpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/stf-inc/stf_object.hpp b/stf-inc/stf_object.hpp index 60287d0..637ecf7 100644 --- a/stf-inc/stf_object.hpp +++ b/stf-inc/stf_object.hpp @@ -46,7 +46,7 @@ namespace stf { * \param data Data to write */ template - static inline std::enable_if_t> + static inline std::enable_if_t> write_(STFOFstream& writer, Ts&&... data) { writer << PackedContainer>...>(std::forward(data)...); } @@ -57,7 +57,7 @@ namespace stf { * \param data Data to write */ template - static inline std::enable_if_t>> + static inline std::enable_if_t>> write_(STFOFstream& writer, Ts&&... data) { (writer << ... << data); } @@ -132,7 +132,7 @@ namespace stf { */ template __attribute__((always_inline)) - static inline std::enable_if_t, size_t> + static inline std::enable_if_t, size_t> read_(STFIFstream& reader, Ts&&... data) { PackedContainerView...> temp; reader >> temp; @@ -148,7 +148,7 @@ namespace stf { */ template __attribute__((always_inline)) - static inline std::enable_if_t>, size_t> + static inline std::enable_if_t>, size_t> read_(STFIFstream& reader, Ts&&... data) { (reader >> ... >> data); diff --git a/stf-inc/stf_packed_container.hpp b/stf-inc/stf_packed_container.hpp index 432dc3f..ea967e9 100644 --- a/stf-inc/stf_packed_container.hpp +++ b/stf-inc/stf_packed_container.hpp @@ -14,7 +14,7 @@ namespace stf { */ template class __attribute__ ((packed)) PackedContainer { - static_assert(type_utils::are_trivially_copyable_v, + static_assert(type_utils::are_pod_v, "All types held in a PackedContainer must be trivially copyable!"); private: @@ -49,7 +49,7 @@ namespace stf { template class __attribute__ ((packed)) PackedContainer /**< Specialized definition for the single-member variant */ { - static_assert(std::is_trivially_copyable_v, + static_assert(std::is_pod_v, "All types held in a PackedContainer must be trivially copyable!"); private: From b7695852f1165fc7bfe451ee04f92d7306887f83 Mon Sep 17 00:00:00 2001 From: Brett Dutro Date: Mon, 5 Feb 2024 14:56:55 -0800 Subject: [PATCH 4/4] Silence -Wsubobject-linkage warning that occurs in some versions of GCC for fields with custom formatters --- stf-inc/stf_protocol_fields.hpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/stf-inc/stf_protocol_fields.hpp b/stf-inc/stf_protocol_fields.hpp index a3078ce..92c4525 100644 --- a/stf-inc/stf_protocol_fields.hpp +++ b/stf-inc/stf_protocol_fields.hpp @@ -25,6 +25,19 @@ #define DEFAULT_VIS #endif +// Some GCC versions complain about Formatter lambdas that are defined in this header. As far as I can tell, +// these warnings are spurious. This disables the warnings if we're running GCC, but only around fields with +// custom formatters +#if defined(__GNUC__) && !defined(__clang__) + #define FORMATTER_PRAGMA_START \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wsubobject-linkage\"") + #define FORMATTER_PRAGMA_END _Pragma("GCC diagnostic pop") +#else + #define FORMATTER_PRAGMA_START + #define FORMATTER_PRAGMA_END +#endif + // Defines r-value and l-value field class constructors for the given argument type // parent_class_tuple and arg_type should either be bare type names or tuples packed with STF_PACK_TEMPLATE #define __FIELD_CONSTRUCTOR(parent_class_tuple, field_name, arg_type) \ @@ -69,8 +82,10 @@ // The __VA_ARGS__ correspond to the field class template parameters. // The first template parameter *must* be the underlying type of the field #define _FIELD_FORMAT_WRAPPER(fmt, field_macro, field_name, ...) \ - inline static const auto _FIELD_FORMATTER_NAME(field_name) = fmt; \ - field_macro(field_name, __VA_ARGS__, _FIELD_FORMATTER_NAME(field_name)) + FORMATTER_PRAGMA_START \ + inline static constexpr auto _FIELD_FORMATTER_NAME(field_name) = fmt; \ + field_macro(field_name, __VA_ARGS__, _FIELD_FORMATTER_NAME(field_name)); \ + FORMATTER_PRAGMA_END // Declares a subclass of ProtocolField // The __VA_ARGS__ are the template parameters supplied to ProtocolField