Skip to content

Conversation

@smallp-o-p
Copy link
Contributor

@smallp-o-p smallp-o-p requested a review from a team as a code owner November 23, 2025 18:48
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Nov 23, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 23, 2025

@llvm/pr-subscribers-libcxx

Author: William Tran-Viet (smallp-o-p)

Changes
  • Mass-reformat tests in std/utilities/optional/optional.object/optional.object.ctor and rearrange header #includes
  • No functional changes
  • Prelude for #169203

Patch is 76.01 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/169231.diff

17 Files Affected:

  • (modified) libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/U.pass.cpp (+91-93)
  • (modified) libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/const_T.pass.cpp (+82-97)
  • (modified) libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/const_optional_U.pass.cpp (+56-62)
  • (modified) libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp (+133-141)
  • (modified) libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/ctor.verify.cpp (+24-15)
  • (modified) libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/deduct.pass.cpp (+22-23)
  • (modified) libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/deduct.verify.cpp (+17-15)
  • (modified) libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/default.pass.cpp (+38-47)
  • (modified) libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/empty_in_place_t_does_not_clobber.pass.cpp (+1-1)
  • (modified) libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/explicit_const_optional_U.pass.cpp (+53-60)
  • (modified) libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/explicit_optional_U.pass.cpp (+44-50)
  • (modified) libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/in_place_t.pass.cpp (+85-109)
  • (modified) libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/initializer_list.pass.cpp (+64-76)
  • (modified) libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp (+110-117)
  • (modified) libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/nullopt_t.pass.cpp (+30-39)
  • (modified) libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/optional_U.pass.cpp (+46-53)
  • (modified) libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/rvalue_T.pass.cpp (+99-118)
diff --git a/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/U.pass.cpp b/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/U.pass.cpp
index a90fecfd075fe..1e951ebdf1d74 100644
--- a/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/U.pass.cpp
+++ b/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/U.pass.cpp
@@ -13,25 +13,28 @@
 // template <class U>
 //   constexpr EXPLICIT optional(U&& u);
 
+#include <cassert>
 #include <optional>
 #include <type_traits>
-#include <cassert>
 
 #include "test_macros.h"
 #include "archetypes.h"
 #include "test_convertible.h"
 
-
 using std::optional;
 
-struct ImplicitThrow
-{
-    constexpr ImplicitThrow(int x) { if (x != -1) TEST_THROW(6);}
+struct ImplicitThrow {
+  constexpr ImplicitThrow(int x) {
+    if (x != -1)
+      TEST_THROW(6);
+  }
 };
 
-struct ExplicitThrow
-{
-    constexpr explicit ExplicitThrow(int x) { if (x != -1) TEST_THROW(6);}
+struct ExplicitThrow {
+  constexpr explicit ExplicitThrow(int x) {
+    if (x != -1)
+      TEST_THROW(6);
+  }
 };
 
 struct ImplicitAny {
@@ -39,56 +42,52 @@ struct ImplicitAny {
   constexpr ImplicitAny(U&&) {}
 };
 
-
 template <class To, class From>
-constexpr bool implicit_conversion(optional<To>&& opt, const From& v)
-{
-    using O = optional<To>;
-    static_assert(test_convertible<O, From>(), "");
-    static_assert(!test_convertible<O, void*>(), "");
-    static_assert(!test_convertible<O, From, int>(), "");
-    return opt && *opt == static_cast<To>(v);
+constexpr bool implicit_conversion(optional<To>&& opt, const From& v) {
+  using O = optional<To>;
+  static_assert(test_convertible<O, From>(), "");
+  static_assert(!test_convertible<O, void*>(), "");
+  static_assert(!test_convertible<O, From, int>(), "");
+  return opt && *opt == static_cast<To>(v);
 }
 
 template <class To, class Input, class Expect>
-constexpr bool explicit_conversion(Input&& in, const Expect& v)
-{
-    using O = optional<To>;
-    static_assert(std::is_constructible<O, Input>::value, "");
-    static_assert(!std::is_convertible<Input, O>::value, "");
-    static_assert(!std::is_constructible<O, void*>::value, "");
-    static_assert(!std::is_constructible<O, Input, int>::value, "");
-    optional<To> opt(std::forward<Input>(in));
-    optional<To> opt2{std::forward<Input>(in)};
-    return opt && *opt == static_cast<To>(v) && (opt2 && *opt2 == static_cast<To>(v));
+constexpr bool explicit_conversion(Input&& in, const Expect& v) {
+  using O = optional<To>;
+  static_assert(std::is_constructible<O, Input>::value, "");
+  static_assert(!std::is_convertible<Input, O>::value, "");
+  static_assert(!std::is_constructible<O, void*>::value, "");
+  static_assert(!std::is_constructible<O, Input, int>::value, "");
+  optional<To> opt(std::forward<Input>(in));
+  optional<To> opt2{std::forward<Input>(in)};
+  return opt && *opt == static_cast<To>(v) && (opt2 && *opt2 == static_cast<To>(v));
 }
 
-void test_implicit()
-{
-    {
-        static_assert(implicit_conversion<long long>(42, 42), "");
-    }
-    {
-        static_assert(implicit_conversion<long double>(3.14, 3.14), "");
-    }
-    {
-        int x = 42;
-        optional<void* const> o(&x);
-        assert(*o == &x);
-    }
-    {
-        using T = TrivialTestTypes::TestType;
-        static_assert(implicit_conversion<T>(42, 42), "");
-    }
-    {
-        using T = TestTypes::TestType;
-        assert(implicit_conversion<T>(3, T(3)));
-    }
-    {
-      using T = TestTypes::TestType;
-      optional<T> opt({3});
-      assert(opt && *opt == static_cast<T>(3));
-    }
+void test_implicit() {
+  {
+    static_assert(implicit_conversion<long long>(42, 42), "");
+  }
+  {
+    static_assert(implicit_conversion<long double>(3.14, 3.14), "");
+  }
+  {
+    int x = 42;
+    optional<void* const> o(&x);
+    assert(*o == &x);
+  }
+  {
+    using T = TrivialTestTypes::TestType;
+    static_assert(implicit_conversion<T>(42, 42), "");
+  }
+  {
+    using T = TestTypes::TestType;
+    assert(implicit_conversion<T>(3, T(3)));
+  }
+  {
+    using T = TestTypes::TestType;
+    optional<T> opt({3});
+    assert(opt && *opt == static_cast<T>(3));
+  }
   {
     using O = optional<ImplicitAny>;
     static_assert(!test_convertible<O, std::in_place_t>(), "");
@@ -96,64 +95,63 @@ void test_implicit()
     static_assert(!test_convertible<O, const std::in_place_t&>(), "");
     static_assert(!test_convertible<O, std::in_place_t&&>(), "");
     static_assert(!test_convertible<O, const std::in_place_t&&>(), "");
-
   }
 #ifndef TEST_HAS_NO_EXCEPTIONS
-    {
-        try {
-            using T = ImplicitThrow;
-            optional<T> t = 42;
-            assert(false);
-            ((void)t);
-        } catch (int) {
-        }
+  {
+    try {
+      using T       = ImplicitThrow;
+      optional<T> t = 42;
+      assert(false);
+      ((void)t);
+    } catch (int) {
     }
+  }
 #endif
 }
 
 void test_explicit() {
+  {
+    using T = ExplicitTrivialTestTypes::TestType;
+    static_assert(explicit_conversion<T>(42, 42), "");
+  }
+  {
+    using T = ExplicitConstexprTestTypes::TestType;
+    static_assert(explicit_conversion<T>(42, 42), "");
+    static_assert(!std::is_convertible<int, T>::value, "");
+  }
+  {
+    using T = ExplicitTestTypes::TestType;
+    T::reset();
     {
-        using T = ExplicitTrivialTestTypes::TestType;
-        static_assert(explicit_conversion<T>(42, 42), "");
-    }
-    {
-        using T = ExplicitConstexprTestTypes::TestType;
-        static_assert(explicit_conversion<T>(42, 42), "");
-        static_assert(!std::is_convertible<int, T>::value, "");
+      assert(explicit_conversion<T>(42, 42));
+      assert(T::alive == 0);
     }
+    T::reset();
     {
-        using T = ExplicitTestTypes::TestType;
-        T::reset();
-        {
-            assert(explicit_conversion<T>(42, 42));
-            assert(T::alive == 0);
-        }
-        T::reset();
-        {
-            optional<T> t(42);
-            assert(T::alive == 1);
-            assert(T::value_constructed == 1);
-            assert(T::move_constructed == 0);
-            assert(T::copy_constructed == 0);
-            assert(t.value().value == 42);
-        }
-        assert(T::alive == 0);
+      optional<T> t(42);
+      assert(T::alive == 1);
+      assert(T::value_constructed == 1);
+      assert(T::move_constructed == 0);
+      assert(T::copy_constructed == 0);
+      assert(t.value().value == 42);
     }
+    assert(T::alive == 0);
+  }
 #ifndef TEST_HAS_NO_EXCEPTIONS
-    {
-        try {
-            using T = ExplicitThrow;
-            optional<T> t(42);
-            assert(false);
-        } catch (int) {
-        }
+  {
+    try {
+      using T = ExplicitThrow;
+      optional<T> t(42);
+      assert(false);
+    } catch (int) {
     }
+  }
 #endif
 }
 
 int main(int, char**) {
-    test_implicit();
-    test_explicit();
+  test_implicit();
+  test_explicit();
 
   return 0;
 }
diff --git a/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/const_T.pass.cpp b/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/const_T.pass.cpp
index 91a2323eebbf4..67d0fcfc18b86 100644
--- a/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/const_T.pass.cpp
+++ b/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/const_T.pass.cpp
@@ -12,117 +12,102 @@
 
 // constexpr optional(const T& v);
 
+#include <cassert>
 #include <optional>
 #include <type_traits>
-#include <cassert>
 
 #include "test_macros.h"
 #include "archetypes.h"
 
 using std::optional;
 
-int main(int, char**)
-{
-    {
-        typedef int T;
-        constexpr T t(5);
-        constexpr optional<T> opt(t);
-        static_assert(static_cast<bool>(opt) == true, "");
-        static_assert(*opt == 5, "");
-
-        struct test_constexpr_ctor
-            : public optional<T>
-        {
-            constexpr test_constexpr_ctor(const T&) {}
-        };
-
-    }
-    {
-        typedef double T;
-        constexpr T t(3);
-        constexpr optional<T> opt(t);
-        static_assert(static_cast<bool>(opt) == true, "");
-        static_assert(*opt == 3, "");
-
-        struct test_constexpr_ctor
-            : public optional<T>
-        {
-            constexpr test_constexpr_ctor(const T&) {}
-        };
+int main(int, char**) {
+  {
+    typedef int T;
+    constexpr T t(5);
+    constexpr optional<T> opt(t);
+    static_assert(static_cast<bool>(opt) == true, "");
+    static_assert(*opt == 5, "");
 
-    }
-    {
-        const int x = 42;
-        optional<const int> o(x);
-        assert(*o == x);
-    }
-    {
-        typedef TestTypes::TestType T;
-        T::reset();
-        const T t(3);
-        optional<T> opt = t;
-        assert(T::alive == 2);
-        assert(T::copy_constructed == 1);
-        assert(static_cast<bool>(opt) == true);
-        assert(opt.value().value == 3);
-    }
-    {
-        typedef ExplicitTestTypes::TestType T;
-        static_assert(!std::is_convertible<T const&, optional<T>>::value, "");
-        T::reset();
-        const T t(3);
-        optional<T> opt(t);
-        assert(T::alive == 2);
-        assert(T::copy_constructed == 1);
-        assert(static_cast<bool>(opt) == true);
-        assert(opt.value().value == 3);
-    }
-    {
-        typedef ConstexprTestTypes::TestType T;
-        constexpr T t(3);
-        constexpr optional<T> opt = {t};
-        static_assert(static_cast<bool>(opt) == true, "");
-        static_assert(opt.value().value == 3, "");
+    struct test_constexpr_ctor : public optional<T> {
+      constexpr test_constexpr_ctor(const T&) {}
+    };
+  }
+  {
+    typedef double T;
+    constexpr T t(3);
+    constexpr optional<T> opt(t);
+    static_assert(static_cast<bool>(opt) == true, "");
+    static_assert(*opt == 3, "");
 
-        struct test_constexpr_ctor
-            : public optional<T>
-        {
-            constexpr test_constexpr_ctor(const T&) {}
-        };
-    }
-    {
-        typedef ExplicitConstexprTestTypes::TestType T;
-        static_assert(!std::is_convertible<const T&, optional<T>>::value, "");
-        constexpr T t(3);
-        constexpr optional<T> opt(t);
-        static_assert(static_cast<bool>(opt) == true, "");
-        static_assert(opt.value().value == 3, "");
+    struct test_constexpr_ctor : public optional<T> {
+      constexpr test_constexpr_ctor(const T&) {}
+    };
+  }
+  {
+    const int x = 42;
+    optional<const int> o(x);
+    assert(*o == x);
+  }
+  {
+    typedef TestTypes::TestType T;
+    T::reset();
+    const T t(3);
+    optional<T> opt = t;
+    assert(T::alive == 2);
+    assert(T::copy_constructed == 1);
+    assert(static_cast<bool>(opt) == true);
+    assert(opt.value().value == 3);
+  }
+  {
+    typedef ExplicitTestTypes::TestType T;
+    static_assert(!std::is_convertible<T const&, optional<T>>::value, "");
+    T::reset();
+    const T t(3);
+    optional<T> opt(t);
+    assert(T::alive == 2);
+    assert(T::copy_constructed == 1);
+    assert(static_cast<bool>(opt) == true);
+    assert(opt.value().value == 3);
+  }
+  {
+    typedef ConstexprTestTypes::TestType T;
+    constexpr T t(3);
+    constexpr optional<T> opt = {t};
+    static_assert(static_cast<bool>(opt) == true, "");
+    static_assert(opt.value().value == 3, "");
 
-        struct test_constexpr_ctor
-            : public optional<T>
-        {
-            constexpr test_constexpr_ctor(const T&) {}
-        };
+    struct test_constexpr_ctor : public optional<T> {
+      constexpr test_constexpr_ctor(const T&) {}
+    };
+  }
+  {
+    typedef ExplicitConstexprTestTypes::TestType T;
+    static_assert(!std::is_convertible<const T&, optional<T>>::value, "");
+    constexpr T t(3);
+    constexpr optional<T> opt(t);
+    static_assert(static_cast<bool>(opt) == true, "");
+    static_assert(opt.value().value == 3, "");
 
-    }
+    struct test_constexpr_ctor : public optional<T> {
+      constexpr test_constexpr_ctor(const T&) {}
+    };
+  }
 #ifndef TEST_HAS_NO_EXCEPTIONS
-    {
-        struct Z {
-            Z(int) {}
-            Z(const Z&) {throw 6;}
-        };
-        typedef Z T;
-        try
-        {
-            const T t(3);
-            optional<T> opt(t);
-            assert(false);
-        }
-        catch (int i)
-        {
-            assert(i == 6);
-        }
+  {
+    struct Z {
+      Z(int) {}
+      Z(const Z&) { throw 6; }
+    };
+    typedef Z T;
+    try {
+      const T t(3);
+      optional<T> opt(t);
+      assert(false);
+    } catch (int i) {
+      assert(i == 6);
     }
+  }
 #endif
 
   return 0;
diff --git a/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/const_optional_U.pass.cpp b/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/const_optional_U.pass.cpp
index 9505238e6e5e2..70fd76ec6ed0b 100644
--- a/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/const_optional_U.pass.cpp
+++ b/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/const_optional_U.pass.cpp
@@ -12,74 +12,69 @@
 // template <class U>
 //   optional(const optional<U>& rhs);
 
+#include <cassert>
 #include <optional>
 #include <type_traits>
-#include <cassert>
 
 #include "test_macros.h"
 
 using std::optional;
 
 template <class T, class U>
-TEST_CONSTEXPR_CXX20 void
-test(const optional<U>& rhs, bool is_going_to_throw = false)
-{
-    bool rhs_engaged = static_cast<bool>(rhs);
+TEST_CONSTEXPR_CXX20 void test(const optional<U>& rhs, bool is_going_to_throw = false) {
+  bool rhs_engaged = static_cast<bool>(rhs);
 #ifndef TEST_HAS_NO_EXCEPTIONS
-    try
-    {
-        optional<T> lhs = rhs;
-        assert(is_going_to_throw == false);
-        assert(static_cast<bool>(lhs) == rhs_engaged);
-        if (rhs_engaged)
-            assert(*lhs == *rhs);
-    }
-    catch (int i)
-    {
-        assert(i == 6);
-    }
-#else
-    if (is_going_to_throw) return;
+  try {
     optional<T> lhs = rhs;
+    assert(is_going_to_throw == false);
     assert(static_cast<bool>(lhs) == rhs_engaged);
     if (rhs_engaged)
-        assert(*lhs == *rhs);
+      assert(*lhs == *rhs);
+  } catch (int i) {
+    assert(i == 6);
+  }
+#else
+  if (is_going_to_throw)
+    return;
+  optional<T> lhs = rhs;
+  assert(static_cast<bool>(lhs) == rhs_engaged);
+  if (rhs_engaged)
+    assert(*lhs == *rhs);
 #endif
 }
 
-class X
-{
-    int i_;
+class X {
+  int i_;
+
 public:
-    constexpr X(int i) : i_(i) {}
-    constexpr X(const X& x) : i_(x.i_) {}
-    TEST_CONSTEXPR_CXX20 ~X() {i_ = 0;}
-    friend constexpr bool operator==(const X& x, const X& y) {return x.i_ == y.i_;}
+  constexpr X(int i) : i_(i) {}
+  constexpr X(const X& x) : i_(x.i_) {}
+  TEST_CONSTEXPR_CXX20 ~X() { i_ = 0; }
+  friend constexpr bool operator==(const X& x, const X& y) { return x.i_ == y.i_; }
 };
 
-class Y
-{
-    int i_;
+class Y {
+  int i_;
+
 public:
-    constexpr Y(int i) : i_(i) {}
+  constexpr Y(int i) : i_(i) {}
 
-    friend constexpr bool operator==(const Y& x, const Y& y) {return x.i_ == y.i_;}
+  friend constexpr bool operator==(const Y& x, const Y& y) { return x.i_ == y.i_; }
 };
 
 int count = 0;
 
-class Z
-{
-    int i_;
+class Z {
+  int i_;
+
 public:
-    Z(int i) : i_(i) {TEST_THROW(6);}
+  Z(int i) : i_(i) { TEST_THROW(6); }
 
-    friend bool operator==(const Z& x, const Z& y) {return x.i_ == y.i_;}
+  friend bool operator==(const Z& x, const Z& y) { return x.i_ == y.i_; }
 };
 
-template<class T, class U>
-constexpr bool test_all()
-{
+template <class T, class U>
+constexpr bool test_all() {
   {
     optional<U> rhs;
     test<T>(rhs);
@@ -91,30 +86,29 @@ constexpr bool test_all()
   return true;
 }
 
-int main(int, char**)
-{
-    test_all<int, short>();
-    test_all<X, int>();
-    test_all<Y, int>();
+int main(int, char**) {
+  test_all<int, short>();
+  test_all<X, int>();
+  test_all<Y, int>();
 #if TEST_STD_VER > 17
-    static_assert(test_all<int, short>());
-    static_assert(test_all<X, int>());
-    static_assert(test_all<Y, int>());
+  static_assert(test_all<int, short>());
+  static_assert(test_all<X, int>());
+  static_assert(test_all<Y, int>());
 #endif
-    {
-        typedef Z T;
-        typedef int U;
-        optional<U> rhs;
-        test<T>(rhs);
-    }
-    {
-        typedef Z T;
-        typedef int U;
-        optional<U> rhs(U{3});
-        test<T>(rhs, true);
-    }
-
-    static_assert(!(std::is_constructible<optional<X>, const optional<Y>&>::value), "");
+  {
+    typedef Z T;
+    typedef int U;
+    optional<U> rhs;
+    test<T>(rhs);
+  }
+  {
+    typedef Z T;
+    typedef int U;
+    optional<U> rhs(U{3});
+    test<T>(rhs, true);
+  }
+
+  static_assert(!(std::is_constructible<optional<X>, const optional<Y>&>::value), "");
 
   return 0;
 }
diff --git a/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp b/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp
index 54a424c4c347d..f61a22c23a04d 100644
--- a/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp
+++ b/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp
@@ -11,173 +11,165 @@
 
 // constexpr optional(const optional<T>& rhs);
 
+#include <cassert>
 #include <optional>
 #include <type_traits>
-#include <cassert>
 
 #include "test_macros.h"
 #include "archetypes.h"
 
 using std::optional;
 
-template <class T, class ...InitArgs>
-void test(InitArgs&&... args)
-{
-    const optional<T> rhs(std::forward<InitArgs>(args)...);
-    bool rhs_engaged = static_cast<bool>(rhs);
-    optional<T> lhs = rhs;
-    assert(static_cast<bool>(lhs) == rhs_engaged);
-    if (rhs_engaged)
-        assert(*lhs == *rhs);
+template <class T, class... InitArgs>
+void test(InitArgs&&... args) {
+  const optional<T> rhs(std::forward<InitArgs>(args)...);
+  bool rhs_engaged = static_cast<bool>(rhs);
+  optional<T> lhs  = rhs;
+  assert(static_cast<bool>(lhs) == rhs_engaged);
+  if (rhs_engaged)
+    assert(*lhs == *rhs);
 }
 
-template <class T, class ...InitArgs>
-constexpr bool constexpr_test(InitArgs&&... args)
-{
-    static_assert( std::is_trivially_copy_constructible_v<T>, ""); // requirement
-    const optional<T> rhs(std::forward<InitArgs>(args)...);
-    optional<T> lhs = rhs;
-    return (lhs.has_value() == rhs.has_value()) &&
-           (lhs.has_value() ? *lhs == *rhs : true);
+template <class T, class... InitArgs>
+constexpr bool constexpr_test(InitArgs&&... args) {
+  static_assert(std::is_trivially_copy_constructible_v<T>, ""); // requirement
+  const optional<T> rhs(std::forward<InitArgs>(args)...);
+  optional<T> lhs = rhs;
+  return (lhs.has_value() == rhs.has_value()) && (lhs.has_value() ? *lhs == *rhs : true);
 }
 
 void test_throwing_ctor() {
 #ifndef TEST_HAS_NO_EXCEPTIONS
-    struct Z {
-        Z() : count(0) {}
-        Z(Z const& o) : count(o.count + 1)
-        { if (count == 2) throw 6; }
-        int count;
-    };
-    const Z z;
-    const optional<Z> rhs(z);
-    try
-    {
-        optional<Z> lhs(rhs);
-        assert(false);
-    }
-    catch (int i)
-    {
-        assert(i == 6);
+  struct Z {
+    Z() : count(0) {}
+    Z(Z const& o) : count(o.count + 1) {
+      if (count == 2)
+        throw 6;
     }
+    int count;
+  };
+  const Z z;
+  const optional<Z> rhs(z);
+  try {
+    optional<Z> lhs(rhs);
+    assert(false);
+  } catch (int i) {
+    assert(i == 6);
+  }
 #endif
 }
 
-template <class T, class ...InitArgs>
-void test_ref(InitArgs&&... args)
-{
-    const optional<T> rhs(std::forward<InitArgs>(args)...);
-    bool rhs_engaged = static_cast<bool>(rhs);
-    optional<T> lhs = rhs;
-    assert(static_cast<bool>(lhs) == rhs_engaged);
-    if (rhs_engaged)
-        assert(&(*lhs) == &(*rhs));
+template <class T, class... InitArgs>
+void test_ref(InitArgs&&... args) {
+  const optional<T> rhs(std::forward<InitArgs>(args)...);
+  bool rhs_engaged = static_cast<bool>(rhs);
+  optional<T> lhs  = rhs;
+  assert(static_cast<bool>(lhs) == rhs_engaged);
+  if (rhs_engaged)
+    assert(&(*lhs) == &(*rhs));
 }
 
-
-void test_reference_extension()
-{
+void test_reference_extension() {
 #if defined(_LIBCPP_VERSION) && 0 // FIXME these extensions are currently disabled.
-    using T = TestTypes::TestType;
-    T::reset();
-    {
-        T t;
-        T::res...
[truncated]

Copy link
Contributor

@frederick-vs-ja frederick-vs-ja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@frederick-vs-ja
Copy link
Contributor

frederick-vs-ja commented Nov 26, 2025

Did you intentionally mention #169231 #169203 in the PR description? If we use it as squashed commit message as-is, it will make that PR mentioned many times in the GitHub UI. (I'm just a bit nervous about this.)

@smallp-o-p
Copy link
Contributor Author

Did you intentionally mention #169231 in the PR description? If we use it as squashed commit message as-is, it will make that PR mentioned many times in the GitHub UI. (I'm just a bit nervous about this.)

I don't mention #169231 in this PR's description? Unless you mean #169203. I can remove it if that might cause problems.

@frederick-vs-ja
Copy link
Contributor

Did you intentionally mention #169231 in the PR description? If we use it as squashed commit message as-is, it will make that PR mentioned many times in the GitHub UI. (I'm just a bit nervous about this.)

I don't mention #169231 in this PR's description? Unless you mean #169203. I can remove it if that might cause problems.

Oh, sorry for the wrong number. This doesn't actually cause problems.

@H-G-Hristov
Copy link
Contributor

@smallp-o-p Do you need assistance with merging the PR?

@smallp-o-p
Copy link
Contributor Author

@smallp-o-p Do you need assistance with merging the PR?

Yes please! Whenever you deem fit.

// clang-format off
{
// optional()
std::optional opt; // expected-error-re {{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}optional'}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change requested for this PR. In a subsequent PR, we can change these lines to

    // expected-error-re@+1 {{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}optional'}}
    std::optional opt;

or

    std::optional opt;
    // expected-error-re@-1 {{no viable constructor or deduction guide for deduction of template arguments of '{{(std::)?}}optional'}}


{
// optional(nullopt_t)
std::optional opt(std::nullopt); // expected-error-re@optional:* {{static assertion failed{{.*}}instantiation of optional with nullopt_t is ill-formed}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, given we expect the error message being emitted for optional:*, we can move the comment in a new line (in a subsequent PR), like the following.

    std::optional opt(std::nullopt);
    // expected-error-re@optional:* {{static assertion failed{{.*}}instantiation of optional with nullopt_t is ill-formed}}

@frederick-vs-ja frederick-vs-ja merged commit f6712b6 into llvm:main Nov 27, 2025
80 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants