From c27207500dfc3396189f3432c4959a8061fcd758 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Fri, 3 Jul 2020 00:10:31 +0100 Subject: [PATCH] Cleanup some compiler warnings --- CMakeModules/Warnings.cmake | 27 +++++++++++++++++++ libs/kimath/include/math/util.h | 10 +++++++ .../dialog_pns_length_tuning_settings.cpp | 2 +- pcbnew/gpcb_plugin.cpp | 4 +-- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/CMakeModules/Warnings.cmake b/CMakeModules/Warnings.cmake index ff4592cefb..26101732fb 100644 --- a/CMakeModules/Warnings.cmake +++ b/CMakeModules/Warnings.cmake @@ -124,6 +124,7 @@ if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) message( STATUS "Enabling warning -Wsign-compare" ) endif() + # Warn about missing initializers in construction CHECK_CXX_COMPILER_FLAG( "-Wmissing-field-initializers" COMPILER_SUPPORTS_WMISSING_INIT ) @@ -133,4 +134,30 @@ if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) endif() + # Warn about empty if/for/while bodies + CHECK_CXX_COMPILER_FLAG( "-Wempty-body" COMPILER_SUPPORTS_WEMPTY_BODY ) + + if( COMPILER_SUPPORTS_WEMPTY_BODY ) + set( WARN_FLAGS_CXX "${WARN_FLAGS_CXX} -Wempty-body" ) + message( STATUS "Enabling warning -Wempty-body" ) + endif() + + + # Warn about out of order intialization + CHECK_CXX_COMPILER_FLAG( "-Wreorder" COMPILER_SUPPORTS_WREORDER ) + + if( COMPILER_SUPPORTS_WREORDER ) + set( WARN_FLAGS_CXX "${WARN_FLAGS_CXX} -Wreorder" ) + message( STATUS "Enabling warning -Wreorder" ) + endif() + + + # Warn about mismatched class/struct declarations + CHECK_CXX_COMPILER_FLAG( "-Wmismatched-tags" COMPILER_SUPPORTS_WMISMATCHED_TAGS ) + + if( COMPILER_SUPPORTS_WMISMATCHED_TAGS ) + set( WARN_FLAGS_CXX "${WARN_FLAGS_CXX} -Wmismatched-tags" ) + message( STATUS "Enabling warning -Wmismatched-tags" ) + endif() + endif() diff --git a/libs/kimath/include/math/util.h b/libs/kimath/include/math/util.h index 7d13679c71..6df1a5611d 100644 --- a/libs/kimath/include/math/util.h +++ b/libs/kimath/include/math/util.h @@ -52,6 +52,12 @@ template inline const T& Clamp( const T& lower, const T& value, con return value; } +// Surpress an annoying warning that the explicit rounding we do is not precise +#if defined( __GNUC__ ) || defined( __CLANG__ ) + _Pragma( "GCC diagnostic push" ) \ + _Pragma( "GCC diagnostic ignored \"-Wimplicit-int-float-conversion\"" ) +#endif + /** * Round a floating point number to an integer using "round halfway cases away from zero". * @@ -74,6 +80,10 @@ constexpr ret_type KiROUND( fp_type v ) return ret_type( max_ret( ret ) ); } +#if defined( __GNUC__ ) || defined( __CLANG__ ) + _Pragma( "GCC diagnostic pop" ) +#endif + /** * Function rescale() * diff --git a/pcbnew/dialogs/dialog_pns_length_tuning_settings.cpp b/pcbnew/dialogs/dialog_pns_length_tuning_settings.cpp index 07584301a2..187567b04f 100644 --- a/pcbnew/dialogs/dialog_pns_length_tuning_settings.cpp +++ b/pcbnew/dialogs/dialog_pns_length_tuning_settings.cpp @@ -113,7 +113,7 @@ bool DIALOG_PNS_LENGTH_TUNING_SETTINGS::AcceptOptions( ) return false; if( !m_spacing.Validate( 0, std::numeric_limits::max() ) ) return false; - if( !m_targetLength.Validate( 0, std::numeric_limits::max() ) ) + if( !m_targetLength.Validate( 0, static_cast( std::numeric_limits::max() ) ) ) return false; if( !m_radius.Validate( 0, 100 ) ) return false; diff --git a/pcbnew/gpcb_plugin.cpp b/pcbnew/gpcb_plugin.cpp index ed720d5cfe..ef29ac3a87 100644 --- a/pcbnew/gpcb_plugin.cpp +++ b/pcbnew/gpcb_plugin.cpp @@ -52,7 +52,7 @@ static inline long parseInt( const wxString& aValue, double aScalar ) { - double value = LONG_MAX; + double value = std::numeric_limits::max(); /* * In 2011 gEDA/pcb introduced values with units, like "10mm" or "200mil". @@ -87,7 +87,7 @@ static inline long parseInt( const wxString& aValue, double aScalar ) // This conversion reports failure on strings as simple as "1000", still // it returns the right result in &value. Thus, ignore the return value. aValue.ToCDouble(&value); - if( value == LONG_MAX ) // conversion really failed + if( value == std::numeric_limits::max() ) // conversion really failed { THROW_IO_ERROR( wxString::Format( _( "Cannot convert \"%s\" to an integer" ), aValue.GetData() ) );