[libcxx-commits] [libcxx] Make std::nullopt_t comparable (PR #195549)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Mon May 4 03:22:24 PDT 2026


================
@@ -13,31 +13,50 @@
 // inline constexpr nullopt_t nullopt(unspecified);
 
 // [optional.nullopt]/2:
-//   Type nullopt_t shall not have a default constructor or an initializer-list
-//   constructor, and shall not be an aggregate.
+//   Type nullopt_t does not have a default constructor or an initializer-list
+//   constructor, and is not an aggregate. nullopt_t models copyable and
+//   three_way_comparable<strong_ordering>.
 
 #include <optional>
 #include <type_traits>
+#if _LIBCPP_STD_VER >= 26
+#  include <vector>
+#  include <ranges>
+#  include <cassert>
+#  include <algorithm>
+#endif
 
 #include "test_macros.h"
 
-using std::nullopt_t;
 using std::nullopt;
+using std::nullopt_t;
 
-constexpr bool test()
-{
-    nullopt_t foo{nullopt};
-    (void)foo;
-    return true;
+constexpr bool test() {
+  nullopt_t foo{nullopt};
+  (void)foo;
+  return true;
 }
 
-int main(int, char**)
-{
-    static_assert(std::is_empty_v<nullopt_t>);
-    static_assert(!std::is_default_constructible_v<nullopt_t>);
-
-    static_assert(std::is_same_v<const nullopt_t, decltype(nullopt)>);
-    static_assert(test());
+int main(int, char**) {
+  static_assert(std::is_empty_v<nullopt_t>);
+  static_assert(!std::is_default_constructible_v<nullopt_t>);
+
+  static_assert(std::is_same_v<const nullopt_t, decltype(nullopt)>);
+  static_assert(test());
+#if TEST_STD_VER >= 26
----------------
frederick-vs-ja wrote:

Ditto, we should test some stuffs since C++17.

https://github.com/llvm/llvm-project/pull/195549


More information about the libcxx-commits mailing list