diff --git a/Modules/Core/Common/include/itkSingleton.h b/Modules/Core/Common/include/itkSingleton.h index 7e06639aeca..17b939f9497 100644 --- a/Modules/Core/Common/include/itkSingleton.h +++ b/Modules/Core/Common/include/itkSingleton.h @@ -23,15 +23,18 @@ #include #include +#ifndef ITK_FUTURE_LEGACY_REMOVE /** \brief A function which does nothing + * \deprecated Preferably use the C++ `[[maybe_unused]]` attribute instead! * * This function is to be used to mark parameters as unused to suppress * compiler warning. It can be used when the parameter needs to be named * (i.e. itkNotUsed cannot be used) but is not always used. */ template -inline void +[[deprecated("Preferably use the C++ `[[maybe_unused]]` attribute instead!")]] inline void Unused(const T &){}; +#endif namespace itk { @@ -124,9 +127,8 @@ template T * Singleton(const char * globalName, std::function deleteFunc) { - static SingletonIndex * singletonIndex = SingletonIndex::GetInstance(); - Unused(singletonIndex); - T * instance = SingletonIndex::GetInstance()->GetGlobalInstance(globalName); + [[maybe_unused]] static SingletonIndex * singletonIndex = SingletonIndex::GetInstance(); + T * instance = SingletonIndex::GetInstance()->GetGlobalInstance(globalName); if (instance == nullptr) { instance = new T; diff --git a/Modules/Core/Common/src/itkObjectFactoryBase.cxx b/Modules/Core/Common/src/itkObjectFactoryBase.cxx index ce883086638..9c78f6f5dc1 100644 --- a/Modules/Core/Common/src/itkObjectFactoryBase.cxx +++ b/Modules/Core/Common/src/itkObjectFactoryBase.cxx @@ -832,8 +832,7 @@ ObjectFactoryBase::SynchronizeObjectFactoryBase(void * objectFactoryBasePrivate) std::list ObjectFactoryBase::GetRegisteredFactories() { - // static SingletonIndex * singletonIndex = SingletonIndex::GetInstance(); - // Unused(singletonIndex); + // [[maybe_unused]] static SingletonIndex * singletonIndex = SingletonIndex::GetInstance(); ObjectFactoryBase::Initialize(); return m_PimplGlobals->m_RegisteredFactories; }