Skip to content

Commit

Permalink
STYLE: Prefer c++11 [[maybe_unused]] attribute over (void)varname
Browse files Browse the repository at this point in the history
The use of (void)varname was a mechanism to silence compiler
warnings prior to universal language support in c++11 for
the [[maybe_unused]] attribute specifier.
  • Loading branch information
hjmjohnson committed Apr 12, 2024
1 parent c41161d commit 126169a
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 32 deletions.
9 changes: 4 additions & 5 deletions Modules/Core/Common/CMake/itkCheckHasFenvtStructMember.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@
int
main()
{
fenv_t fenv;
[[maybe_unused]] fenv_t fenv;
#if defined(ITK_CHECK_FENV_T_CONTROL)
(void)sizeof(fenv.__control);
[[maybe_unused]] const auto tempSize = sizeof(fenv.__control);
#elif defined(ITK_CHECK_FENV_T_CONTROL_WORD)
(void)sizeof(fenv.__control_word);
[[maybe_unused]] const auto tempSize = sizeof(fenv.__control_word);
#elif defined(ITK_CHECK_FENV_T_CW)
(void)sizeof(fenv.__cw);
[[maybe_unused]] const auto tempSize = sizeof(fenv.__cw);
#else
(void)fenv;
# error \
"Unknown fenv_t struct member test: Make sure to specify a compile definition of the form -DITK_CHECK_FENV_T_xxx"
#endif
Expand Down
4 changes: 1 addition & 3 deletions Modules/Core/Common/include/itkObjectFactoryBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,10 @@ class ITKCommon_EXPORT ObjectFactoryBase : public Object
{};

// Factory registration, made thread-safe by "magic statics" (as introduced with C++11).
static const FactoryRegistration staticFactoryRegistration = [] {
[[maybe_unused]] static const FactoryRegistration staticFactoryRegistration = [] {
RegisterFactoryInternal(TFactory::New());
return FactoryRegistration{};
}();

(void)staticFactoryRegistration;
}

/** Initialize the static members of ObjectFactoryBase. */
Expand Down
9 changes: 4 additions & 5 deletions Modules/Core/Common/include/itkSingletonMacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@
#ifndef itkSingletonMacro_h
#define itkSingletonMacro_h

#define itkInitGlobalsMacro(VarName) \
{ \
static auto * staticGlobals = Get##VarName##Pointer(); \
(void)staticGlobals; \
} \
#define itkInitGlobalsMacro(VarName) \
{ \
[[maybe_unused]] static auto * staticGlobals = Get##VarName##Pointer(); \
} \
ITK_MACROEND_NOOP_STATEMENT

#define itkGetGlobalDeclarationMacro(Type, VarName) static Type * Get##VarName##Pointer()
Expand Down
4 changes: 1 addition & 3 deletions Modules/Core/Common/include/itkVariableLengthVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,8 @@ class ITK_TEMPLATE_EXPORT VariableLengthVector
struct NeverReallocate : AllocateRootPolicy
{
bool
operator()(unsigned int newSize, unsigned int oldSize) const
operator()([[maybe_unused]] unsigned int newSize, [[maybe_unused]] unsigned int oldSize) const
{
(void)newSize;
(void)oldSize;
itkAssertInDebugAndIgnoreInReleaseMacro(newSize == oldSize &&
"SetSize is expected to never change the VariableLengthVector size...");
return true;
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/src/itkFloatingPointExceptions.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ itkFloatingPointExceptionsAbortOrExit()
}
}

void
[[maybe_unused]] void
itkFloatingPointExceptionsNotSupported()
{
std::cerr << "FloatingPointExceptions are not supported on this platform." << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ FloatingPointExceptions::Enable()
sigaction(SIGFPE, &act, nullptr);
# endif
FloatingPointExceptions::m_PimplGlobals->m_Enabled = true;
(void)itkFloatingPointExceptionsNotSupported; // avoid unused-function warning
#else
itkFloatingPointExceptionsNotSupported();
#endif
Expand Down
3 changes: 1 addition & 2 deletions Modules/Core/Common/test/itkBitCastGTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ TEST(BitCast, ResultIsBitwiseEqualToArgument)
Expect_return_value_is_bitwise_equal_to_function_argument<unsigned int>(i);
}

int value;
(void)value;
[[maybe_unused]] int value;
Expect_return_value_is_bitwise_equal_to_function_argument<intptr_t>(&value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ itkQuadEdgeMeshEulerOperatorCreateCenterVertexTest(int, char *[])
std::cout << "OK" << std::endl;
#endif

(void)createCenterVertex->GetNameOfClass();
[[maybe_unused]] const std::string name_of_class = createCenterVertex->GetNameOfClass();

createCenterVertex->SetInput(mesh);
#ifndef NDEBUG
Expand Down
8 changes: 2 additions & 6 deletions Modules/IO/MINC/src/itkMINCImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ extern "C"
void
MINCIOFreeTmpDimHandle(unsigned int size, midimhandle_t * ptr)
{
int error = 0;
unsigned int x = 0;
if (!ptr)
{
/*
Expand All @@ -46,16 +44,14 @@ extern "C"
#endif
return;
}
for (; x < size; ++x)
for (unsigned int x = 0; x < size; ++x)
{
error = mifree_dimension_handle(ptr[x]);
[[maybe_unused]] int error = mifree_dimension_handle(ptr[x]);
#ifndef NDEBUG
if (error != MI_NOERROR)
{
printf("MINCIOFreeTmpDimHandle: mifree_dimension_handle(ptr[%u]) returned %d", x, error);
}
#else
(void)error;
#endif
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ TransformFactoryBase::RegisterDefaultTransforms()
// make sure that the factory instance has
// been created. All normal paths to this method
// already do this but this makes certain sure it's done
(void)TransformFactoryBase::GetFactory();
[[maybe_unused]] auto currentFactory = TransformFactoryBase::GetFactory();

if (!TransformFactoryBasePrivate::DefaultTransformsRegistered)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ CovarianceSampleFilter<TSample>::MakeOutput(DataObjectPointerArraySizeType index

if (index == 1)
{
MeasurementVectorRealType mean;
(void)mean; // for complainty pants : valgrind
[[maybe_unused]] MeasurementVectorRealType mean;
NumericTraits<MeasurementVectorRealType>::SetLength(mean, this->GetMeasurementVectorSize());
// NumericTraits::SetLength also initializes array to zero
auto decoratedMean = MeasurementVectorDecoratedType::New();
Expand Down
3 changes: 1 addition & 2 deletions Modules/Numerics/Statistics/include/itkMeanSampleFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ template <typename TSample>
auto
MeanSampleFilter<TSample>::MakeOutput(DataObjectPointerArraySizeType itkNotUsed(idx)) -> DataObjectPointer
{
MeasurementVectorRealType mean;
(void)mean; // for complainty pants : valgrind
[[maybe_unused]] MeasurementVectorRealType mean;
NumericTraits<MeasurementVectorRealType>::SetLength(mean, this->GetMeasurementVectorSize());
// NumericTraits::SetLength also initializes array to zero
auto decoratedMean = MeasurementVectorDecoratedType::New();
Expand Down

0 comments on commit 126169a

Please sign in to comment.