Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COMP: Suppress some Wformat-nonliteral warnings #4616

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ Standard: Cpp11
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
- ITK_GCC_PRAGMA_PUSH
- ITK_GCC_PRAGMA_POP
- ITK_GCC_SUPPRESS_Wfloat_equal
- ITK_GCC_SUPPRESS_Wformat_nonliteral
- CLANG_PRAGMA_PUSH
- CLANG_PRAGMA_POP
- CLANG_SUPPRESS_Wcpp14_extensions
- INTEL_PRAGMA_WARN_PUSH
- INTEL_PRAGMA_WARN_POP
- INTEL_SUPPRESS_warning_1292
TabWidth: 2
UseTab: Never
...
9 changes: 5 additions & 4 deletions .github/workflows/itk_dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ Crofton's
Cuadra
Cz
DDataFrameobject
Dz
Dasarathy
Deref
Dij
Expand All @@ -55,6 +54,7 @@ Dxx
Dyx
Dyy
Dyz
Dz
Dzx
Dzy
Dzz
Expand All @@ -74,13 +74,13 @@ Fletch
Freesurfer
Frenet
GEAdw
GPUSuperclass's
Gao
Gibbsian
Gifti
Golby
Graphviz
Greenleaf
Gifti
GPUSuperclass's
Guillen
Haar
Hackathon
Expand All @@ -95,11 +95,11 @@ Hilden
Hiraki
Hirschberg
Hostname
Intelli
IOregion
ITKIOMeshGifti
ITKImageToIplImage
ITKOptimizersv
Intelli
Irfan
Irix
Isocenter
Expand Down Expand Up @@ -740,6 +740,7 @@ ponderation
posn
postcondition
posteriori
pragmas
preallocated
precalculate
precalculating
Expand Down
14 changes: 8 additions & 6 deletions Modules/Core/Common/include/itkConceptChecking.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,11 @@ struct EqualityComparable
void
constraints()
{
CLANG_PRAGMA_PUSH
CLANG_SUPPRESS_Wfloat_equal Detail::RequireBooleanExpression(a == b);
ITK_GCC_PRAGMA_PUSH
ITK_GCC_SUPPRESS_Wfloat_equal
Detail::RequireBooleanExpression(a == b);
Detail::RequireBooleanExpression(a != b);
CLANG_PRAGMA_POP
ITK_GCC_PRAGMA_POP
}

T1 a;
Expand All @@ -331,10 +332,11 @@ struct Comparable
Detail::RequireBooleanExpression(a > b);
Detail::RequireBooleanExpression(a <= b);
Detail::RequireBooleanExpression(a >= b);
CLANG_PRAGMA_PUSH
CLANG_SUPPRESS_Wfloat_equal Detail::RequireBooleanExpression(a == b);
ITK_GCC_PRAGMA_PUSH
ITK_GCC_SUPPRESS_Wfloat_equal
Detail::RequireBooleanExpression(a == b);
Detail::RequireBooleanExpression(a != b);
CLANG_PRAGMA_POP
ITK_GCC_PRAGMA_POP
}

T1 a;
Expand Down
56 changes: 32 additions & 24 deletions Modules/Core/Common/include/itkMacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,27 @@ namespace itk
// to be quoted.
#define ITK_PRAGMA(x) _Pragma(#x)

// The clang compiler has many useful non-default compiler warnings
// that tend to have a high false positive rate.
// The following set of defines allows us to suppress false positives
// and still track down suspicious code
// The GCC/Clang compilers have many useful non-default compiler warnings
// that tend to have a high false positive rate or are otherwise not always appropriate.
// The following set of defines allows us to suppress instances of said warnings.

// For GCC and Clang (Clang also identifies itself as GCC, and supports these pragmas):
#if defined(__GNUC__)
# define ITK_GCC_PRAGMA_PUSH ITK_PRAGMA(GCC diagnostic push)
# define ITK_GCC_PRAGMA_POP ITK_PRAGMA(GCC diagnostic pop)
# define ITK_GCC_SUPPRESS_Wfloat_equal ITK_PRAGMA(GCC diagnostic ignored "-Wfloat-equal")
# define ITK_GCC_SUPPRESS_Wformat_nonliteral ITK_PRAGMA(GCC diagnostic ignored "-Wformat-nonliteral")
#else
# define ITK_GCC_PRAGMA_PUSH
# define ITK_GCC_PRAGMA_POP
# define ITK_GCC_SUPPRESS_Wfloat_equal
# define ITK_GCC_SUPPRESS_Wformat_nonliteral
#endif

// For Clang only (and not GCC):
#if defined(__clang__) && defined(__has_warning)
# define CLANG_PRAGMA_PUSH ITK_PRAGMA(clang diagnostic push)
# define CLANG_PRAGMA_POP ITK_PRAGMA(clang diagnostic pop)
# if __has_warning("-Wfloat-equal")
# define CLANG_SUPPRESS_Wfloat_equal ITK_PRAGMA(clang diagnostic ignored "-Wfloat-equal")
# else
# define CLANG_SUPPRESS_Wfloat_equal
# endif
# if __has_warning("-Wc++14-extensions")
# define CLANG_SUPPRESS_Wcpp14_extensions ITK_PRAGMA(clang diagnostic ignored "-Wc++14-extensions")
# else
Expand All @@ -119,7 +128,6 @@ namespace itk
#else
# define CLANG_PRAGMA_PUSH
# define CLANG_PRAGMA_POP
# define CLANG_SUPPRESS_Wfloat_equal
# define CLANG_SUPPRESS_Wcpp14_extensions
#endif

Expand Down Expand Up @@ -878,13 +886,13 @@ compilers.
itkDebugMacro("setting input " #name " to " << _arg); \
const DecoratorType * oldInput = \
itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
CLANG_PRAGMA_PUSH \
CLANG_SUPPRESS_Wfloat_equal \
ITK_GCC_PRAGMA_PUSH \
ITK_GCC_SUPPRESS_Wfloat_equal \
if (oldInput && oldInput->Get() == _arg) \
{ \
return; \
} \
CLANG_PRAGMA_POP \
ITK_GCC_PRAGMA_POP \
auto newInput = DecoratorType::New(); \
newInput->Set(_arg); \
this->Set##name##Input(newInput); \
Expand Down Expand Up @@ -982,17 +990,17 @@ compilers.
/** Set built-in type or regular C++ type. Creates member Set"name"() (e.g., SetVisibility()); */
// clang-format off
#define itkSetMacro(name, type) \
virtual void Set##name(type _arg) \
virtual void Set##name(type _arg) \
{ \
itkDebugMacro("setting " #name " to " << _arg); \
CLANG_PRAGMA_PUSH \
CLANG_SUPPRESS_Wfloat_equal \
ITK_GCC_PRAGMA_PUSH \
ITK_GCC_SUPPRESS_Wfloat_equal \
if (this->m_##name != _arg) \
{ \
this->m_##name = std::move(_arg); \
this->m_##name = std::move(_arg); \
this->Modified(); \
} \
CLANG_PRAGMA_POP \
ITK_GCC_PRAGMA_POP \
} \
ITK_MACROEND_NOOP_STATEMENT
// clang-format on
Expand Down Expand Up @@ -1080,14 +1088,14 @@ compilers.
{ \
const type temp_extrema = (_arg <= min ? min : (_arg >= max ? max : _arg)); \
itkDebugMacro("setting " << #name " to " << _arg); \
CLANG_PRAGMA_PUSH \
CLANG_SUPPRESS_Wfloat_equal \
ITK_GCC_PRAGMA_PUSH \
ITK_GCC_SUPPRESS_Wfloat_equal \
if (this->m_##name != temp_extrema) \
{ \
this->m_##name = temp_extrema; \
this->Modified(); \
} \
CLANG_PRAGMA_POP \
ITK_GCC_PRAGMA_POP \
} \
ITK_MACROEND_NOOP_STATEMENT
// clang-format on
Expand Down Expand Up @@ -1208,13 +1216,13 @@ compilers.
unsigned int i; \
for (i = 0; i < count; ++i) \
{ \
CLANG_PRAGMA_PUSH \
CLANG_SUPPRESS_Wfloat_equal \
ITK_GCC_PRAGMA_PUSH \
ITK_GCC_SUPPRESS_Wfloat_equal \
if (data[i] != this->m_##name[i]) \
{ \
break; \
} \
CLANG_PRAGMA_POP \
ITK_GCC_PRAGMA_POP \
} \
if (i < count) \
{ \
Expand Down
7 changes: 4 additions & 3 deletions Modules/Core/Common/include/itkMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -724,9 +724,10 @@ template <typename TInput1, typename TInput2>
inline bool
ExactlyEquals(const TInput1 & x1, const TInput2 & x2)
{
CLANG_PRAGMA_PUSH
CLANG_SUPPRESS_Wfloat_equal return x1 == x2;
CLANG_PRAGMA_POP
ITK_GCC_PRAGMA_PUSH
ITK_GCC_SUPPRESS_Wfloat_equal
return x1 == x2;
ITK_GCC_PRAGMA_POP
}

// The NotExactlyEquals function
Expand Down
12 changes: 6 additions & 6 deletions Modules/Core/Common/include/itkMathDetail.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ namespace Detail
////////////////////////////////////////
// Base versions

CLANG_PRAGMA_PUSH
CLANG_SUPPRESS_Wfloat_equal
ITK_GCC_PRAGMA_PUSH
ITK_GCC_SUPPRESS_Wfloat_equal

template <typename TReturn, typename TInput>
inline TReturn
RoundHalfIntegerToEven_base(TInput x)
template <typename TReturn, typename TInput>
inline TReturn
RoundHalfIntegerToEven_base(TInput x)
{
if (NumericTraits<TInput>::IsNonnegative(x))
{
Expand Down Expand Up @@ -135,7 +135,7 @@ Ceil_base(TInput x)
return (NumericTraits<TInput>::IsNegative(x)) ? r : (x == static_cast<TInput>(r) ? r : r + static_cast<TReturn>(1));
}

CLANG_PRAGMA_POP
ITK_GCC_PRAGMA_POP

////////////////////////////////////////
// 32 bits versions
Expand Down
6 changes: 3 additions & 3 deletions Modules/Core/Common/include/itkMultiThreaderBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,11 @@ CLANG_PRAGMA_PUSH
CLANG_SUPPRESS_Wcpp14_extensions
// clang-format on
# ifdef ITK_LEGACY_SILENT
struct ThreadInfoStruct
struct ThreadInfoStruct
# else
struct [[deprecated("Use WorkUnitInfo, ThreadInfoStruct is deprecated since ITK 5.0")]] ThreadInfoStruct
struct [[deprecated("Use WorkUnitInfo, ThreadInfoStruct is deprecated since ITK 5.0")]] ThreadInfoStruct
# endif
// clang-format off
// clang-format off
CLANG_PRAGMA_POP
INTEL_PRAGMA_WARN_POP
// clang-format on
Expand Down
33 changes: 19 additions & 14 deletions Modules/Core/Common/test/itkMathRoundProfileTest1.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,25 @@ itkMathRoundTestHelperFunction(double x)
return static_cast<int>(x >= 0. ? x : (itk::Math::ExactlyEquals(x, static_cast<int>(x)) ? x : x - 1.));
}

#define itkRoundMacro(x, y) \
if (x >= 0.5) \
{ \
y = static_cast<int>(x + 0.5); \
} \
else \
{ \
CLANG_PRAGMA_PUSH \
CLANG_SUPPRESS_Wfloat_equal if ((x + 0.5) == static_cast<int>(x + 0.5)) CLANG_PRAGMA_POP \
{ \
y = static_cast<int>(x + 0.5); \
} \
else { y = static_cast<int>(x - 0.5); } \
} \
#define itkRoundMacro(x, y) \
if (x >= 0.5) \
{ \
y = static_cast<int>(x + 0.5); \
} \
else \
{ \
ITK_GCC_PRAGMA_PUSH \
ITK_GCC_SUPPRESS_Wfloat_equal \
if ((x + 0.5) == static_cast<int>(x + 0.5)) \
{ \
y = static_cast<int>(x + 0.5); \
} \
else \
{ \
y = static_cast<int>(x - 0.5); \
} \
ITK_GCC_PRAGMA_POP \
} \
ITK_MACROEND_NOOP_STATEMENT

int
Expand Down
7 changes: 4 additions & 3 deletions Modules/Core/Common/test/itkRealTimeIntervalTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
#define CHECK_FOR_VALUE(a, b) \
{ \
double eps = 4.0 * itk::NumericTraits<double>::epsilon(); \
CLANG_PRAGMA_PUSH \
CLANG_SUPPRESS_Wfloat_equal eps = (b == 0.0) ? eps : itk::Math::abs(b * eps); \
CLANG_PRAGMA_POP \
ITK_GCC_PRAGMA_PUSH \
ITK_GCC_SUPPRESS_Wfloat_equal \
eps = (b == 0.0) ? eps : itk::Math::abs(b * eps); \
ITK_GCC_PRAGMA_POP \
if (itk::Math::abs(a - b) > eps) \
{ \
std::cerr << "Error in " #a << " expected " << b << " but got " << a << std::endl; \
Expand Down
7 changes: 4 additions & 3 deletions Modules/Core/Common/test/itkRealTimeStampTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
#define CHECK_FOR_VALUE(a, b) \
{ \
double eps = 4.0 * itk::NumericTraits<double>::epsilon(); \
CLANG_PRAGMA_PUSH \
CLANG_SUPPRESS_Wfloat_equal eps = (b == 0.0) ? eps : itk::Math::abs(b * eps); \
CLANG_PRAGMA_POP \
ITK_GCC_PRAGMA_PUSH \
ITK_GCC_SUPPRESS_Wfloat_equal \
eps = (b == 0.0) ? eps : itk::Math::abs(b * eps); \
ITK_GCC_PRAGMA_POP \
if (itk::Math::abs(a - b) > eps) \
{ \
std::cerr << "Error in " #a << " expected " << b << " but got " << a << std::endl; \
Expand Down
6 changes: 4 additions & 2 deletions Modules/Core/Common/test/itkVariableLengthVectorTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
#include "itkMath.h"

#define ASSERT(cond, text) \
CLANG_PRAGMA_PUSH \
CLANG_SUPPRESS_Wfloat_equal if (!(cond)) CLANG_PRAGMA_POP \
ITK_GCC_PRAGMA_PUSH \
ITK_GCC_SUPPRESS_Wfloat_equal \
if (!(cond)) \
{ \
std::cerr << __FILE__ << ':' << __LINE__ << ':' << "Assertion failed: " << #cond << ": " << text << std::endl; \
result = EXIT_FAILURE; \
} \
ITK_GCC_PRAGMA_POP \
ITK_MACROEND_NOOP_STATEMENT

int
Expand Down
Loading