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

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Tue Dec 30 22:59:25 PST 2025


================
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 example provided for LWG4370 compiles.
+
+#include <cassert>
+#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; }
+};
+
+int main() {
----------------
frederick-vs-ja wrote:

libc++ tests conventionally use `int main(int, char**) { /* ... */ return 0; }` when `main` is needed. But I'm not sure whether you want to actually run this test.

If you want to run this, filename `relops.pass.cpp` should be used instead, and replace the `void` casts with `assert` (as you've included `<cassert>`). Also, it will make more sense to run the cases in both constant evaluation and run time.

If you don't want to run this, `<cassert>` is redundant and we should use `void test() { /* ... */ }` instead of `main`.

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


More information about the libcxx-commits mailing list