commit 552f30ab626f8e58ecc2472df44c7b070815c577
parent 84f8b56d85d0e2b88f84896d55e0bea391ce54d9
Author: Emilio Cobos Álvarez <emilio@crisal.io>
Date: Wed, 12 Nov 2025 05:17:24 +0000
Bug 1768116 - Compile as C++20. r=glandium,webrtc-reviewers,mjf
Co-authored-by: Chris Peterson <cpeterson@mozilla.com>
Differential Revision: https://phabricator.services.mozilla.com/D271779
Diffstat:
9 files changed, 88 insertions(+), 59 deletions(-)
diff --git a/build/moz.configure/toolchain.configure b/build/moz.configure/toolchain.configure
@@ -653,15 +653,19 @@ def check_compiler(configure_cache, compiler, language, target, android_version)
flags.append("-Xclang")
flags.append("-std=gnu17")
- cxx17_version = 201703
- if info.language == "C++":
- if info.language_version != cxx17_version:
- # MSVC headers include C++17 features, but don't guard them
- # with appropriate checks.
- if info.type == "clang-cl":
- flags.append("-std:c++17")
- else:
- flags.append("-std=gnu++17")
+ cxx20_version = 202002
+ if info.language == "C++" and info.language_version != cxx20_version:
+ if info.type == "clang-cl":
+ flags.append("-std:c++20")
+ else:
+ flags.append("-std=gnu++20")
+
+ # gcc 10 defines C++20's __cplusplus as 201709L instead of 202002L.
+ # Redefine as C++20's final vesion for gcc 10 so modern C++20 code's
+ # __cplusplus version checks work as expected.
+ if info.type == "gcc" and info.version < Version("11.0.0"):
+ flags.append("-U__cplusplus")
+ flags.append("-D__cplusplus=202002L")
# Check compiler target
# --------------------------------------------------------------------
@@ -1322,7 +1326,7 @@ def sysroot(host_or_target, target_sysroot=None):
elif host_or_target.os == "iOS" and ios_sdk:
path = ios_sdk
if path:
- # Find the version of libstdc++ headears in the sysroot
+ # Find the version of libstdc++ headers in the sysroot
include = os.path.join(path, "usr/include/c++")
if os.path.isdir(include):
with os.scandir(include) as d:
diff --git a/build/moz.configure/warnings.configure b/build/moz.configure/warnings.configure
@@ -102,21 +102,18 @@ check_and_add_warning("-Wloop-analysis", min_clang_version="4.0.0")
# positives.
check_and_add_warning("-Wno-range-loop-analysis", min_clang_version="4.0.0")
-# Enable some C++20 compat warnings. We can remove these flags after we compile
-# as C++20 (bug 1768116), because they will be enabled by default:
-check_and_add_warning("-Wcomma-subscript", cxx_compiler, when=not_clang_based)
-check_and_add_warning("-Wenum-compare-conditional", min_clang_version="10.0.0")
-check_and_add_warning("-Wenum-float-conversion", min_clang_version="10.0.0")
-check_and_add_warning("-Wvolatile", cxx_compiler, when=not_clang)
-
+# Suppress some C++20 enum conversion warnings to be fixed later. These
+# warnings will become hard errors in C++26 and must be fixed before updating.
# Disable some C++20 errors to be fixed in bugs 1791958, 1791955, and 1775161.
check_and_add_warning(
- "-Wno-deprecated-anon-enum-enum-conversion",
+ "-Wno-deprecated-anon-enum-enum-conversion", # Bug 1791958
cxx_compiler,
min_clang_version="10.0.0",
)
check_and_add_warning(
- "-Wno-deprecated-enum-enum-conversion", cxx_compiler, min_clang_version="10.0.0"
+ "-Wno-deprecated-enum-enum-conversion", # Bug 1791955
+ cxx_compiler,
+ min_clang_version="10.0.0",
)
# Suppress C++20 warnings about implicit capture of `this` until they are fixed
# in bug 1775161. gcc doesn't have a -Wdeprecated-this-capture flag like clang,
diff --git a/docs/code-quality/coding-style/using_cxx_in_firefox_code.rst b/docs/code-quality/coding-style/using_cxx_in_firefox_code.rst
@@ -30,8 +30,9 @@ their size are valid values.
- As of Mozilla 59, C++14 mode is required to build Mozilla.
- As of Mozilla 67, MSVC can no longer be used to build Mozilla.
- As of Mozilla 73, C++17 mode is required to build Mozilla.
+- As of Mozilla 147, C++20 mode is required to build Mozilla.
-This means that C++17 can be used where supported on all platforms. The
+This means that C++20 can be used where supported on all platforms. The
list of acceptable features is given below:
.. list-table::
@@ -43,8 +44,8 @@ list of acceptable features is given below:
- Clang
-
* - Current minimal requirement
- - 10
- - 17
+ - 10.1
+ - 17.0
-
* - Feature
- GCC
diff --git a/dom/media/webrtc/third_party_build/gn-configs/webrtc.json b/dom/media/webrtc/third_party_build/gn-configs/webrtc.json
@@ -10,15 +10,7 @@
},
"FINAL_LIBRARY": "xul"
},
- "mozilla_flags": [
- "-fobjc-arc",
- "-mavx2",
- "-mfma",
- "-mfpu=neon",
- "-msse2",
- "-std=gnu++20",
- "-std:c++20"
- ],
+ "mozilla_flags": ["-fobjc-arc", "-mavx2", "-mfma", "-mfpu=neon", "-msse2"],
"write_mozbuild_variables": {
"INCLUDE_TK_CFLAGS_DIRS": [
"third_party/libwebrtc/modules/desktop_capture/desktop_capture_gn",
diff --git a/gfx/wr/swgl/build.rs b/gfx/wr/swgl/build.rs
@@ -202,12 +202,12 @@ fn main() {
if let Ok(tool) = build.try_get_compiler() {
if tool.is_like_msvc() {
build
- .flag("/std:c++17")
+ .flag("/std:c++20")
.flag("/EHs-")
.flag("/GR-");
} else {
build
- .flag("-std=c++17")
+ .flag("-std=c++20")
.flag("-fno-exceptions")
.flag("-fno-rtti")
.flag("-fno-math-errno");
diff --git a/js/src/build/js-config.in b/js/src/build/js-config.in
@@ -108,7 +108,7 @@ if test "$echo_libdir" = "yes"; then
fi
if test "$echo_cflags" = "yes"; then
- echo "-std=gnu++11 -isystem $includedir/$JS_LIBRARY_NAME $NSPR_CFLAGS"
+ echo "-std=gnu++20 -isystem $includedir/$JS_LIBRARY_NAME $NSPR_CFLAGS"
fi
if test "$echo_libs" = "yes"; then
diff --git a/python/mozbuild/mozbuild/test/configure/test_toolchain_configure.py b/python/mozbuild/mozbuild/test/configure/test_toolchain_configure.py
@@ -29,6 +29,8 @@ DEFAULT_CXX_14 = {"__cplusplus": "201402L"}
DEFAULT_CXX_17 = {"__cplusplus": "201703L"}
+DEFAULT_CXX_20 = {"__cplusplus": "202002L"}
+
SUPPORTS_GNU99 = {"-std=gnu99": DEFAULT_C99}
SUPPORTS_GNU17 = {"-std=gnu17": DEFAULT_C17}
@@ -49,6 +51,13 @@ SUPPORTS_CXX17 = {
"-std:c++17": DEFAULT_CXX_17,
}
+SUPPORTS_GNUXX20 = {"-std=gnu++20": DEFAULT_CXX_20}
+
+SUPPORTS_CXX20 = {
+ "-std=c++20": DEFAULT_CXX_20,
+ "-std:c++20": DEFAULT_CXX_20,
+}
+
@memoize
def GCC_BASE(version):
@@ -76,9 +85,18 @@ def GXX(version):
GCC_7 = GCC("7.3.0") + DEFAULT_C11
GXX_7 = GXX("7.3.0") + DEFAULT_CXX_14 + SUPPORTS_GNUXX17 + SUPPORTS_CXX17
GCC_10 = GCC("10.2.1") + DEFAULT_C17
-GXX_10 = GXX("10.2.1") + DEFAULT_CXX_14 + SUPPORTS_GNUXX17 + SUPPORTS_CXX17
+GXX_10 = (
+ GXX("10.2.1")
+ + DEFAULT_CXX_14
+ + SUPPORTS_GNUXX17
+ + SUPPORTS_CXX17
+ + {
+ "-std=gnu++20": {"__cplusplus": "201709L"},
+ "-std=c++20": {"__cplusplus": "201709L"},
+ }
+)
GCC_14 = GCC("14.3.0") + DEFAULT_C17
-GXX_14 = GXX("14.3.0") + DEFAULT_CXX_17
+GXX_14 = GXX("14.3.0") + DEFAULT_CXX_17 + SUPPORTS_GNUXX20 + SUPPORTS_CXX20
DEFAULT_GCC = GCC_14
DEFAULT_GXX = GXX_14
@@ -163,17 +181,34 @@ def XCODE(compiler):
CLANG_14 = CLANG("14.0.0") + DEFAULT_C17
CLANGXX_14 = CLANGXX("14.0.0") + DEFAULT_CXX_14
CLANG_17 = CLANG("17.0.0") + DEFAULT_C17
-CLANGXX_17 = CLANGXX("17.0.0") + DEFAULT_CXX_17
+CLANGXX_17 = CLANGXX("17.0.0") + DEFAULT_CXX_17 + SUPPORTS_CXX20 + SUPPORTS_GNUXX20
CLANG_19 = CLANG("19.1.7") + DEFAULT_C17
-CLANGXX_19 = CLANGXX("19.1.7") + DEFAULT_CXX_17
+CLANGXX_19 = CLANGXX("19.1.7") + DEFAULT_CXX_17 + SUPPORTS_CXX20 + SUPPORTS_GNUXX20
XCODE_CLANG_14 = XCODE(CLANG("14.0.0") + DEFAULT_C17)
-XCODE_CLANGXX_14 = XCODE(CLANGXX("14.0.0") + SUPPORTS_GNUXX17 + SUPPORTS_CXX17)
+XCODE_CLANGXX_14 = XCODE(
+ CLANGXX("14.0.0")
+ + SUPPORTS_GNUXX17
+ + SUPPORTS_CXX17
+ + SUPPORTS_GNUXX20
+ + SUPPORTS_CXX20
+)
XCODE_CLANG_17 = XCODE(CLANG("16.0.0") + DEFAULT_C17)
-XCODE_CLANGXX_17 = XCODE(CLANGXX("16.0.0") + SUPPORTS_GNUXX17 + SUPPORTS_CXX17)
+XCODE_CLANGXX_17 = XCODE(
+ CLANGXX("16.0.0")
+ + SUPPORTS_GNUXX17
+ + SUPPORTS_CXX17
+ + SUPPORTS_GNUXX20
+ + SUPPORTS_CXX20
+)
XCODE_CLANG_19 = XCODE(CLANG("17.0.0") + DEFAULT_C17)
XCODE_CLANGXX_19 = XCODE(
- CLANGXX("17.0.0") + DEFAULT_CXX_14 + SUPPORTS_GNUXX17 + SUPPORTS_CXX17
+ CLANGXX("17.0.0")
+ + DEFAULT_CXX_14
+ + SUPPORTS_GNUXX17
+ + SUPPORTS_CXX17
+ + SUPPORTS_GNUXX20
+ + SUPPORTS_CXX20
)
DEFAULT_CLANG = CLANG_19
DEFAULT_CLANGXX = CLANGXX_19
@@ -235,6 +270,7 @@ CLANG_CL_14 = (
+ SUPPORTS_GNUXX11
+ SUPPORTS_CXX14
+ SUPPORTS_CXX17
+ + SUPPORTS_CXX20
) + {"*.cpp": {"__STDC_VERSION__": False, "__cplusplus": "201703L"}}
CLANG_CL_19 = (
CLANG_19
@@ -243,6 +279,7 @@ CLANG_CL_19 = (
+ SUPPORTS_GNUXX11
+ SUPPORTS_CXX14
+ SUPPORTS_CXX17
+ + SUPPORTS_CXX20
) + {"*.cpp": {"__STDC_VERSION__": False, "__cplusplus": "201703L"}}
CLANG_CL_PLATFORM_X86 = FakeCompiler(
@@ -307,6 +344,7 @@ LIBRARY_NAME_INFOS = {
class BaseToolchainTest(BaseConfigureTest):
def setUp(self):
super(BaseToolchainTest, self).setUp()
+ self.maxDiff = None
self.out = StringIO()
self.logger = logging.getLogger("BaseToolchainTest")
self.logger.setLevel(logging.ERROR)
@@ -439,7 +477,7 @@ class LinuxToolchainTest(BaseToolchainTest):
language="C",
)
GXX_10_RESULT = CompilerResult(
- flags=["-std=gnu++17"],
+ flags=["-std=gnu++20", "-U__cplusplus", "-D__cplusplus=202002L"],
version="10.2.1",
type="gcc",
compiler="/usr/bin/g++-10",
@@ -447,7 +485,7 @@ class LinuxToolchainTest(BaseToolchainTest):
)
GCC_14_RESULT = GCC_10_RESULT + {"compiler": "/usr/bin/gcc-14", "version": "14.3.0"}
GXX_14_RESULT = CompilerResult(
- flags=[],
+ flags=["-std=gnu++20"],
version="14.3.0",
type="gcc",
compiler="/usr/bin/g++-14",
@@ -470,7 +508,7 @@ class LinuxToolchainTest(BaseToolchainTest):
language="C",
)
CLANGXX_17_RESULT = CompilerResult(
- flags=[],
+ flags=["-std=gnu++20"],
version="17.0.0",
type="clang",
compiler="/usr/bin/clang++-17",
@@ -835,7 +873,7 @@ class OSXToolchainTest(BaseToolchainTest):
language="C",
)
DEFAULT_CLANGXX_RESULT = CompilerResult(
- flags=["-stdlib=libc++", "-std=gnu++17"],
+ flags=["-stdlib=libc++", "-std=gnu++20"],
version="19.1.4.or.more",
type="clang",
compiler="/usr/bin/clang++",
@@ -943,7 +981,7 @@ class MingwToolchainTest(BaseToolchainTest):
)
CLANGXX_CL_19_RESULT = CompilerResult(
version="19.1.7",
- flags=[],
+ flags=["-std:c++20"],
type="clang-cl",
compiler="/usr/bin/clang-cl",
language="C++",
@@ -1498,7 +1536,7 @@ class OSXCrossToolchainTest(BaseToolchainTest):
language="C",
)
DEFAULT_CLANGXX_RESULT = CompilerResult(
- flags=[],
+ flags=["-std=gnu++20"],
version="17.0.0",
type="clang",
compiler="/usr/bin/clang++",
diff --git a/python/mozbuild/mozbuild/test/configure/test_toolchain_helpers.py b/python/mozbuild/mozbuild/test/configure/test_toolchain_helpers.py
@@ -239,7 +239,14 @@ class FakeCompiler(dict):
apply_defn(defn)
for flag in flags:
- apply_defn(self.get(flag, {}))
+ if flag.startswith("-D"):
+ name, val = flag[2:].split("=")
+ apply_defn({name: val})
+ elif flag.startswith("-U"):
+ name = flag[2:]
+ apply_defn({name: False})
+ else:
+ apply_defn(self.get(flag, {}))
pp.out = StringIO()
pp.do_include(file)
diff --git a/third_party/libwebrtc/BUILD.gn b/third_party/libwebrtc/BUILD.gn
@@ -315,16 +315,6 @@ config("common_config") {
cflags_objc = []
defines = []
- # We should be able to remove this after c++20 is enabled
- # across the Mozilla tree.
- if (build_with_mozilla) {
- if (is_win) {
- cflags_cc += [ "-std:c++20" ]
- } else {
- cflags_cc += [ "-std=gnu++20" ]
- }
- }
-
if (rtc_enable_protobuf) {
defines += [ "WEBRTC_ENABLE_PROTOBUF=1" ]
} else {
@@ -426,7 +416,7 @@ config("common_config") {
# "-Wnested-externs", (C/Obj-C only)
]
cflags_objc += [ "-Wstrict-prototypes" ]
- cflags_cc += [
+ cflags_cc = [
"-Wnon-virtual-dtor",
# This is enabled for clang; enable for gcc as well.