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

Check thisClass argument of GetNameOfClass macro calls, fix class name returned by GetNameOfClass() overrides #4378

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
17 changes: 13 additions & 4 deletions Modules/Core/Common/include/itkMacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#endif

#include <sstream>
#include <type_traits> // For is_same, remove_const, and remove_reference.

/** \namespace itk
* \brief The "itk" namespace contains all Insight Segmentation and
Expand Down Expand Up @@ -436,12 +437,20 @@ namespace itk
/** Macro's used to add `GetNameOfClass()` member functions to polymorphic ITK classes: `itkVirtualGetNameOfClassMacro`
* adds a virtual `GetNameOfClass()` member function to the class definition, and `itkOverrideGetNameOfClassMacro` adds
* a `GetNameOfClass()` override. */
#define itkVirtualGetNameOfClassMacro(thisClass) \
virtual const char * GetNameOfClass() const { return #thisClass; } \
#define itkVirtualGetNameOfClassMacro(thisClass) \
virtual const char * GetNameOfClass() const \
{ \
static_assert(std::is_same_v<thisClass, std::remove_const_t<std::remove_reference_t<decltype(*this)>>>); \
return #thisClass; \
} \
ITK_MACROEND_NOOP_STATEMENT

#define itkOverrideGetNameOfClassMacro(thisClass) \
const char * GetNameOfClass() const override { return #thisClass; } \
#define itkOverrideGetNameOfClassMacro(thisClass) \
const char * GetNameOfClass() const override \
{ \
static_assert(std::is_same_v<thisClass, std::remove_const_t<std::remove_reference_t<decltype(*this)>>>); \
return #thisClass; \
} \
ITK_MACROEND_NOOP_STATEMENT

#ifdef ITK_FUTURE_LEGACY_REMOVE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class amoebaTestF2 : public itk::SingleValuedCostFunction
using Pointer = itk::SmartPointer<Self>;
using ConstPointer = itk::SmartPointer<const Self>;
itkNewMacro(Self);
itkOverrideGetNameOfClassMacro(amoebaTestF1);
itkOverrideGetNameOfClassMacro(amoebaTestF2);

using ParametersType = Superclass::ParametersType;
using MeasureType = Superclass::MeasureType;
Expand Down
2 changes: 1 addition & 1 deletion Modules/Numerics/Optimizers/test/itkLBFGSOptimizerTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class LBFGSCostFunction : public itk::SingleValuedCostFunction
using Pointer = itk::SmartPointer<Self>;
using ConstPointer = itk::SmartPointer<const Self>;
itkNewMacro(Self);
itkOverrideGetNameOfClassMacro(LBFCostFunction);
itkOverrideGetNameOfClassMacro(LBFGSCostFunction);

enum
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class ITK_TEMPLATE_EXPORT BinaryImageToLevelSetImageAdaptor<TInputImage, LevelSe
itkNewMacro(Self);

/** Run-time type information */
itkOverrideGetNameOfClassMacro(BinaryImageToLevelSetImageAdaptorBase);
itkOverrideGetNameOfClassMacro(BinaryImageToLevelSetImageAdaptor);

using InputImageType = TInputImage;
using InputImagePixelType = typename InputImageType::PixelType;
Expand Down