refactor: add portable diagnostic pragmas

This commit is contained in:
Johel Ernesto Guerrero Peña
2021-03-16 23:03:20 -04:00
committed by Mateusz Pusz
parent b356a53fa4
commit 229d303319
3 changed files with 23 additions and 4 deletions

View File

@@ -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

View File

@@ -38,8 +38,11 @@ namespace units {
template<typename BaseType>
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<typename T>

View File

@@ -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 <ciso646>