commit fa4d5d596a2f0799354301f0be19374a33504918
parent ad2eab95e56be42a6995ea130e3b900ece7fb2ec
Author: Jan de Mooij <jdemooij@mozilla.com>
Date: Thu, 13 Nov 2025 11:53:57 +0000
Bug 1999913 - Remove #ifdef in SafelyInitialized::create and mark function constexpr. r=jonco
GCC and Clang builds in CI are now green with the static-asserts enabled everywhere.
Differential Revision: https://phabricator.services.mozilla.com/D272422
Diffstat:
3 files changed, 9 insertions(+), 12 deletions(-)
diff --git a/js/public/RootingAPI.h b/js/public/RootingAPI.h
@@ -223,14 +223,11 @@ JS_PUBLIC_API void HeapScriptWriteBarriers(JSScript** objp, JSScript* prev,
*/
template <typename T, typename Enable = void>
struct SafelyInitialized {
- static T create() {
+ static constexpr T create() {
// This function wants to presume that |T()| -- which value-initializes a
// |T| per C++11 [expr.type.conv]p2 -- will produce a safely-initialized,
// safely-usable T that it can return.
-#if defined(XP_WIN) || defined(XP_DARWIN) || \
- (defined(XP_UNIX) && !defined(__clang__))
-
// That presumption holds for pointers, where value initialization produces
// a null pointer.
constexpr bool IsPointer = std::is_pointer_v<T>;
@@ -246,8 +243,6 @@ struct SafelyInitialized {
static_assert(IsPointer || IsNonTriviallyDefaultConstructibleClassOrUnion,
"T() must evaluate to a safely-initialized T");
-#endif
-
return T();
}
};
diff --git a/js/src/wasm/WasmAnyRef.h b/js/src/wasm/WasmAnyRef.h
@@ -104,7 +104,7 @@ class AnyRef {
// Get the pointer tag stored in value_.
AnyRefTag pointerTag() const { return GetUintptrTag(value_); }
- explicit AnyRef(uintptr_t value) : value_(value) {}
+ explicit constexpr AnyRef(uintptr_t value) : value_(value) {}
static constexpr uintptr_t TagUintptr(uintptr_t value, AnyRefTag tag) {
MOZ_ASSERT(!(value & TagMask));
@@ -151,15 +151,15 @@ class AnyRef {
// The inclusive minimum 31-bit signed integer, -2^30.
static constexpr int32_t MinI31Value = -(2 << 29);
- explicit AnyRef() : value_(NullRefValue) {}
- MOZ_IMPLICIT AnyRef(std::nullptr_t) : value_(NullRefValue) {}
+ explicit constexpr AnyRef() : value_(NullRefValue) {}
+ MOZ_IMPLICIT constexpr AnyRef(std::nullptr_t) : value_(NullRefValue) {}
// The null AnyRef value.
- static AnyRef null() { return AnyRef(NullRefValue); }
+ static constexpr AnyRef null() { return AnyRef(NullRefValue); }
// An invalid AnyRef cannot arise naturally from wasm and so can be used as
// a sentinel value to indicate failure from an AnyRef-returning function.
- static AnyRef invalid() { return AnyRef(InvalidRefValue); }
+ static constexpr AnyRef invalid() { return AnyRef(InvalidRefValue); }
// Given a JSObject* that comes from JS, turn it into AnyRef.
static AnyRef fromJSObjectOrNull(JSObject* objectOrNull) {
diff --git a/js/src/wasm/WasmValue.h b/js/src/wasm/WasmValue.h
@@ -500,7 +500,9 @@ struct InternalBarrierMethods<wasm::Val> {
template <>
struct JS::SafelyInitialized<js::wasm::AnyRef> {
- static js::wasm::AnyRef create() { return js::wasm::AnyRef::null(); }
+ static constexpr js::wasm::AnyRef create() {
+ return js::wasm::AnyRef::null();
+ }
};
#endif // wasm_val_h