Skip to content

Commit

Permalink
STYLE: Prefer c++11 [[maybe_unused]] attribute over (void)
Browse files Browse the repository at this point in the history
The use of (void)varname was a mechansim 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 877acba commit 7f8732a
Show file tree
Hide file tree
Showing 74 changed files with 289 additions and 367 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ TreeIteratorBase<TTreeType>::Add(ValueType element)

template <typename TTreeType>
bool
TreeIteratorBase<TTreeType>::Add(int itkNotUsed(childPosition), ValueType element)
TreeIteratorBase<TTreeType>::Add([[maybe_unused]] int childPosition, ValueType element)
{
if (m_Position)
{
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ ExtractImageFilterCopyRegion(
const typename BinaryUnsignedIntDispatch<T1, T2>::FirstLessThanSecondType & firstLessThanSecond,
ImageRegion<T1> & destRegion,
const ImageRegion<T2> & srcRegion,
const ImageRegion<T1> & totalInputExtractionRegion)
[[maybe_unused]] const ImageRegion<T1> & totalInputExtractionRegion)
{
(void)totalInputExtractionRegion;
ImageToImageFilterDefaultCopyRegion<T1, T2>(firstLessThanSecond, destRegion, srcRegion);
}

Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/include/itkImageBoundaryCondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ class ITK_TEMPLATE_EXPORT ImageBoundaryCondition
* pixel values in the outputRequestedRegion.
*/
virtual RegionType
GetInputRequestedRegion(const RegionType & inputLargestPossibleRegion, const RegionType & outputRequestedRegion) const
GetInputRequestedRegion(const RegionType & inputLargestPossibleRegion,
[[maybe_unused]] const RegionType & outputRequestedRegion) const
{
(void)outputRequestedRegion;
return inputLargestPossibleRegion;
}

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
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkPolyLineCell.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ PolyLineCell<TCellInterface>::SetPointIds(PointIdConstIterator first)
*/
template <typename TCellInterface>
void
PolyLineCell<TCellInterface>::SetPointIds(int itkNotUsed(dummy), int num, PointIdConstIterator first)
PolyLineCell<TCellInterface>::SetPointIds([[maybe_unused]] int dummy, int num, PointIdConstIterator first)
{
PointIdConstIterator ii(first);

Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkPolygonCell.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ PolygonCell<TCellInterface>::GetBoundaryFeature(int dimension,
*/
template <typename TCellInterface>
void
PolygonCell<TCellInterface>::SetPointIds(int itkNotUsed(dummy), int num, PointIdConstIterator first)
PolygonCell<TCellInterface>::SetPointIds([[maybe_unused]] int dummy, int num, PointIdConstIterator first)
{
PointIdConstIterator ii(first);

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
20 changes: 8 additions & 12 deletions Modules/Core/Common/include/itkVariableLengthVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class ITK_TEMPLATE_EXPORT VariableLengthVector
struct AlwaysReallocate : AllocateRootPolicy
{
bool
operator()(unsigned int itkNotUsed(newSize), unsigned int itkNotUsed(oldSize)) const
operator()([[maybe_unused]] unsigned int newSize, [[maybe_unused]] unsigned int oldSize) const
{
return true;
}
Expand All @@ -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 Expand Up @@ -298,10 +296,10 @@ class ITK_TEMPLATE_EXPORT VariableLengthVector
{
template <typename TValue2>
void
operator()(unsigned int itkNotUsed(newSize),
unsigned int itkNotUsed(oldSize),
TValue2 * itkNotUsed(oldBuffer),
TValue2 * itkNotUsed(newBuffer)) const
operator()([[maybe_unused]] unsigned int newSize,
[[maybe_unused]] unsigned int oldSize,
TValue2 * itkNotUsed(oldBuffer),
TValue2 * itkNotUsed(newBuffer)) const
{}
};
//@}
Expand Down Expand Up @@ -1033,9 +1031,8 @@ struct GetType
* \note the default unspecialized behaviour returns the input number \c v.
*/
static Type
Load(Type const & v, unsigned int idx)
Load(Type const & v, [[maybe_unused]] unsigned int idx)
{
(void)idx;
return v;
}
};
Expand All @@ -1052,9 +1049,8 @@ struct GetType
*/
template <typename TExpr1, typename TExpr2>
inline std::enable_if_t<mpl::And<mpl::IsArray<TExpr1>, mpl::IsArray<TExpr2>>::Value, unsigned int>
GetSize(TExpr1 const & lhs, TExpr2 const & rhs)
GetSize(TExpr1 const & lhs, [[maybe_unused]] TExpr2 const & rhs)
{
(void)rhs;
itkAssertInDebugAndIgnoreInReleaseMacro(lhs.Size() == rhs.Size());
return lhs.Size();
}
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/src/itkObjectFactoryBase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ using ITK_LOAD_FUNCTION = ObjectFactoryBase * (*)();
* lower case for LibExtension values.
*/
inline bool
NameIsSharedLibrary(const char * name)
NameIsSharedLibrary([[maybe_unused]] const char * name)
{
#ifdef ITK_DYNAMIC_LOADING
std::string extension = itksys::DynamicLoader::LibExtension();
Expand All @@ -368,7 +368,6 @@ NameIsSharedLibrary(const char * name)
return true;
}
#else // ITK_DYNAMIC_LOADING
(void)name;
itkGenericExceptionMacro("ITK was not built with support for dynamic loading.");
#endif
return false;
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);
}
5 changes: 1 addition & 4 deletions Modules/Core/Common/test/itkCrossHelperTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@


int
itkCrossHelperTest(int argc, char * argv[])
itkCrossHelperTest([[maybe_unused]] int argc, [[maybe_unused]] char * argv[])
{
(void)argc;
(void)argv;

constexpr unsigned int Dimension2D = 2;
constexpr unsigned int Dimension3D = 3;
constexpr unsigned int Dimension4D = 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class ITK_TEMPLATE_EXPORT GPUFiniteDifferenceFunction : public FiniteDifferenceF
/** Allocate GPU buffers for computing metric statistics
* */
virtual void
GPUAllocateMetricData(unsigned int itkNotUsed(numPixels))
GPUAllocateMetricData([[maybe_unused]] unsigned int numPixels)
{}

/** Release GPU buffers for computing metric statistics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ testEvaluateValueAndDerivative()
}

int
itkBSplineInterpolateImageFunctionTest(int itkNotUsed(argc), char * itkNotUsed(argv)[])
itkBSplineInterpolateImageFunctionTest([[maybe_unused]] int argc, char * itkNotUsed(argv)[])
{
int flag = 0; /* Did this test program work? */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


int
itkRayCastInterpolateImageFunctionTest(int itkNotUsed(argc), char * itkNotUsed(argv)[])
itkRayCastInterpolateImageFunctionTest([[maybe_unused]] int argc, char * itkNotUsed(argv)[])
{

using PixelType = unsigned char;
Expand Down
91 changes: 31 additions & 60 deletions Modules/Core/QuadEdgeMesh/include/itkQuadEdgeMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,8 @@ class ITK_TEMPLATE_EXPORT QuadEdgeMesh : public Mesh<TPixel, VDimension, TTraits
* https://public.kitware.com/pipermail/insight-users/2005-April/012613.html
*/
void
CopyInformation(const DataObject * data) override
{
(void)data;
}
CopyInformation([[maybe_unused]] const DataObject * data) override
{}
void
Graft(const DataObject * data) override;

Expand All @@ -234,113 +232,86 @@ class ITK_TEMPLATE_EXPORT QuadEdgeMesh : public Mesh<TPixel, VDimension, TTraits
#if !defined(ITK_WRAPPING_PARSER)
/** overloaded method for backward compatibility */
void
SetBoundaryAssignments(int dimension, BoundaryAssignmentsContainer * container)
{
(void)dimension;
(void)container;
}
SetBoundaryAssignments([[maybe_unused]] int dimension, [[maybe_unused]] BoundaryAssignmentsContainer * container)
{}

/** overloaded method for backward compatibility */
BoundaryAssignmentsContainerPointer
GetBoundaryAssignments(int dimension)
GetBoundaryAssignments([[maybe_unused]] int dimension)
{
(void)dimension;
return (nullptr);
}

/** overloaded method for backward compatibility */
const BoundaryAssignmentsContainerPointer
GetBoundaryAssignments(int dimension) const
GetBoundaryAssignments([[maybe_unused]] int dimension) const
{
(void)dimension;
return (nullptr);
}

#endif

/** overloaded method for backward compatibility */
void
SetBoundaryAssignment(int dimension,
CellIdentifier cellId,
CellFeatureIdentifier featureId,
CellIdentifier boundaryId)
{
(void)dimension;
(void)cellId;
(void)featureId;
(void)boundaryId;
}
SetBoundaryAssignment([[maybe_unused]] int dimension,
[[maybe_unused]] CellIdentifier cellId,
[[maybe_unused]] CellFeatureIdentifier featureId,
[[maybe_unused]] CellIdentifier boundaryId)
{}

/** overloaded method for backward compatibility */
bool
GetBoundaryAssignment(int dimension,
CellIdentifier cellId,
CellFeatureIdentifier featureId,
CellIdentifier * boundaryId) const
GetBoundaryAssignment([[maybe_unused]] int dimension,
[[maybe_unused]] CellIdentifier cellId,
[[maybe_unused]] CellFeatureIdentifier featureId,
[[maybe_unused]] CellIdentifier * boundaryId) const
{
(void)dimension;
(void)cellId;
(void)featureId;
(void)boundaryId;
return (false); // ALEX: is it the good way?
}

/** overloaded method for backward compatibility */
bool
RemoveBoundaryAssignment(int dimension, CellIdentifier cellId, CellFeatureIdentifier featureId)
RemoveBoundaryAssignment([[maybe_unused]] int dimension,
[[maybe_unused]] CellIdentifier cellId,
[[maybe_unused]] CellFeatureIdentifier featureId)
{
(void)dimension;
(void)cellId;
(void)featureId;
return (false); // ALEX: is it the good way?
}

/** overloaded method for backward compatibility */
bool
GetCellBoundaryFeature(int dimension,
CellIdentifier cellId,
CellFeatureIdentifier featureId,
CellAutoPointer & cellAP) const
GetCellBoundaryFeature([[maybe_unused]] int dimension,
[[maybe_unused]] CellIdentifier cellId,
[[maybe_unused]] CellFeatureIdentifier featureId,
[[maybe_unused]] CellAutoPointer & cellAP) const
{
(void)dimension;
(void)cellId;
(void)featureId;
(void)cellAP;
return (false);
}

/** overloaded method for backward compatibility */
CellIdentifier
GetCellBoundaryFeatureNeighbors(int dimension,
CellIdentifier cellId,
CellFeatureIdentifier featureId,
std::set<CellIdentifier> * cellSet)
GetCellBoundaryFeatureNeighbors([[maybe_unused]] int dimension,
[[maybe_unused]] CellIdentifier cellId,
[[maybe_unused]] CellFeatureIdentifier featureId,
[[maybe_unused]] std::set<CellIdentifier> * cellSet)
{
(void)dimension;
(void)cellId;
(void)featureId;
(void)cellSet;
return CellIdentifier{};
}

/** NOTE ALEX: this method do not use CellFeature and thus could be recoded */
CellIdentifier
GetCellNeighbors(CellIdentifier itkNotUsed(cellId), std::set<CellIdentifier> * itkNotUsed(cellSet))
GetCellNeighbors([[maybe_unused]] CellIdentifier cellId, [[maybe_unused]] std::set<CellIdentifier> * cellSet)
{
return CellIdentifier{};
}

/** overloaded method for backward compatibility */
bool
GetAssignedCellBoundaryIfOneExists(int dimension,
CellIdentifier cellId,
CellFeatureIdentifier featureId,
CellAutoPointer & cellAP) const
GetAssignedCellBoundaryIfOneExists([[maybe_unused]] int dimension,
[[maybe_unused]] CellIdentifier cellId,
[[maybe_unused]] CellFeatureIdentifier featureId,
[[maybe_unused]] CellAutoPointer & cellAP) const
{
(void)dimension;
(void)cellId;
(void)featureId;
(void)cellAP;
return (false); // ALEX: is it the good way?
}

Expand Down
Loading

0 comments on commit 7f8732a

Please sign in to comment.