[libcxx-commits] [libcxx] [libc++] Resolve LWG4370 (PR #174062)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Tue Dec 30 23:32:28 PST 2025


================
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++17
+// <optional>
+
+// Verify that comparison operators of `optional` accept underlying return types convertible both from and to `bool`
+// as required by LWG4370.
+
+#include <optional>
+
+struct Bool {
+  Bool(bool) {};
+  operator bool() const { return true; };
+};
+
+struct S {
+  Bool operator==(S) const { return true; }
+  Bool operator!=(S) const { return true; }
+  Bool operator<=(S) const { return true; }
+  Bool operator<(S) const { return true; }
+  Bool operator>(S) const { return true; }
+  Bool operator>=(S) const { return true; }
+};
+
+constexpr void test() {
----------------
frederick-vs-ja wrote:

The `constexpr` looks superfluous if we only verify the validness of comparison operator functions.
Also, it makes a program ill-formed, no diagnostic required before C++23 (because the underlying comparisons never result in constant subexpressions, see also [P2448R2](http://wg21.link/p2448R2)).
```suggestion
void test() {
```

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


More information about the libcxx-commits mailing list