From 9e50a890853333f5d9eb36305763d7ab00886825 Mon Sep 17 00:00:00 2001
From: Chris Peterson <cpeterson@mozilla.com>
Date: Wed, 16 Nov 2022 00:54:27 +0000
Subject: [PATCH] Bug 1800293 - mfbt: Don't use std::is_literal_type when
 compiling as C++20. r=glandium

`std::is_literal_type` was deprecated in C++17 and removed in C++20. Continue using it when compiling as C++17 to retain what benefits it does provide for generic code.

> The `is_literal` type trait offers negligible value to generic code, as what is really needed is the ability to know that a specific construction would produce constant initialization. The core term of a literal type having at least one constexpr constructor is too weak to be used meaningfully.

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0174r2.html

https://en.cppreference.com/w/cpp/types/is_literal_type

Differential Revision: https://phabricator.services.mozilla.com/D161952
---
 mfbt/tests/TestResult.cpp    | 2 ++
 mfbt/tests/TestTypedEnum.cpp | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/mfbt/tests/TestResult.cpp b/mfbt/tests/TestResult.cpp
index b66d3b608ed2c..20680e41c832c 100644
--- a/mfbt/tests/TestResult.cpp
+++ b/mfbt/tests/TestResult.cpp
@@ -98,11 +98,13 @@ static_assert(sizeof(Foo32) >= sizeof(uintptr_t) ||
                   sizeof(Result<Foo16, Foo32>) <= sizeof(uintptr_t),
               "Result with small types should be pointer-sized");
 
+#if __cplusplus < 202002L
 static_assert(std::is_literal_type_v<Result<int*, Failed>>);
 static_assert(std::is_literal_type_v<Result<Ok, Failed>>);
 static_assert(std::is_literal_type_v<Result<Ok, Foo8>>);
 static_assert(std::is_literal_type_v<Result<Foo8, Foo16>>);
 static_assert(!std::is_literal_type_v<Result<Ok, UniquePtr<int>>>);
+#endif
 
 static constexpr GenericErrorResult<Failed> Fail() { return Err(Failed{}); }
 
diff --git a/mfbt/tests/TestTypedEnum.cpp b/mfbt/tests/TestTypedEnum.cpp
index 814d3485ce416..cddbb39e0b75f 100644
--- a/mfbt/tests/TestTypedEnum.cpp
+++ b/mfbt/tests/TestTypedEnum.cpp
@@ -11,10 +11,10 @@
 #include <type_traits>
 
 // A rough feature check for is_literal_type. Not very carefully checked.
-// Feel free to amend as needed.
+// Feel free to amend as needed. is_literal_type was removed in C++20.
 // We leave ANDROID out because it's using stlport which doesn't have
 // std::is_literal_type.
-#if __cplusplus >= 201103L && !defined(ANDROID)
+#if __cplusplus >= 201103L && __cplusplus < 202002L && !defined(ANDROID)
 #  if defined(__clang__)
 /*
  * Per Clang documentation, "Note that marketing version numbers should not
-- 
GitLab