diff --git a/SConstruct b/SConstruct index 0d4f12e5046..d2a34358363 100644 --- a/SConstruct +++ b/SConstruct @@ -634,6 +634,7 @@ if env["strict_checks"]: # Run SCU file generation script if in a SCU build. if env["scu_build"]: + env.Append(CPPDEFINES=["SCU_BUILD_ENABLED"]) max_includes_per_scu = 8 if env.dev_build: max_includes_per_scu = 1024 diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index 11148f30ab1..9a1de524d54 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -30,6 +30,8 @@ #include "ustring.h" +STATIC_ASSERT_INCOMPLETE_TYPE(class, Dictionary); + #include "core/crypto/crypto_core.h" #include "core/math/color.h" #include "core/math/math_funcs.h" diff --git a/core/typedefs.h b/core/typedefs.h index 8a417bfb713..b537a313dc6 100644 --- a/core/typedefs.h +++ b/core/typedefs.h @@ -439,3 +439,23 @@ inline constexpr bool is_zero_constructible_v = is_zero_constructible::value; #define GODOT_MSVC_WARNING_POP #define GODOT_MSVC_WARNING_PUSH_AND_IGNORE(m_warning) #endif + +template +struct is_fully_defined : std::false_type {}; + +template +struct is_fully_defined> : std::true_type {}; + +template +constexpr bool is_fully_defined_v = is_fully_defined::value; + +#ifndef SCU_BUILD_ENABLED +/// Enforces the requirement that a class is not fully defined. +/// This can be used to reduce include coupling and keep compile times low. +/// The check must be made at the top of the corresponding .cpp file of a header. +#define STATIC_ASSERT_INCOMPLETE_TYPE(m_keyword, m_type) \ + m_keyword m_type; \ + static_assert(!is_fully_defined_v, #m_type " was unexpectedly fully defined. Please check the include hierarchy of '" __FILE__ "' and remove includes that resolve the " #m_keyword "."); +#else +#define STATIC_ASSERT_INCOMPLETE_TYPE(m_keyword, m_type) +#endif diff --git a/core/variant/array.cpp b/core/variant/array.cpp index bd84aaa6890..4d2fc175fd1 100644 --- a/core/variant/array.cpp +++ b/core/variant/array.cpp @@ -30,6 +30,9 @@ #include "array.h" +STATIC_ASSERT_INCOMPLETE_TYPE(class, Dictionary); +STATIC_ASSERT_INCOMPLETE_TYPE(class, String); + #include "container_type_validate.h" #include "core/math/math_funcs.h" #include "core/object/script_language.h"