Skip to content

Commit aedd081

Browse files
committed
Core: Bump C++ Standard to C++20
1 parent ec7d25d commit aedd081

File tree

23 files changed

+239
-81
lines changed

23 files changed

+239
-81
lines changed

SConstruct

Lines changed: 28 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -656,16 +656,16 @@ cc_version_metadata1 = cc_version["metadata1"]
656656

657657
if cc_version_major == -1:
658658
print_warning(
659-
"Couldn't detect compiler version, skipping version checks. "
660-
"Build may fail if the compiler doesn't support C++17 fully."
659+
"Couldn't detect compiler version, skipping version checks. Build may "
660+
"fail if the compiler doesn't support C++20 fully."
661661
)
662662
elif methods.using_gcc(env):
663-
if cc_version_major < 9:
663+
if cc_version_major < 11:
664664
print_error(
665-
"Detected GCC version older than 9, which does not fully support "
666-
"C++17, or has bugs when compiling Godot. Supported versions are 9 "
667-
"and later. Use a newer GCC version, or Clang 6 or later by passing "
668-
'"use_llvm=yes" to the SCons command line.'
665+
"Detected GCC version older than 11, which does not fully support "
666+
"C++20. Supported versions are GCC 11 and later. Use a newer GCC "
667+
'version, or Clang 13 or later by passing "use_llvm=yes" to the '
668+
"SCons command line."
669669
)
670670
Exit(255)
671671
elif cc_version_metadata1 == "win32":
@@ -680,47 +680,31 @@ elif methods.using_clang(env):
680680
# Apple LLVM versions differ from upstream LLVM version \o/, compare
681681
# in https://en.wikipedia.org/wiki/Xcode#Toolchain_versions
682682
if methods.is_apple_clang(env):
683-
if cc_version_major < 10:
683+
if cc_version_major < 15:
684684
print_error(
685-
"Detected Apple Clang version older than 10, which does not fully "
686-
"support C++17. Supported versions are Apple Clang 10 and later."
685+
"Detected Apple Clang version older than 15, which does not fully "
686+
"support C++20. Supported versions are Apple Clang 15 and later."
687687
)
688688
Exit(255)
689-
elif env["debug_paths_relative"] and cc_version_major < 12:
690-
print_warning(
691-
"Apple Clang < 12 doesn't support -ffile-prefix-map, disabling `debug_paths_relative` option."
692-
)
693-
env["debug_paths_relative"] = False
694689
else:
695-
if cc_version_major < 6:
690+
if cc_version_major < 13:
696691
print_error(
697-
"Detected Clang version older than 6, which does not fully support "
698-
"C++17. Supported versions are Clang 6 and later."
692+
"Detected Clang version older than 13, which does not fully support "
693+
"C++20. Supported versions are Clang 13 and later."
699694
)
700695
Exit(255)
701-
elif env["debug_paths_relative"] and cc_version_major < 10:
702-
print_warning("Clang < 10 doesn't support -ffile-prefix-map, disabling `debug_paths_relative` option.")
703-
env["debug_paths_relative"] = False
704696

705697
elif env.msvc:
706-
# Ensure latest minor builds of Visual Studio 2017/2019.
707-
# https://github.com/godotengine/godot/pull/94995#issuecomment-2336464574
708-
if cc_version_major == 16 and cc_version_minor < 11:
709-
print_error(
710-
"Detected Visual Studio 2019 version older than 16.11, which has bugs "
711-
"when compiling Godot. Use a newer VS2019 version, or VS2022."
712-
)
713-
Exit(255)
714-
if cc_version_major == 15 and cc_version_minor < 9:
698+
if cc_version_major < 16:
715699
print_error(
716-
"Detected Visual Studio 2017 version older than 15.9, which has bugs "
717-
"when compiling Godot. Use a newer VS2017 version, or VS2019/VS2022."
700+
"Detected Visual Studio version older than 2019, which does not fully "
701+
"support C++20. Supported versions are Visual Studio 2019 and later."
718702
)
719703
Exit(255)
720-
if cc_version_major < 15:
704+
elif cc_version_major == 16 and cc_version_minor < 11:
721705
print_error(
722-
"Detected Visual Studio 2015 or earlier, which is unsupported in Godot. "
723-
"Supported versions are Visual Studio 2017 and later."
706+
"Detected Visual Studio 2019 version older than 16.11, which does not "
707+
"fully support C++20. Use a newer VS2019 version, or VS2022."
724708
)
725709
Exit(255)
726710

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

833817
# Set our C and C++ standard requirements.
834-
# C++17 is required as we need guaranteed copy elision as per GH-36436.
835-
# Prepending to make it possible to override.
836818
# This needs to come after `configure`, otherwise we don't have env.msvc.
837819
if not env.msvc:
838820
# Specifying GNU extensions support explicitly, which are supported by
839-
# both GCC and Clang. Both currently default to gnu17 and gnu++17.
821+
# both GCC and Clang. Both currently default to gnu17 and gnu++20.
840822
env.Prepend(CFLAGS=["-std=gnu17"])
841-
env.Prepend(CXXFLAGS=["-std=gnu++17"])
823+
env.Prepend(CXXFLAGS=["-std=gnu++20"])
842824
else:
843825
# MSVC started offering C standard support with Visual Studio 2019 16.8, which covers all
844-
# of our supported VS2019 & VS2022 versions; VS2017 will only pass the C++ standard.
845-
env.Prepend(CXXFLAGS=["/std:c++17"])
846-
if cc_version_major < 16:
847-
print_warning("Visual Studio 2017 cannot specify a C-Standard.")
848-
else:
849-
env.Prepend(CFLAGS=["/std:c17"])
826+
# of our supported VS2019 & VS2022 versions.
827+
env.Prepend(CFLAGS=["/std:c17"])
828+
env.Prepend(CXXFLAGS=["/std:c++20"])
850829
# MSVC is non-conforming with the C++ standard by default, so we enable more conformance.
851830
# Note that this is still not complete conformance, as certain Windows-related headers
852831
# don't compile under complete conformance.
@@ -904,22 +883,15 @@ if env.msvc and not methods.using_clang(env): # MSVC
904883
else: # GCC, Clang
905884
common_warnings = []
906885
if methods.using_gcc(env):
907-
common_warnings += ["-Wshadow", "-Wno-misleading-indentation"]
908-
if cc_version_major < 11:
909-
# Regression in GCC 9/10, spams so much in our variadic templates
910-
# that we need to outright disable it.
911-
common_warnings += ["-Wno-type-limits"]
886+
common_warnings += ["-Wshadow", "-Wno-misleading-indentation", "-Wenum-conversion"]
912887
if cc_version_major == 12:
913888
# Regression in GCC 12, false positives in our error macros, see GH-58747.
914889
common_warnings += ["-Wno-return-type"]
915-
if cc_version_major >= 11:
916-
common_warnings += ["-Wenum-conversion"]
917890
elif methods.using_clang(env) or methods.using_emcc(env):
918-
common_warnings += ["-Wshadow-field-in-constructor", "-Wshadow-uncaptured-local"]
891+
common_warnings += ["-Wshadow-field-in-constructor", "-Wshadow-uncaptured-local", "-Wenum-conversion"]
919892
# We often implement `operator<` for structs of pointers as a requirement
920893
# for putting them in `Set` or `Map`. We don't mind about unreliable ordering.
921894
common_warnings += ["-Wno-ordered-compare-function-pointers"]
922-
common_warnings += ["-Wenum-conversion"]
923895

924896
# clang-cl will interpret `-Wall` as `-Weverything`, workaround with compatibility cast.
925897
env["WARNLEVEL"] = "-Wall" if not env.msvc else "-W3"
@@ -931,19 +903,14 @@ else: # GCC, Clang
931903
env.AppendUnique(
932904
CCFLAGS=[
933905
"-Walloc-zero",
906+
"-Wattribute-alias=2",
934907
"-Wduplicated-branches",
935908
"-Wduplicated-cond",
909+
"-Wlogical-op",
936910
"-Wstringop-overflow=4",
937911
]
938912
)
939913
env.AppendUnique(CXXFLAGS=["-Wplacement-new=1", "-Wvirtual-inheritance"])
940-
# Need to fix a warning with AudioServer lambdas before enabling.
941-
# if cc_version_major != 9: # GCC 9 had a regression (GH-36325).
942-
# env.Append(CXXFLAGS=["-Wnoexcept"])
943-
if cc_version_major >= 9:
944-
env.AppendUnique(CCFLAGS=["-Wattribute-alias=2"])
945-
if cc_version_major >= 11: # Broke on MethodBind templates before GCC 11.
946-
env.AppendUnique(CCFLAGS=["-Wlogical-op"])
947914
elif methods.using_clang(env) or methods.using_emcc(env):
948915
env.AppendUnique(CCFLAGS=["-Wimplicit-fallthrough"])
949916
elif env["warnings"] == "all":

core/io/ip_address.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ struct [[nodiscard]] IPAddress {
7979
return false;
8080
}
8181

82+
bool operator==(const String &p_ip) const { return operator==(IPAddress(p_ip)); }
83+
bool operator!=(const String &p_ip) const { return operator!=(IPAddress(p_ip)); }
84+
8285
void clear();
8386
bool is_wildcard() const { return wildcard; }
8487
bool is_valid() const { return valid; }

core/math/rect2.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,10 @@ Rect2::operator String() const {
293293
Rect2::operator Rect2i() const {
294294
return Rect2i(position, size);
295295
}
296+
297+
bool Rect2::operator==(const Rect2i &p_rect2i) const {
298+
return operator==(Rect2(p_rect2i));
299+
}
300+
bool Rect2::operator!=(const Rect2i &p_rect2i) const {
301+
return operator!=(Rect2(p_rect2i));
302+
}

core/math/rect2.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ struct [[nodiscard]] Rect2 {
209209
constexpr bool operator==(const Rect2 &p_rect) const { return position == p_rect.position && size == p_rect.size; }
210210
constexpr bool operator!=(const Rect2 &p_rect) const { return position != p_rect.position || size != p_rect.size; }
211211

212+
bool operator==(const Rect2i &p_rect2i) const;
213+
bool operator!=(const Rect2i &p_rect2i) const;
214+
212215
inline Rect2 grow(real_t p_amount) const {
213216
Rect2 g = *this;
214217
g.grow_by(p_amount);

core/math/vector2.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,22 @@ Vector2::operator String() const {
213213
Vector2::operator Vector2i() const {
214214
return Vector2i(x, y);
215215
}
216+
217+
bool Vector2::operator==(const Vector2i &p_vector2i) const {
218+
return operator==(Vector2(p_vector2i));
219+
}
220+
bool Vector2::operator!=(const Vector2i &p_vector2i) const {
221+
return operator!=(Vector2(p_vector2i));
222+
}
223+
bool Vector2::operator<(const Vector2i &p_vector2i) const {
224+
return operator<(Vector2(p_vector2i));
225+
}
226+
bool Vector2::operator>(const Vector2i &p_vector2i) const {
227+
return operator>(Vector2(p_vector2i));
228+
}
229+
bool Vector2::operator<=(const Vector2i &p_vector2i) const {
230+
return operator<=(Vector2(p_vector2i));
231+
}
232+
bool Vector2::operator>=(const Vector2i &p_vector2i) const {
233+
return operator>=(Vector2(p_vector2i));
234+
}

core/math/vector2.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,13 @@ struct [[nodiscard]] Vector2 {
166166
constexpr bool operator<=(const Vector2 &p_vec2) const { return x == p_vec2.x ? (y <= p_vec2.y) : (x < p_vec2.x); }
167167
constexpr bool operator>=(const Vector2 &p_vec2) const { return x == p_vec2.x ? (y >= p_vec2.y) : (x > p_vec2.x); }
168168

169+
bool operator==(const Vector2i &p_vector2i) const;
170+
bool operator!=(const Vector2i &p_vector2i) const;
171+
bool operator<(const Vector2i &p_vector2i) const;
172+
bool operator>(const Vector2i &p_vector2i) const;
173+
bool operator<=(const Vector2i &p_vector2i) const;
174+
bool operator>=(const Vector2i &p_vector2i) const;
175+
169176
real_t angle() const;
170177
static Vector2 from_angle(real_t p_angle);
171178

core/math/vector3.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,22 @@ Vector3::operator String() const {
161161
Vector3::operator Vector3i() const {
162162
return Vector3i(x, y, z);
163163
}
164+
165+
bool Vector3::operator==(const Vector3i &p_vector3i) const {
166+
return operator==(Vector3(p_vector3i));
167+
}
168+
bool Vector3::operator!=(const Vector3i &p_vector3i) const {
169+
return operator!=(Vector3(p_vector3i));
170+
}
171+
bool Vector3::operator<(const Vector3i &p_vector3i) const {
172+
return operator<(Vector3(p_vector3i));
173+
}
174+
bool Vector3::operator>(const Vector3i &p_vector3i) const {
175+
return operator>(Vector3(p_vector3i));
176+
}
177+
bool Vector3::operator<=(const Vector3i &p_vector3i) const {
178+
return operator<=(Vector3(p_vector3i));
179+
}
180+
bool Vector3::operator>=(const Vector3i &p_vector3i) const {
181+
return operator>=(Vector3(p_vector3i));
182+
}

core/math/vector3.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,13 @@ struct [[nodiscard]] Vector3 {
211211
constexpr bool operator>(const Vector3 &p_v) const;
212212
constexpr bool operator>=(const Vector3 &p_v) const;
213213

214+
bool operator==(const Vector3i &p_vector3i) const;
215+
bool operator!=(const Vector3i &p_vector3i) const;
216+
bool operator<(const Vector3i &p_vector3i) const;
217+
bool operator>(const Vector3i &p_vector3i) const;
218+
bool operator<=(const Vector3i &p_vector3i) const;
219+
bool operator>=(const Vector3i &p_vector3i) const;
220+
214221
explicit operator String() const;
215222
operator Vector3i() const;
216223

core/math/vector4.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,22 @@ static_assert(sizeof(Vector4) == 4 * sizeof(real_t));
225225
Vector4::operator Vector4i() const {
226226
return Vector4i(x, y, z, w);
227227
}
228+
229+
bool Vector4::operator==(const Vector4i &p_vector4i) const {
230+
return operator==(Vector4(p_vector4i));
231+
}
232+
bool Vector4::operator!=(const Vector4i &p_vector4i) const {
233+
return operator!=(Vector4(p_vector4i));
234+
}
235+
bool Vector4::operator<(const Vector4i &p_vector4i) const {
236+
return operator<(Vector4(p_vector4i));
237+
}
238+
bool Vector4::operator>(const Vector4i &p_vector4i) const {
239+
return operator>(Vector4(p_vector4i));
240+
}
241+
bool Vector4::operator<=(const Vector4i &p_vector4i) const {
242+
return operator<=(Vector4(p_vector4i));
243+
}
244+
bool Vector4::operator>=(const Vector4i &p_vector4i) const {
245+
return operator>=(Vector4(p_vector4i));
246+
}

core/math/vector4.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ struct [[nodiscard]] Vector4 {
144144
constexpr bool operator>=(const Vector4 &p_vec4) const;
145145
constexpr bool operator<=(const Vector4 &p_vec4) const;
146146

147+
bool operator==(const Vector4i &p_vector4i) const;
148+
bool operator!=(const Vector4i &p_vector4i) const;
149+
bool operator<(const Vector4i &p_vector4i) const;
150+
bool operator>(const Vector4i &p_vector4i) const;
151+
bool operator<=(const Vector4i &p_vector4i) const;
152+
bool operator>=(const Vector4i &p_vector4i) const;
153+
147154
explicit operator String() const;
148155
operator Vector4i() const;
149156

0 commit comments

Comments
 (0)