Skip to content

Commit 2147cf4

Browse files
committed
Core: Bump C++ Standard to C++20
1 parent 2dd26a0 commit 2147cf4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+167
-412
lines changed

.github/workflows/linux_builds.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ env:
1111
GODOT_CPP_BRANCH: 4.4
1212
DOTNET_NOLOGO: true
1313
DOTNET_CLI_TELEMETRY_OPTOUT: true
14-
ASAN_OPTIONS: color=always:print_suppressions=1:suppressions=${{ github.workspace }}/misc/error_suppressions/asan.txt
14+
ASAN_OPTIONS: color=always:print_suppressions=1:suppressions=${{ github.workspace }}/misc/error_suppressions/asan.txt:alloc_dealloc_mismatch=0
1515
LSAN_OPTIONS: color=always:print_suppressions=1:suppressions=${{ github.workspace }}/misc/error_suppressions/lsan.txt
1616
TSAN_OPTIONS: color=always:print_suppressions=1:suppressions=${{ github.workspace }}/misc/error_suppressions/tsan.txt
1717
UBSAN_OPTIONS: color=always:print_suppressions=1:suppressions=${{ github.workspace }}/misc/error_suppressions/ubsan.txt
1818

1919
jobs:
2020
build-linux:
21-
# Stay one LTS before latest to increase portability of Linux artifacts.
22-
runs-on: ubuntu-22.04
21+
runs-on: ubuntu-24.04
2322
name: ${{ matrix.name }}
2423
timeout-minutes: 120
2524
strategy:

SConstruct

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

666666
if cc_version_major == -1:
667667
print_warning(
668-
"Couldn't detect compiler version, skipping version checks. "
669-
"Build may fail if the compiler doesn't support C++17 fully."
668+
"Couldn't detect compiler version, skipping version checks. Build may "
669+
"fail if the compiler doesn't support C++20 fully."
670670
)
671671
elif methods.using_gcc(env):
672-
if cc_version_major < 9:
672+
if cc_version_major < 11:
673673
print_error(
674-
"Detected GCC version older than 9, which does not fully support "
675-
"C++17, or has bugs when compiling Godot. Supported versions are 9 "
676-
"and later. Use a newer GCC version, or Clang 6 or later by passing "
677-
'"use_llvm=yes" to the SCons command line.'
674+
"Detected GCC version older than 11, which does not fully support "
675+
"C++20. Supported versions are GCC 11 and later. Use a newer GCC "
676+
'version, or Clang 16 or later by passing "use_llvm=yes" to the '
677+
"SCons command line."
678678
)
679679
Exit(255)
680680
elif cc_version_metadata1 == "win32":
@@ -689,47 +689,33 @@ elif methods.using_clang(env):
689689
# Apple LLVM versions differ from upstream LLVM version \o/, compare
690690
# in https://en.wikipedia.org/wiki/Xcode#Toolchain_versions
691691
if methods.is_apple_clang(env):
692-
if cc_version_major < 10:
692+
if cc_version_major < 15:
693693
print_error(
694-
"Detected Apple Clang version older than 10, which does not fully "
695-
"support C++17. Supported versions are Apple Clang 10 and later."
694+
"Detected Apple Clang version older than 15, which does not fully "
695+
"support C++20. Supported versions are Apple Clang 15 and later."
696696
)
697697
Exit(255)
698-
elif env["debug_paths_relative"] and cc_version_major < 12:
699-
print_warning(
700-
"Apple Clang < 12 doesn't support -ffile-prefix-map, disabling `debug_paths_relative` option."
701-
)
702-
env["debug_paths_relative"] = False
703698
else:
704-
if cc_version_major < 6:
699+
if cc_version_major < 16:
705700
print_error(
706-
"Detected Clang version older than 6, which does not fully support "
707-
"C++17. Supported versions are Clang 6 and later."
701+
"Detected Clang version older than 16, which does not fully support "
702+
"C++20. Supported versions are Clang 16 and later."
708703
)
709704
Exit(255)
710-
elif env["debug_paths_relative"] and cc_version_major < 10:
711-
print_warning("Clang < 10 doesn't support -ffile-prefix-map, disabling `debug_paths_relative` option.")
712-
env["debug_paths_relative"] = False
713705

714706
elif env.msvc:
715707
# Ensure latest minor builds of Visual Studio 2017/2019.
716708
# https://github.com/godotengine/godot/pull/94995#issuecomment-2336464574
717-
if cc_version_major == 16 and cc_version_minor < 11:
718-
print_error(
719-
"Detected Visual Studio 2019 version older than 16.11, which has bugs "
720-
"when compiling Godot. Use a newer VS2019 version, or VS2022."
721-
)
722-
Exit(255)
723-
if cc_version_major == 15 and cc_version_minor < 9:
709+
if cc_version_major < 16:
724710
print_error(
725-
"Detected Visual Studio 2017 version older than 15.9, which has bugs "
726-
"when compiling Godot. Use a newer VS2017 version, or VS2019/VS2022."
711+
"Detected Visual Studio version older than 2019, which does not fully "
712+
"support C++20. Supported versions are Visual Studio 2019 and later."
727713
)
728714
Exit(255)
729-
if cc_version_major < 15:
715+
elif cc_version_major == 16 and cc_version_minor < 11:
730716
print_error(
731-
"Detected Visual Studio 2015 or earlier, which is unsupported in Godot. "
732-
"Supported versions are Visual Studio 2017 and later."
717+
"Detected Visual Studio 2019 version older than 16.11, which has bugs "
718+
"when compiling Godot. Use a newer VS2019 version, or VS2022."
733719
)
734720
Exit(255)
735721

@@ -840,22 +826,17 @@ if env["lto"] != "none":
840826
print("Using LTO: " + env["lto"])
841827

842828
# Set our C and C++ standard requirements.
843-
# C++17 is required as we need guaranteed copy elision as per GH-36436.
844-
# Prepending to make it possible to override.
845829
# This needs to come after `configure`, otherwise we don't have env.msvc.
846830
if not env.msvc:
847831
# Specifying GNU extensions support explicitly, which are supported by
848-
# both GCC and Clang. Both currently default to gnu17 and gnu++17.
832+
# both GCC and Clang. Both currently default to gnu17 and gnu++20.
849833
env.Prepend(CFLAGS=["-std=gnu17"])
850-
env.Prepend(CXXFLAGS=["-std=gnu++17"])
834+
env.Prepend(CXXFLAGS=["-std=gnu++20"])
851835
else:
852836
# MSVC started offering C standard support with Visual Studio 2019 16.8, which covers all
853-
# of our supported VS2019 & VS2022 versions; VS2017 will only pass the C++ standard.
854-
env.Prepend(CXXFLAGS=["/std:c++17"])
855-
if cc_version_major < 16:
856-
print_warning("Visual Studio 2017 cannot specify a C-Standard.")
857-
else:
858-
env.Prepend(CFLAGS=["/std:c17"])
837+
# of our supported VS2019 & VS2022 versions.
838+
env.Prepend(CFLAGS=["/std:c17"])
839+
env.Prepend(CXXFLAGS=["/std:c++20"])
859840
# MSVC is non-conforming with the C++ standard by default, so we enable more conformance.
860841
# Note that this is still not complete conformance, as certain Windows-related headers
861842
# don't compile under complete conformance.
@@ -913,22 +894,15 @@ if env.msvc and not methods.using_clang(env): # MSVC
913894
else: # GCC, Clang
914895
common_warnings = []
915896
if methods.using_gcc(env):
916-
common_warnings += ["-Wshadow", "-Wno-misleading-indentation"]
917-
if cc_version_major < 11:
918-
# Regression in GCC 9/10, spams so much in our variadic templates
919-
# that we need to outright disable it.
920-
common_warnings += ["-Wno-type-limits"]
897+
common_warnings += ["-Wshadow", "-Wno-misleading-indentation", "-Wenum-conversion"]
921898
if cc_version_major == 12:
922899
# Regression in GCC 12, false positives in our error macros, see GH-58747.
923900
common_warnings += ["-Wno-return-type"]
924-
if cc_version_major >= 11:
925-
common_warnings += ["-Wenum-conversion"]
926901
elif methods.using_clang(env) or methods.using_emcc(env):
927-
common_warnings += ["-Wshadow-field-in-constructor", "-Wshadow-uncaptured-local"]
902+
common_warnings += ["-Wshadow-field-in-constructor", "-Wshadow-uncaptured-local", "-Wenum-conversion"]
928903
# We often implement `operator<` for structs of pointers as a requirement
929904
# for putting them in `Set` or `Map`. We don't mind about unreliable ordering.
930905
common_warnings += ["-Wno-ordered-compare-function-pointers"]
931-
common_warnings += ["-Wenum-conversion"]
932906

933907
# clang-cl will interpret `-Wall` as `-Weverything`, workaround with compatibility cast.
934908
env["WARNLEVEL"] = "-Wall" if not env.msvc else "-W3"
@@ -940,19 +914,14 @@ else: # GCC, Clang
940914
env.AppendUnique(
941915
CCFLAGS=[
942916
"-Walloc-zero",
917+
"-Wattribute-alias=2",
943918
"-Wduplicated-branches",
944919
"-Wduplicated-cond",
920+
"-Wlogical-op",
945921
"-Wstringop-overflow=4",
946922
]
947923
)
948924
env.AppendUnique(CXXFLAGS=["-Wplacement-new=1", "-Wvirtual-inheritance"])
949-
# Need to fix a warning with AudioServer lambdas before enabling.
950-
# if cc_version_major != 9: # GCC 9 had a regression (GH-36325).
951-
# env.Append(CXXFLAGS=["-Wnoexcept"])
952-
if cc_version_major >= 9:
953-
env.AppendUnique(CCFLAGS=["-Wattribute-alias=2"])
954-
if cc_version_major >= 11: # Broke on MethodBind templates before GCC 11.
955-
env.AppendUnique(CCFLAGS=["-Wlogical-op"])
956925
elif methods.using_clang(env) or methods.using_emcc(env):
957926
env.AppendUnique(CCFLAGS=["-Wimplicit-fallthrough"])
958927
elif env["warnings"] == "all":
@@ -968,8 +937,6 @@ else: # GCC, Clang
968937
# Configure external includes.
969938
if env.msvc:
970939
if not methods.using_clang(env):
971-
if cc_version_major < 16 or (cc_version_major == 16 and cc_version_minor < 10):
972-
env.AppendUnique(CCFLAGS=["/experimental:external"])
973940
env.AppendUnique(CCFLAGS=["/external:anglebrackets"])
974941
env.AppendUnique(CCFLAGS=["/external:W0"])
975942
env["EXTINCPREFIX"] = "/external:I"

core/io/ip_address.h

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,7 @@ struct [[nodiscard]] IPAddress {
6363
}
6464
return true;
6565
}
66-
67-
bool operator!=(const IPAddress &p_ip) const {
68-
if (p_ip.valid != valid) {
69-
return true;
70-
}
71-
if (!valid) {
72-
return true;
73-
}
74-
for (int i = 0; i < 4; i++) {
75-
if (field32[i] != p_ip.field32[i]) {
76-
return true;
77-
}
78-
}
79-
return false;
80-
}
66+
bool operator==(const String &p_ip) const { return operator==(IPAddress(p_ip)); }
8167

8268
void clear();
8369
bool is_wildcard() const { return wildcard; }

core/math/aabb.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ struct [[nodiscard]] AABB {
6161
constexpr bool operator==(const AABB &p_rval) const {
6262
return position == p_rval.position && size == p_rval.size;
6363
}
64-
constexpr bool operator!=(const AABB &p_rval) const {
65-
return position != p_rval.position || size != p_rval.size;
66-
}
6764

6865
bool is_equal_approx(const AABB &p_aabb) const;
6966
bool is_same(const AABB &p_aabb) const;

core/math/basis.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ struct [[nodiscard]] Basis {
124124
bool is_finite() const;
125125

126126
constexpr bool operator==(const Basis &p_matrix) const;
127-
constexpr bool operator!=(const Basis &p_matrix) const;
128127

129128
_FORCE_INLINE_ Vector3 xform(const Vector3 &p_vector) const;
130129
_FORCE_INLINE_ Vector3 xform_inv(const Vector3 &p_vector) const;
@@ -259,10 +258,6 @@ constexpr bool Basis::operator==(const Basis &p_matrix) const {
259258
return true;
260259
}
261260

262-
constexpr bool Basis::operator!=(const Basis &p_matrix) const {
263-
return (!(*this == p_matrix));
264-
}
265-
266261
_FORCE_INLINE_ void Basis::operator*=(const Basis &p_matrix) {
267262
set(
268263
p_matrix.tdotx(rows[0]), p_matrix.tdoty(rows[0]), p_matrix.tdotz(rows[0]),

core/math/bvh_abb.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ struct BVH_ABB {
5959
POINT neg_max;
6060

6161
bool operator==(const BVH_ABB &o) const { return (min == o.min) && (neg_max == o.neg_max); }
62-
bool operator!=(const BVH_ABB &o) const { return (*this == o) == false; }
6362

6463
void set(const POINT &_min, const POINT &_max) {
6564
min = _min;

core/math/bvh_tree.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ struct BVHHandle {
101101
void set_id(uint32_t p_id) { _data = p_id; }
102102

103103
bool operator==(const BVHHandle &p_h) const { return _data == p_h._data; }
104-
bool operator!=(const BVHHandle &p_h) const { return (*this == p_h) == false; }
105104
};
106105

107106
// helper class to make iterative versions of recursive functions

core/math/color.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ struct [[nodiscard]] Color {
7474
constexpr bool operator==(const Color &p_color) const {
7575
return (r == p_color.r && g == p_color.g && b == p_color.b && a == p_color.a);
7676
}
77-
constexpr bool operator!=(const Color &p_color) const {
78-
return (r != p_color.r || g != p_color.g || b != p_color.b || a != p_color.a);
79-
}
8077

8178
constexpr Color operator+(const Color &p_color) const;
8279
constexpr void operator+=(const Color &p_color);

core/math/convex_hull.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,6 @@ class ConvexHullInternal {
136136
return (x == b.x) && (y == b.y) && (z == b.z);
137137
}
138138

139-
bool operator!=(const Point32 &b) const {
140-
return (x != b.x) || (y != b.y) || (z != b.z);
141-
}
142-
143139
bool is_zero() {
144140
return (x == 0) && (y == 0) && (z == 0);
145141
}

core/math/plane.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ struct [[nodiscard]] Plane {
7777
bool is_finite() const;
7878

7979
constexpr bool operator==(const Plane &p_plane) const;
80-
constexpr bool operator!=(const Plane &p_plane) const;
8180
explicit operator String() const;
8281

8382
Plane() = default;
@@ -129,9 +128,5 @@ constexpr bool Plane::operator==(const Plane &p_plane) const {
129128
return normal == p_plane.normal && d == p_plane.d;
130129
}
131130

132-
constexpr bool Plane::operator!=(const Plane &p_plane) const {
133-
return normal != p_plane.normal || d != p_plane.d;
134-
}
135-
136131
template <>
137132
struct is_zero_constructible<Plane> : std::true_type {};

0 commit comments

Comments
 (0)