diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 2b5381b0..b3c4b8e1 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -51,10 +51,6 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") find_package(range-v3) target_link_libraries(mp-units-core INTERFACE range-v3::range-v3) endif() -elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - target_compile_options(mp-units-core INTERFACE - -Wno-non-template-friend - ) elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") target_compile_options(mp-units-core INTERFACE /utf-8 # Specifies both the source character set and the execution character set as UTF-8 diff --git a/src/core/include/units/bits/external/downcasting.h b/src/core/include/units/bits/external/downcasting.h index eac6d432..ef1039e5 100644 --- a/src/core/include/units/bits/external/downcasting.h +++ b/src/core/include/units/bits/external/downcasting.h @@ -38,8 +38,11 @@ namespace units { template struct downcast_base { using downcast_base_type = BaseType; +UNITS_DIAGNOSTIC_PUSH +UNITS_DIAGNOSTIC_IGNORE_NON_TEMPLATE_FRIEND friend auto downcast_guide(downcast_base); friend auto downcast_poison_pill(downcast_base); +UNITS_DIAGNOSTIC_POP }; template diff --git a/src/core/include/units/bits/external/hacks.h b/src/core/include/units/bits/external/hacks.h index 8eb647a8..d72df2bf 100644 --- a/src/core/include/units/bits/external/hacks.h +++ b/src/core/include/units/bits/external/hacks.h @@ -31,6 +31,26 @@ #define UNITS_COMP_MSVC _MSC_VER #endif +// Adapted from https://github.com/ericniebler/range-v3/blob/master/include/range/v3/detail/config.hpp#L185. +#define UNITS_PRAGMA(X) _Pragma(#X) +#if !UNITS_COMP_MSVC +#define UNITS_DIAGNOSTIC_PUSH UNITS_PRAGMA(GCC diagnostic push) +#define UNITS_DIAGNOSTIC_POP UNITS_PRAGMA(GCC diagnostic pop) +#define UNITS_DIAGNOSTIC_IGNORE_PRAGMAS UNITS_PRAGMA(GCC diagnostic ignored "-Wpragmas") +#define UNITS_DIAGNOSTIC_IGNORE(X) \ + UNITS_DIAGNOSTIC_IGNORE_PRAGMAS \ + UNITS_PRAGMA(GCC diagnostic ignored "-Wunknown-pragmas") \ + UNITS_PRAGMA(GCC diagnostic ignored "-Wunknown-warning-option") \ + UNITS_PRAGMA(GCC diagnostic ignored X) +#define UNITS_DIAGNOSTIC_IGNORE_NON_TEMPLATE_FRIEND UNITS_DIAGNOSTIC_IGNORE("-Wnon-template-friend") +#else +#define UNITS_DIAGNOSTIC_PUSH UNITS_PRAGMA(warning(push)) +#define UNITS_DIAGNOSTIC_POP UNITS_PRAGMA(warning(pop)) +#define UNITS_DIAGNOSTIC_IGNORE_PRAGMAS UNITS_PRAGMA(warning(disable : 4068)) +#define UNITS_DIAGNOSTIC_IGNORE(X) UNITS_DIAGNOSTIC_IGNORE_PRAGMAS UNITS_PRAGMA(warning(disable : X)) +#define UNITS_DIAGNOSTIC_IGNORE_NON_TEMPLATE_FRIEND +#endif + #if UNITS_COMP_CLANG #include