Skip to content

Commit 182875b

Browse files
committed
Core: Bump C++ Standard to C++20
1 parent d705613 commit 182875b

File tree

10 files changed

+64
-75
lines changed

10 files changed

+64
-75
lines changed

SConstruct

Lines changed: 28 additions & 63 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 13 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,31 @@ 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 < 13:
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 13, which does not fully support "
702+
"C++20. Supported versions are Clang 13 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:
715-
# Ensure latest minor builds of Visual Studio 2017/2019.
716-
# 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:
707+
if cc_version_major < 16:
724708
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."
709+
"Detected Visual Studio version older than 2019, which does not fully "
710+
"support C++20. Supported versions are Visual Studio 2019 and later."
727711
)
728712
Exit(255)
729-
if cc_version_major < 15:
713+
elif cc_version_major == 16 and cc_version_minor < 11:
730714
print_error(
731-
"Detected Visual Studio 2015 or earlier, which is unsupported in Godot. "
732-
"Supported versions are Visual Studio 2017 and later."
715+
"Detected Visual Studio 2019 version older than 16.11, which does not "
716+
"fully support C++20. Use a newer VS2019 version, or VS2022."
733717
)
734718
Exit(255)
735719

@@ -840,22 +824,17 @@ if env["lto"] != "none":
840824
print("Using LTO: " + env["lto"])
841825

842826
# 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.
845827
# This needs to come after `configure`, otherwise we don't have env.msvc.
846828
if not env.msvc:
847829
# Specifying GNU extensions support explicitly, which are supported by
848-
# both GCC and Clang. Both currently default to gnu17 and gnu++17.
830+
# both GCC and Clang. Both currently default to gnu17 and gnu++20.
849831
env.Prepend(CFLAGS=["-std=gnu17"])
850-
env.Prepend(CXXFLAGS=["-std=gnu++17"])
832+
env.Prepend(CXXFLAGS=["-std=gnu++20"])
851833
else:
852834
# 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"])
835+
# of our supported VS2019 & VS2022 versions.
836+
env.Prepend(CFLAGS=["/std:c17"])
837+
env.Prepend(CXXFLAGS=["/std:c++20"])
859838
# MSVC is non-conforming with the C++ standard by default, so we enable more conformance.
860839
# Note that this is still not complete conformance, as certain Windows-related headers
861840
# don't compile under complete conformance.
@@ -913,22 +892,15 @@ if env.msvc and not methods.using_clang(env): # MSVC
913892
else: # GCC, Clang
914893
common_warnings = []
915894
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"]
895+
common_warnings += ["-Wshadow", "-Wno-misleading-indentation", "-Wenum-conversion"]
921896
if cc_version_major == 12:
922897
# Regression in GCC 12, false positives in our error macros, see GH-58747.
923898
common_warnings += ["-Wno-return-type"]
924-
if cc_version_major >= 11:
925-
common_warnings += ["-Wenum-conversion"]
926899
elif methods.using_clang(env) or methods.using_emcc(env):
927-
common_warnings += ["-Wshadow-field-in-constructor", "-Wshadow-uncaptured-local"]
900+
common_warnings += ["-Wshadow-field-in-constructor", "-Wshadow-uncaptured-local", "-Wenum-conversion"]
928901
# We often implement `operator<` for structs of pointers as a requirement
929902
# for putting them in `Set` or `Map`. We don't mind about unreliable ordering.
930903
common_warnings += ["-Wno-ordered-compare-function-pointers"]
931-
common_warnings += ["-Wenum-conversion"]
932904

933905
# clang-cl will interpret `-Wall` as `-Weverything`, workaround with compatibility cast.
934906
env["WARNLEVEL"] = "-Wall" if not env.msvc else "-W3"
@@ -940,19 +912,14 @@ else: # GCC, Clang
940912
env.AppendUnique(
941913
CCFLAGS=[
942914
"-Walloc-zero",
915+
"-Wattribute-alias=2",
943916
"-Wduplicated-branches",
944917
"-Wduplicated-cond",
918+
"-Wlogical-op",
945919
"-Wstringop-overflow=4",
946920
]
947921
)
948922
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"])
956923
elif methods.using_clang(env) or methods.using_emcc(env):
957924
env.AppendUnique(CCFLAGS=["-Wimplicit-fallthrough"])
958925
elif env["warnings"] == "all":
@@ -968,8 +935,6 @@ else: # GCC, Clang
968935
# Configure external includes.
969936
if env.msvc:
970937
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"])
973938
env.AppendUnique(CCFLAGS=["/external:anglebrackets"])
974939
env.AppendUnique(CCFLAGS=["/external:W0"])
975940
env["EXTINCPREFIX"] = "/external:I"

core/os/spin_lock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static_assert(std::atomic_bool::is_always_lock_free);
9393

9494
class SpinLock {
9595
union {
96-
mutable std::atomic<bool> locked = ATOMIC_VAR_INIT(false);
96+
mutable std::atomic<bool> locked = false;
9797
char aligner[Thread::CACHE_LINE_BYTES];
9898
};
9999

core/typedefs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636

3737
// IWYU pragma: always_keep
3838

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

4343
// IWYU pragma: begin_exports
4444

drivers/metal/SCsub

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ env_thirdparty.disable_warnings()
3333
env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources)
3434
env_metal.drivers_sources += thirdparty_obj
3535

36-
# Enable C++20 for the Objective-C++ Metal code, which uses C++20 concepts.
37-
if "-std=gnu++17" in env_metal["CXXFLAGS"]:
38-
env_metal["CXXFLAGS"].remove("-std=gnu++17")
39-
env_metal.Append(CXXFLAGS=["-std=gnu++20"])
40-
4136
# Enable module support
4237
env_metal.Append(CCFLAGS=["-fmodules", "-fcxx-modules"])
4338

modules/mono/mono_gc_handle.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ struct GCHandleIntPtr {
4848
_FORCE_INLINE_ bool operator==(const GCHandleIntPtr &p_other) { return value == p_other.value; }
4949
_FORCE_INLINE_ bool operator!=(const GCHandleIntPtr &p_other) { return value != p_other.value; }
5050

51+
// FIXME: C++20 doesn't allow aggregate initializers to bypass deleted constructors.
52+
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1008r1.pdf
53+
#if 0
5154
GCHandleIntPtr() = delete;
55+
#endif
5256
};
5357
}
5458

thirdparty/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,7 @@ Patches:
10431043

10441044
- `0001-revert-tvglines-bezier-precision.patch` (GH-96658)
10451045
- `0002-use-heap-alloc.patch` (GH-109530)
1046+
- `0003-cpp20-explicit-namespace.patch` (GH-100749)
10461047

10471048

10481049
## tinyexr
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
diff --git a/thirdparty/thorvg/src/loaders/svg/tvgSvgSceneBuilder.cpp b/thirdparty/thorvg/src/loaders/svg/tvgSvgSceneBuilder.cpp
2+
index 175739250a..5c2b36d394 100644
3+
--- a/thirdparty/thorvg/src/loaders/svg/tvgSvgSceneBuilder.cpp
4+
+++ b/thirdparty/thorvg/src/loaders/svg/tvgSvgSceneBuilder.cpp
5+
@@ -218 +218 @@ static bool _appendClipUseNode(SvgLoaderData& loaderData, SvgNode* node, Shape*
6+
- return _appendClipShape(loaderData, child, shape, vBox, svgPath, identity((const Matrix*)(&finalTransform)) ? nullptr : &finalTransform);
7+
+ return _appendClipShape(loaderData, child, shape, vBox, svgPath, tvg::identity((const Matrix*)(&finalTransform)) ? nullptr : &finalTransform);
8+
diff --git a/thirdparty/thorvg/src/renderer/sw_engine/tvgSwFill.cpp b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwFill.cpp
9+
index e012465b70..380e547dcf 100644
10+
--- a/thirdparty/thorvg/src/renderer/sw_engine/tvgSwFill.cpp
11+
+++ b/thirdparty/thorvg/src/renderer/sw_engine/tvgSwFill.cpp
12+
@@ -231 +231 @@ bool _prepareLinear(SwFill* fill, const LinearGradient* linear, const Matrix& tr
13+
- bool isTransformation = !identity((const Matrix*)(&gradTransform));
14+
+ bool isTransformation = !tvg::identity((const Matrix*)(&gradTransform));
15+
@@ -298 +298 @@ bool _prepareRadial(SwFill* fill, const RadialGradient* radial, const Matrix& tr
16+
- bool isTransformation = !identity((const Matrix*)(&gradTransform));
17+
+ bool isTransformation = !tvg::identity((const Matrix*)(&gradTransform));
18+
diff --git a/thirdparty/thorvg/src/renderer/tvgPaint.cpp b/thirdparty/thorvg/src/renderer/tvgPaint.cpp
19+
index e00c2c1954..873e65527b 100644
20+
--- a/thirdparty/thorvg/src/renderer/tvgPaint.cpp
21+
+++ b/thirdparty/thorvg/src/renderer/tvgPaint.cpp
22+
@@ -316 +316 @@ bool Paint::Impl::bounds(float* x, float* y, float* w, float* h, bool transforme
23+
- if (!transformed || identity(&m)) {
24+
+ if (!transformed || tvg::identity(&m)) {

thirdparty/thorvg/src/loaders/svg/tvgSvgSceneBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ static bool _appendClipUseNode(SvgLoaderData& loaderData, SvgNode* node, Shape*
215215
}
216216
if (child->transform) finalTransform *= *child->transform;
217217

218-
return _appendClipShape(loaderData, child, shape, vBox, svgPath, identity((const Matrix*)(&finalTransform)) ? nullptr : &finalTransform);
218+
return _appendClipShape(loaderData, child, shape, vBox, svgPath, tvg::identity((const Matrix*)(&finalTransform)) ? nullptr : &finalTransform);
219219
}
220220

221221

thirdparty/thorvg/src/renderer/sw_engine/tvgSwFill.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ bool _prepareLinear(SwFill* fill, const LinearGradient* linear, const Matrix& tr
228228
fill->linear.offset = -fill->linear.dx * x1 - fill->linear.dy * y1;
229229

230230
auto gradTransform = linear->transform();
231-
bool isTransformation = !identity((const Matrix*)(&gradTransform));
231+
bool isTransformation = !tvg::identity((const Matrix*)(&gradTransform));
232232

233233
if (isTransformation) {
234234
gradTransform = transform * gradTransform;
@@ -295,7 +295,7 @@ bool _prepareRadial(SwFill* fill, const RadialGradient* radial, const Matrix& tr
295295
if (fill->radial.a > 0) fill->radial.invA = 1.0f / fill->radial.a;
296296

297297
auto gradTransform = radial->transform();
298-
bool isTransformation = !identity((const Matrix*)(&gradTransform));
298+
bool isTransformation = !tvg::identity((const Matrix*)(&gradTransform));
299299

300300
if (isTransformation) gradTransform = transform * gradTransform;
301301
else {

thirdparty/thorvg/src/renderer/tvgPaint.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ bool Paint::Impl::bounds(float* x, float* y, float* w, float* h, bool transforme
316316
const auto& m = this->transform(origin);
317317

318318
//Case: No transformed, quick return!
319-
if (!transformed || identity(&m)) {
319+
if (!transformed || tvg::identity(&m)) {
320320
PAINT_METHOD(ret, bounds(x, y, w, h, stroking));
321321
return ret;
322322
}

0 commit comments

Comments
 (0)