Skip to content
Open
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
89 changes: 28 additions & 61 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -656,16 +656,16 @@ cc_version_metadata1 = cc_version["metadata1"]

if cc_version_major == -1:
print_warning(
"Couldn't detect compiler version, skipping version checks. "
"Build may fail if the compiler doesn't support C++17 fully."
"Couldn't detect compiler version, skipping version checks. Build may "
"fail if the compiler doesn't support C++20 fully."
)
elif methods.using_gcc(env):
if cc_version_major < 9:
if cc_version_major < 11:
print_error(
"Detected GCC version older than 9, which does not fully support "
"C++17, or has bugs when compiling Godot. Supported versions are 9 "
"and later. Use a newer GCC version, or Clang 6 or later by passing "
'"use_llvm=yes" to the SCons command line.'
"Detected GCC version older than 11, which does not fully support "
"C++20. Supported versions are GCC 11 and later. Use a newer GCC "
'version, or Clang 13 or later by passing "use_llvm=yes" to the '
"SCons command line."
)
Exit(255)
elif cc_version_metadata1 == "win32":
Expand All @@ -680,47 +680,31 @@ elif methods.using_clang(env):
# Apple LLVM versions differ from upstream LLVM version \o/, compare
# in https://en.wikipedia.org/wiki/Xcode#Toolchain_versions
if methods.is_apple_clang(env):
if cc_version_major < 10:
if cc_version_major < 15:
print_error(
"Detected Apple Clang version older than 10, which does not fully "
"support C++17. Supported versions are Apple Clang 10 and later."
"Detected Apple Clang version older than 15, which does not fully "
"support C++20. Supported versions are Apple Clang 15 and later."
)
Exit(255)
elif env["debug_paths_relative"] and cc_version_major < 12:
print_warning(
"Apple Clang < 12 doesn't support -ffile-prefix-map, disabling `debug_paths_relative` option."
)
env["debug_paths_relative"] = False
else:
if cc_version_major < 6:
if cc_version_major < 13:
print_error(
"Detected Clang version older than 6, which does not fully support "
"C++17. Supported versions are Clang 6 and later."
"Detected Clang version older than 13, which does not fully support "
"C++20. Supported versions are Clang 13 and later."
)
Exit(255)
elif env["debug_paths_relative"] and cc_version_major < 10:
print_warning("Clang < 10 doesn't support -ffile-prefix-map, disabling `debug_paths_relative` option.")
env["debug_paths_relative"] = False

elif env.msvc:
# Ensure latest minor builds of Visual Studio 2017/2019.
# https://github.com/godotengine/godot/pull/94995#issuecomment-2336464574
if cc_version_major == 16 and cc_version_minor < 11:
print_error(
"Detected Visual Studio 2019 version older than 16.11, which has bugs "
"when compiling Godot. Use a newer VS2019 version, or VS2022."
)
Exit(255)
if cc_version_major == 15 and cc_version_minor < 9:
if cc_version_major < 16:
print_error(
"Detected Visual Studio 2017 version older than 15.9, which has bugs "
"when compiling Godot. Use a newer VS2017 version, or VS2019/VS2022."
"Detected Visual Studio version older than 2019, which does not fully "
"support C++20. Supported versions are Visual Studio 2019 and later."
)
Exit(255)
if cc_version_major < 15:
elif cc_version_major == 16 and cc_version_minor < 11:
print_error(
"Detected Visual Studio 2015 or earlier, which is unsupported in Godot. "
"Supported versions are Visual Studio 2017 and later."
"Detected Visual Studio 2019 version older than 16.11, which does not "
"fully support C++20. Use a newer VS2019 version, or VS2022."
)
Exit(255)

Expand Down Expand Up @@ -831,22 +815,17 @@ if env["lto"] != "none":
print("Using LTO: " + env["lto"])

# Set our C and C++ standard requirements.
# C++17 is required as we need guaranteed copy elision as per GH-36436.
# Prepending to make it possible to override.
# This needs to come after `configure`, otherwise we don't have env.msvc.
if not env.msvc:
# Specifying GNU extensions support explicitly, which are supported by
# both GCC and Clang. Both currently default to gnu17 and gnu++17.
# both GCC and Clang. Both currently default to gnu17 and gnu++20.
env.Prepend(CFLAGS=["-std=gnu17"])
env.Prepend(CXXFLAGS=["-std=gnu++17"])
env.Prepend(CXXFLAGS=["-std=gnu++20"])
else:
# MSVC started offering C standard support with Visual Studio 2019 16.8, which covers all
# of our supported VS2019 & VS2022 versions; VS2017 will only pass the C++ standard.
env.Prepend(CXXFLAGS=["/std:c++17"])
if cc_version_major < 16:
print_warning("Visual Studio 2017 cannot specify a C-Standard.")
else:
env.Prepend(CFLAGS=["/std:c17"])
# of our supported VS2019 & VS2022 versions.
env.Prepend(CFLAGS=["/std:c17"])
env.Prepend(CXXFLAGS=["/std:c++20"])
# MSVC is non-conforming with the C++ standard by default, so we enable more conformance.
# Note that this is still not complete conformance, as certain Windows-related headers
# don't compile under complete conformance.
Expand Down Expand Up @@ -904,22 +883,15 @@ if env.msvc and not methods.using_clang(env): # MSVC
else: # GCC, Clang
common_warnings = []
if methods.using_gcc(env):
common_warnings += ["-Wshadow", "-Wno-misleading-indentation"]
if cc_version_major < 11:
# Regression in GCC 9/10, spams so much in our variadic templates
# that we need to outright disable it.
common_warnings += ["-Wno-type-limits"]
common_warnings += ["-Wshadow", "-Wno-misleading-indentation", "-Wenum-conversion"]
if cc_version_major == 12:
# Regression in GCC 12, false positives in our error macros, see GH-58747.
common_warnings += ["-Wno-return-type"]
if cc_version_major >= 11:
common_warnings += ["-Wenum-conversion"]
elif methods.using_clang(env) or methods.using_emcc(env):
common_warnings += ["-Wshadow-field-in-constructor", "-Wshadow-uncaptured-local"]
common_warnings += ["-Wshadow-field-in-constructor", "-Wshadow-uncaptured-local", "-Wenum-conversion"]
# We often implement `operator<` for structs of pointers as a requirement
# for putting them in `Set` or `Map`. We don't mind about unreliable ordering.
common_warnings += ["-Wno-ordered-compare-function-pointers"]
common_warnings += ["-Wenum-conversion"]

# clang-cl will interpret `-Wall` as `-Weverything`, workaround with compatibility cast.
env["WARNLEVEL"] = "-Wall" if not env.msvc else "-W3"
Expand All @@ -931,19 +903,14 @@ else: # GCC, Clang
env.AppendUnique(
CCFLAGS=[
"-Walloc-zero",
"-Wattribute-alias=2",
"-Wduplicated-branches",
"-Wduplicated-cond",
"-Wlogical-op",
"-Wstringop-overflow=4",
]
)
env.AppendUnique(CXXFLAGS=["-Wplacement-new=1", "-Wvirtual-inheritance"])
# Need to fix a warning with AudioServer lambdas before enabling.
# if cc_version_major != 9: # GCC 9 had a regression (GH-36325).
# env.Append(CXXFLAGS=["-Wnoexcept"])
if cc_version_major >= 9:
env.AppendUnique(CCFLAGS=["-Wattribute-alias=2"])
if cc_version_major >= 11: # Broke on MethodBind templates before GCC 11.
env.AppendUnique(CCFLAGS=["-Wlogical-op"])
elif methods.using_clang(env) or methods.using_emcc(env):
env.AppendUnique(CCFLAGS=["-Wimplicit-fallthrough"])
elif env["warnings"] == "all":
Expand Down
3 changes: 3 additions & 0 deletions core/io/ip_address.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ struct [[nodiscard]] IPAddress {
return false;
}

bool operator==(const String &p_ip) const { return operator==(IPAddress(p_ip)); }
bool operator!=(const String &p_ip) const { return operator!=(IPAddress(p_ip)); }

void clear();
bool is_wildcard() const { return wildcard; }
bool is_valid() const { return valid; }
Expand Down
7 changes: 7 additions & 0 deletions core/math/rect2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,10 @@ Rect2::operator String() const {
Rect2::operator Rect2i() const {
return Rect2i(position, size);
}

bool Rect2::operator==(const Rect2i &p_rect2i) const {
return operator==(Rect2(p_rect2i));
}
bool Rect2::operator!=(const Rect2i &p_rect2i) const {
return operator!=(Rect2(p_rect2i));
}
3 changes: 3 additions & 0 deletions core/math/rect2.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ struct [[nodiscard]] Rect2 {
constexpr bool operator==(const Rect2 &p_rect) const { return position == p_rect.position && size == p_rect.size; }
constexpr bool operator!=(const Rect2 &p_rect) const { return position != p_rect.position || size != p_rect.size; }

bool operator==(const Rect2i &p_rect2i) const;
bool operator!=(const Rect2i &p_rect2i) const;

inline Rect2 grow(real_t p_amount) const {
Rect2 g = *this;
g.grow_by(p_amount);
Expand Down
19 changes: 19 additions & 0 deletions core/math/vector2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,22 @@ Vector2::operator String() const {
Vector2::operator Vector2i() const {
return Vector2i(x, y);
}

bool Vector2::operator==(const Vector2i &p_vector2i) const {
return operator==(Vector2(p_vector2i));
}
bool Vector2::operator!=(const Vector2i &p_vector2i) const {
return operator!=(Vector2(p_vector2i));
}
bool Vector2::operator<(const Vector2i &p_vector2i) const {
return operator<(Vector2(p_vector2i));
}
bool Vector2::operator>(const Vector2i &p_vector2i) const {
return operator>(Vector2(p_vector2i));
}
bool Vector2::operator<=(const Vector2i &p_vector2i) const {
return operator<=(Vector2(p_vector2i));
}
bool Vector2::operator>=(const Vector2i &p_vector2i) const {
return operator>=(Vector2(p_vector2i));
}
7 changes: 7 additions & 0 deletions core/math/vector2.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ struct [[nodiscard]] Vector2 {
constexpr bool operator<=(const Vector2 &p_vec2) const { return x == p_vec2.x ? (y <= p_vec2.y) : (x < p_vec2.x); }
constexpr bool operator>=(const Vector2 &p_vec2) const { return x == p_vec2.x ? (y >= p_vec2.y) : (x > p_vec2.x); }

bool operator==(const Vector2i &p_vector2i) const;
bool operator!=(const Vector2i &p_vector2i) const;
bool operator<(const Vector2i &p_vector2i) const;
bool operator>(const Vector2i &p_vector2i) const;
bool operator<=(const Vector2i &p_vector2i) const;
bool operator>=(const Vector2i &p_vector2i) const;

real_t angle() const;
static Vector2 from_angle(real_t p_angle);

Expand Down
19 changes: 19 additions & 0 deletions core/math/vector3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,22 @@ Vector3::operator String() const {
Vector3::operator Vector3i() const {
return Vector3i(x, y, z);
}

bool Vector3::operator==(const Vector3i &p_vector3i) const {
return operator==(Vector3(p_vector3i));
}
bool Vector3::operator!=(const Vector3i &p_vector3i) const {
return operator!=(Vector3(p_vector3i));
}
bool Vector3::operator<(const Vector3i &p_vector3i) const {
return operator<(Vector3(p_vector3i));
}
bool Vector3::operator>(const Vector3i &p_vector3i) const {
return operator>(Vector3(p_vector3i));
}
bool Vector3::operator<=(const Vector3i &p_vector3i) const {
return operator<=(Vector3(p_vector3i));
}
bool Vector3::operator>=(const Vector3i &p_vector3i) const {
return operator>=(Vector3(p_vector3i));
}
7 changes: 7 additions & 0 deletions core/math/vector3.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ struct [[nodiscard]] Vector3 {
constexpr bool operator>(const Vector3 &p_v) const;
constexpr bool operator>=(const Vector3 &p_v) const;

bool operator==(const Vector3i &p_vector3i) const;
bool operator!=(const Vector3i &p_vector3i) const;
bool operator<(const Vector3i &p_vector3i) const;
bool operator>(const Vector3i &p_vector3i) const;
bool operator<=(const Vector3i &p_vector3i) const;
bool operator>=(const Vector3i &p_vector3i) const;

explicit operator String() const;
operator Vector3i() const;

Expand Down
19 changes: 19 additions & 0 deletions core/math/vector4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,22 @@ static_assert(sizeof(Vector4) == 4 * sizeof(real_t));
Vector4::operator Vector4i() const {
return Vector4i(x, y, z, w);
}

bool Vector4::operator==(const Vector4i &p_vector4i) const {
return operator==(Vector4(p_vector4i));
}
bool Vector4::operator!=(const Vector4i &p_vector4i) const {
return operator!=(Vector4(p_vector4i));
}
bool Vector4::operator<(const Vector4i &p_vector4i) const {
return operator<(Vector4(p_vector4i));
}
bool Vector4::operator>(const Vector4i &p_vector4i) const {
return operator>(Vector4(p_vector4i));
}
bool Vector4::operator<=(const Vector4i &p_vector4i) const {
return operator<=(Vector4(p_vector4i));
}
bool Vector4::operator>=(const Vector4i &p_vector4i) const {
return operator>=(Vector4(p_vector4i));
}
7 changes: 7 additions & 0 deletions core/math/vector4.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ struct [[nodiscard]] Vector4 {
constexpr bool operator>=(const Vector4 &p_vec4) const;
constexpr bool operator<=(const Vector4 &p_vec4) const;

bool operator==(const Vector4i &p_vector4i) const;
bool operator!=(const Vector4i &p_vector4i) const;
bool operator<(const Vector4i &p_vector4i) const;
bool operator>(const Vector4i &p_vector4i) const;
bool operator<=(const Vector4i &p_vector4i) const;
bool operator>=(const Vector4i &p_vector4i) const;

explicit operator String() const;
operator Vector4i() const;

Expand Down
21 changes: 13 additions & 8 deletions core/object/ref_counted.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ class Ref {
return T::get_class_static();
}

_FORCE_INLINE_ bool operator==(const T *p_ptr) const {
template <typename T_Other>
_FORCE_INLINE_ bool operator==(const T_Other *p_ptr) const {
return reference == p_ptr;
}
_FORCE_INLINE_ bool operator!=(const T *p_ptr) const {
template <typename T_Other>
_FORCE_INLINE_ bool operator!=(const T_Other *p_ptr) const {
return reference != p_ptr;
}
#ifdef STRICT_CHECKS
Expand All @@ -103,14 +105,17 @@ class Ref {
bool operator!=(std::nullptr_t) const = delete;
#endif // STRICT_CHECKS

_FORCE_INLINE_ bool operator<(const Ref<T> &p_r) const {
return reference < p_r.reference;
template <typename T_Other>
_FORCE_INLINE_ bool operator<(const Ref<T_Other> &p_ref) const {
return reference < p_ref.ptr();
}
_FORCE_INLINE_ bool operator==(const Ref<T> &p_r) const {
return reference == p_r.reference;
template <typename T_Other>
_FORCE_INLINE_ bool operator==(const Ref<T_Other> &p_ref) const {
return reference == p_ref.ptr();
}
_FORCE_INLINE_ bool operator!=(const Ref<T> &p_r) const {
return reference != p_r.reference;
template <typename T_Other>
_FORCE_INLINE_ bool operator!=(const Ref<T_Other> &p_ref) const {
return reference != p_ref.ptr();
}

_FORCE_INLINE_ T *operator*() const {
Expand Down
2 changes: 1 addition & 1 deletion core/os/spin_lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static_assert(std::atomic_bool::is_always_lock_free);

class SpinLock {
union {
mutable std::atomic<bool> locked = ATOMIC_VAR_INIT(false);
mutable std::atomic<bool> locked = false;
char aligner[Thread::CACHE_LINE_BYTES];
};

Expand Down
3 changes: 3 additions & 0 deletions core/string/node_path.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class [[nodiscard]] NodePath {
bool operator!=(const NodePath &p_path) const;
void operator=(const NodePath &p_path);

bool operator==(const String &p_path) const { return operator==(NodePath(p_path)); }
bool operator!=(const String &p_path) const { return operator!=(NodePath(p_path)); }

void simplify();
NodePath simplified() const;

Expand Down
4 changes: 2 additions & 2 deletions core/typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@

// IWYU pragma: always_keep

// Ensure that C++ standard is at least C++17.
// Ensure that C++ standard is at least C++20.
// If on MSVC, also ensures that the `Zc:__cplusplus` flag is present.
static_assert(__cplusplus >= 201703L, "Minimum of C++17 required.");
static_assert(__cplusplus >= 202002L, "Minimum of C++20 required.");

// IWYU pragma: begin_exports

Expand Down
Loading