Skip to content

Commit

Permalink
Merge pull request #26 from sparcians/upstream-master
Browse files Browse the repository at this point in the history
GCC Fixes
  • Loading branch information
bdutro authored Feb 5, 2024
2 parents f252a87 + b769585 commit ad46cb7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
6 changes: 5 additions & 1 deletion cmake/stf-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions stf-inc/stf_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace stf {
* \param data Data to write
*/
template<typename... Ts>
static inline std::enable_if_t<type_utils::are_trivially_copyable_v<Ts...>>
static inline std::enable_if_t<type_utils::are_pod_v<Ts...>>
write_(STFOFstream& writer, Ts&&... data) {
writer << PackedContainer<std::remove_cv_t<std::remove_reference_t<Ts>>...>(std::forward<Ts>(data)...);
}
Expand All @@ -57,7 +57,7 @@ namespace stf {
* \param data Data to write
*/
template<typename... Ts>
static inline std::enable_if_t<std::negation_v<type_utils::are_trivially_copyable<Ts...>>>
static inline std::enable_if_t<std::negation_v<type_utils::are_pod<Ts...>>>
write_(STFOFstream& writer, Ts&&... data) {
(writer << ... << data);
}
Expand Down Expand Up @@ -132,7 +132,7 @@ namespace stf {
*/
template<typename... Ts>
__attribute__((always_inline))
static inline std::enable_if_t<type_utils::are_trivially_copyable_v<Ts...>, size_t>
static inline std::enable_if_t<type_utils::are_pod_v<Ts...>, size_t>
read_(STFIFstream& reader, Ts&&... data) {
PackedContainerView<std::remove_reference_t<Ts>...> temp;
reader >> temp;
Expand All @@ -148,7 +148,7 @@ namespace stf {
*/
template<typename... Ts>
__attribute__((always_inline))
static inline std::enable_if_t<std::negation_v<type_utils::are_trivially_copyable<Ts...>>, size_t>
static inline std::enable_if_t<std::negation_v<type_utils::are_pod<Ts...>>, size_t>
read_(STFIFstream& reader, Ts&&... data) {
(reader >> ... >> data);

Expand Down
4 changes: 2 additions & 2 deletions stf-inc/stf_packed_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace stf {
*/
template<typename T, typename ... Ts>
class __attribute__ ((packed)) PackedContainer {
static_assert(type_utils::are_trivially_copyable_v<T, Ts...>,
static_assert(type_utils::are_pod_v<T, Ts...>,
"All types held in a PackedContainer must be trivially copyable!");

private:
Expand Down Expand Up @@ -49,7 +49,7 @@ namespace stf {

template<typename T>
class __attribute__ ((packed)) PackedContainer<T> /**< Specialized definition for the single-member variant */ {
static_assert(std::is_trivially_copyable_v<T>,
static_assert(std::is_pod_v<T>,
"All types held in a PackedContainer must be trivially copyable!");

private:
Expand Down
19 changes: 17 additions & 2 deletions stf-inc/stf_protocol_fields.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions stf-inc/type_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ namespace stf {
template<typename... Ts>
inline constexpr bool are_trivially_copyable_v = are_trivially_copyable<Ts...>::value;

template <typename... Ts>
struct are_pod : std::conjunction<std::is_pod<std::remove_reference_t<Ts>>...> {};

template<typename... Ts>
inline constexpr bool are_pod_v = are_pod<Ts...>::value;

template <typename T, typename = void>
struct is_iterable : std::false_type {};

Expand Down

0 comments on commit ad46cb7

Please sign in to comment.