diff --git a/Modules/Core/Common/include/itkIndent.h b/Modules/Core/Common/include/itkIndent.h index 9e3d058069a..eba89c5b060 100644 --- a/Modules/Core/Common/include/itkIndent.h +++ b/Modules/Core/Common/include/itkIndent.h @@ -28,7 +28,9 @@ #ifndef itkIndent_h #define itkIndent_h +// itkMacro.h includes itkPrintHelper.h, which includes this header: never include itkMacro.h here. #include "ITKCommonExport.h" +#include "itkConfigure.h" // ITK_LEGACY_REMOVE #include @@ -54,15 +56,18 @@ class ITKCommon_EXPORT Indent using Self = Indent; #ifndef ITK_LEGACY_REMOVE + // [[deprecated]] rather than itkLegacyMacro, which would require itkMacro.h. /** Method for creation. \deprecated Instead of calling `New()`, please simply create an indent by directly constructing the object. Indent is default-constructible, so it can be allocated on the stack. */ - itkLegacyMacro(static Self * New();) + [[deprecated]] static Self * + New(); /** Destroy this instance. \deprecated Instead of calling `Delete()`, please use the C++ pattern RAII ("Resource Acquisition Is Initialization"). */ - itkLegacyMacro(void Delete()) + [[deprecated]] void + Delete() { delete this; } @@ -94,4 +99,7 @@ class ITKCommon_EXPORT Indent }; } // end namespace itk +// Tested by itkPrintHelper.h to detect the include cycle described above. +#define itkIndent_h_complete + #endif diff --git a/Modules/Core/Common/include/itkPrintHelper.h b/Modules/Core/Common/include/itkPrintHelper.h index db244284c07..f9c8c0e6b11 100644 --- a/Modules/Core/Common/include/itkPrintHelper.h +++ b/Modules/Core/Common/include/itkPrintHelper.h @@ -21,6 +21,9 @@ #include "itkMacro.h" #include "itkIndent.h" +#ifndef itkIndent_h_complete +# error "itk::Indent incomplete: itkIndent.h must not include itkMacro.h (keep ITKCommonExport.h, itkConfigure.h)" +#endif #include #include diff --git a/Modules/Core/Common/test/itkPrintHelperGTest.cxx b/Modules/Core/Common/test/itkPrintHelperGTest.cxx index 8f4438b60fe..333cd4eb2a5 100644 --- a/Modules/Core/Common/test/itkPrintHelperGTest.cxx +++ b/Modules/Core/Common/test/itkPrintHelperGTest.cxx @@ -16,6 +16,8 @@ * *=========================================================================*/ +// itkIndent.h first on purpose: it must compile before itkMacro.h is seen (issue #7025). +#include "itkIndent.h" #include "itkPrintHelper.h" #include "itkOffset.h" #include "gtest/gtest.h"