Only try to remove the implicit conversion warning if it is supported

This commit is contained in:
Ian McInerney 2020-07-03 02:59:19 +01:00
parent f7156a9d49
commit b5adf5bb21
5 changed files with 15 additions and 2 deletions

View File

@ -160,4 +160,11 @@ if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
message( STATUS "Enabling warning -Wmismatched-tags" )
endif()
# See if the compiler will throw warnings on these conversions
CHECK_CXX_COMPILER_FLAG( "-Wimplicit-int-float-conversion" COMPILER_SUPPORTS_WIMPLICIT_FLOAT_CONVERSION )
if( COMPILER_SUPPORTS_WIMPLICIT_FLOAT_CONVERSION )
# This one is different, it is used to guard warning removal for this inside the code
set( HAVE_WIMPLICIT_FLOAT_CONVERSION true )
endif()
endif()

View File

@ -49,6 +49,9 @@
#define strncasecmp strnicmp
#endif
// Does the compiler support the -Wimplicit-int-float-conversion warning
#cmakedefine HAVE_WIMPLICIT_FLOAT_CONVERSION
// Use Posix getc_unlocked() instead of getc() when it's available.
#cmakedefine HAVE_FGETC_NOLOCK

View File

@ -36,6 +36,7 @@ target_link_libraries( kimath
)
target_include_directories( kimath PUBLIC
${PROJECT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
$<TARGET_PROPERTY:clipper,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:othermath,INTERFACE_INCLUDE_DIRECTORIES>

View File

@ -26,6 +26,7 @@
#ifndef UTIL_H
#define UTIL_H
#include <config.h>
#include <cstdint>
#include <limits>
#include <typeinfo>
@ -53,7 +54,7 @@ template <typename T> inline const T& Clamp( const T& lower, const T& value, con
}
// Surpress an annoying warning that the explicit rounding we do is not precise
#if defined( __GNUC__ ) || defined( __CLANG__ )
#ifdef HAVE_WIMPLICIT_FLOAT_CONVERSION
_Pragma( "GCC diagnostic push" ) \
_Pragma( "GCC diagnostic ignored \"-Wimplicit-int-float-conversion\"" )
#endif
@ -80,7 +81,7 @@ constexpr ret_type KiROUND( fp_type v )
return ret_type( max_ret( ret ) );
}
#if defined( __GNUC__ ) || defined( __CLANG__ )
#ifdef HAVE_WIMPLICIT_FLOAT_CONVERSION
_Pragma( "GCC diagnostic pop" )
#endif

View File

@ -11,5 +11,6 @@ target_include_directories( othermath
# kiround is needed
target_include_directories( othermath
PRIVATE
${PROJECT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/libs/kimath/include
)