commit 69e6e8511d0bc0aefbdfa1573b284502ac87b1b9
parent bb2804c0b611e30f3f48a6049e3aca6f133de7b7
Author: Chris Peterson <cpeterson@mozilla.com>
Date: Tue, 9 Dec 2025 00:01:32 +0000
Bug 2002864 - Replace MOZ_CONSTINIT with C++20 constinit. r=xpcom-reviewers,sergesanspaille,emilio
Differential Revision: https://phabricator.services.mozilla.com/D274515
Diffstat:
3 files changed, 3 insertions(+), 20 deletions(-)
diff --git a/docs/code-quality/coding-style/coding_style_cpp.rst b/docs/code-quality/coding-style/coding_style_cpp.rst
@@ -395,12 +395,12 @@ C/C++ practices
should generally be marked explicit. Exceptions should be annotated
with ``MOZ_IMPLICIT``.
- Global variables with runtime initialization should be avoided. Flagging
- them as ``constexpr`` or ``MOZ_CONSTINIT`` is a good way to make sure the
+ them as ``constexpr`` or ``constinit`` is a good way to make sure the
initialization happens at compile-time. If runtime initialization cannot be
avoided, use the attribute ``MOZ_RUNINIT`` to identify those and tell the
linter to ignore that variable. If a variable is flagged as ``MOZ_RUNINIT``
- while the linter detects it could be ``MOZ_CONSTINIT``, you get an error. In
- case where the status of the global variable varies (e.g. depending on
+ while the linter detects it could be ``constinit``, you will get an error. In
+ cases where the status of the global variable varies (e.g. depending on
template parameter), just flag it ``MOZ_GLOBINIT``.
- Use ``char32_t`` as the return type or argument type of a method that
returns or takes as argument a single Unicode scalar value. (Don't
diff --git a/mfbt/Attributes.h b/mfbt/Attributes.h
@@ -9,8 +9,6 @@
#ifndef mozilla_Attributes_h
#define mozilla_Attributes_h
-#include "mozilla/Compiler.h"
-
/*
* MOZ_ALWAYS_INLINE is a macro which expands to tell the compiler that the
* method decorated with it must be inlined, even if the compiler thinks
@@ -654,7 +652,6 @@
* expression. If a member of another class uses this class, or if another
* class inherits from this class, then it is considered to be a non-heap
* class as well, although this attribute need not be provided in such cases.
- * MOZ_CONSTINIT: pre-C++20 equivalent to `constinit`.
* MOZ_RUNINIT: Applies to global variables with runtime initialization.
* MOZ_GLOBINIT: Applies to global variables with potential runtime
* initialization (e.g. inside macro or when initialisation status depends on
@@ -1081,19 +1078,6 @@
# define MOZ_EMPTY_BASES
#endif
-/**
- * Pre- C++20 equivalent to constinit
- */
-#if defined(__cpp_constinit)
-# define MOZ_CONSTINIT constinit
-#elif defined(__clang__)
-# define MOZ_CONSTINIT [[clang::require_constant_initialization]]
-#elif MOZ_GCC_VERSION_AT_LEAST(10, 1, 0)
-# define MOZ_CONSTINIT __constinit
-#else
-# define MOZ_CONSTINIT
-#endif
-
// XXX: GCC somehow does not allow attributes before lambda return types, while
// clang requires so. See also bug 1627007.
#ifdef __clang__
diff --git a/mfbt/api.yml b/mfbt/api.yml
@@ -150,7 +150,6 @@ Attributes.h:
- MOZ_FORMAT_WPRINTF
- MOZ_XPCOM_ABI
- MOZ_EMPTY_BASES
- - MOZ_CONSTINIT
- MOZ_CAN_RUN_SCRIPT_BOUNDARY_LAMBDA
BinarySearch.h: