Skip to content

Commit bef82a3

Browse files
committed
Add STATIC_ASSERT_INCOMPLETE_CLASS to enforce include minimality.
Add enforcments against `Dictionary` for `ustring.h` and two for `Dictionary` and `String` from `array.h`.
1 parent 6f2ab52 commit bef82a3

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

core/string/ustring.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
#include "ustring.h"
3232

33+
STATIC_ASSERT_INCOMPLETE_CLASS(Dictionary);
34+
3335
#include "core/crypto/crypto_core.h"
3436
#include "core/math/color.h"
3537
#include "core/math/math_funcs.h"

core/typedefs.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,3 +440,23 @@ inline constexpr bool is_zero_constructible_v = is_zero_constructible<T>::value;
440440
#define GODOT_MSVC_WARNING_POP
441441
#define GODOT_MSVC_WARNING_PUSH_AND_IGNORE(m_warning)
442442
#endif
443+
444+
template <typename T, typename = void>
445+
struct is_incomplete_type : std::true_type {};
446+
447+
template <typename T>
448+
struct is_incomplete_type<T, std::void_t<decltype(sizeof(T))>> : std::false_type {};
449+
450+
template <typename T>
451+
constexpr bool is_incomplete_type_v = is_incomplete_type<T>::value;
452+
453+
#ifndef SCU_BUILD
454+
/// Enforces the requirement that a class is not fully defined.
455+
/// This can be used to reduce include coupling and keep compile times low.
456+
/// The check must be made at the top of the corresponding .cpp file of a header.
457+
#define STATIC_ASSERT_INCOMPLETE_CLASS(m_type) \
458+
class m_type; \
459+
static_assert(is_incomplete_type_v<m_type>, #m_type " was fully defined when it should not be. Please check include hierarchy of " __FILE__);
460+
#else
461+
#define STATIC_ASSERT_INCOMPLETE_CLASS(m_type)
462+
#endif

core/variant/array.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030

3131
#include "array.h"
3232

33+
STATIC_ASSERT_INCOMPLETE_CLASS(Dictionary);
34+
STATIC_ASSERT_INCOMPLETE_CLASS(String);
35+
3336
#include "container_type_validate.h"
3437
#include "core/math/math_funcs.h"
3538
#include "core/object/script_language.h"

methods.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def add_source_files_scu(self, sources, files, allow_gen=False):
6969

7070
# Add all the gen.cpp files in the SCU directory
7171
add_source_files_orig(self, sources, subdir + ".scu/scu_*.gen.cpp", True)
72+
self.Append(CPPDEFINES=["SCU_BUILD"])
7273
return True
7374
return False
7475

0 commit comments

Comments
 (0)