[libcxx-commits] [libcxx] [libc++] Implement LWG3133: Modernizing numeric type requirements (PR #208145)

Yordan Vásquez via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jul 7 22:58:35 PDT 2026


https://github.com/vyordan created https://github.com/llvm/llvm-project/pull/208145

This implements the resolution of LWG3133, which modernizes the requirements on `T` for `std::complex<T>` and `std::valarray<T>` in [numeric.requirements].

- Adds a `static_assert` to `std::complex<T>` requiring `T` to be a cv-unqualified object type, following the same pattern already used by `std::optional<T>`.
- No code changes were needed for `std::valarray<T>`: its `operator[]` already indexes through a raw pointer and never relies on a user-overloadable `operator&`, so it already conforms to the revised wording.
- Added a `.verify.cpp` test covering `complex<const T>` and `complex<volatile T>`.
- Ran the full `complex.number` test suite locally (97/97 passing) to confirm no regressions.

Fixes #100254

>From 16f173d3dbc1840d52e09121dff1df14297e71d1 Mon Sep 17 00:00:00 2001
From: vyordan <vyordangiovani at gmail.com>
Date: Tue, 7 Jul 2026 23:55:36 -0600
Subject: [PATCH] [libc++] Implement LWG3133: Modernizing numeric type
 requirements

Add a static_assert to std::complex<T> requiring that T be a
cv-unqualified object type, matching the revised wording in
[numeric.requirements]. This mirrors the existing pattern used by
std::optional<T>.

No implementation changes were needed for std::valarray<T>, since
its operator[] already indexes safely without depending on a
user-overloadable operator&.

Fixes #100254
---
 libcxx/docs/Status/Cxx20Issues.csv            |  2 +-
 libcxx/include/complex                        |  6 ++++
 ..._requires_cv_unqualified_object.verify.cpp | 30 +++++++++++++++++++
 3 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100644 libcxx/test/std/numerics/complex.number/complex/complex_requires_cv_unqualified_object.verify.cpp

diff --git a/libcxx/docs/Status/Cxx20Issues.csv b/libcxx/docs/Status/Cxx20Issues.csv
index f43a56f99f025..e3845d3e946d3 100644
--- a/libcxx/docs/Status/Cxx20Issues.csv
+++ b/libcxx/docs/Status/Cxx20Issues.csv
@@ -136,7 +136,7 @@
 "`LWG3101 <https://wg21.link/LWG3101>`__","``span``\ 's ``Container``\  constructors need another constraint","2019-02 (Kona)","|Complete|","","`#103837 <https://github.com/llvm/llvm-project/issues/103837>`__",""
 "`LWG3112 <https://wg21.link/LWG3112>`__","``system_error``\  and ``filesystem_error``\  constructors taking a ``string``\  may not be able to meet their postconditions","2019-02 (Kona)","|Nothing To Do|","","`#100253 <https://github.com/llvm/llvm-project/issues/100253>`__",""
 "`LWG3119 <https://wg21.link/LWG3119>`__","Program-definedness of closure types","2019-02 (Kona)","|Nothing To Do|","","`#103838 <https://github.com/llvm/llvm-project/issues/103838>`__",""
-"`LWG3133 <https://wg21.link/LWG3133>`__","Modernizing numeric type requirements","2019-02 (Kona)","","","`#100254 <https://github.com/llvm/llvm-project/issues/100254>`__",""
+"`LWG3133 <https://wg21.link/LWG3133>`__","Modernizing numeric type requirements","2019-02 (Kona)","|Complete|","23","`#100254 <https://github.com/llvm/llvm-project/issues/100254>`__",""
 "`LWG3144 <https://wg21.link/LWG3144>`__","``span``\  does not have a ``const_pointer``\  typedef","2019-02 (Kona)","|Complete|","","`#103839 <https://github.com/llvm/llvm-project/issues/103839>`__",""
 "`LWG3173 <https://wg21.link/LWG3173>`__","Enable CTAD for ``ref-view``\ ","2019-02 (Kona)","|Complete|","15","`#103840 <https://github.com/llvm/llvm-project/issues/103840>`__",""
 "`LWG3179 <https://wg21.link/LWG3179>`__","``subrange``\  should always model ``Range``\ ","2019-02 (Kona)","|Nothing To Do|","","`#103842 <https://github.com/llvm/llvm-project/issues/103842>`__",""
diff --git a/libcxx/include/complex b/libcxx/include/complex
index f1ba85eb9624e..1fb4db220c0b8 100644
--- a/libcxx/include/complex
+++ b/libcxx/include/complex
@@ -266,6 +266,9 @@ template<class T> complex<T> tanh (const complex<T>&);
 #  include <__tuple/tuple_element.h>
 #  include <__tuple/tuple_size.h>
 #  include <__type_traits/conditional.h>
+#  include <__type_traits/is_object.h>
+#  include <__type_traits/is_same.h>
+#  include <__type_traits/remove_cv.h>
 #  include <__utility/move.h>
 #  include <cmath>
 #  include <version>
@@ -307,6 +310,9 @@ class complex {
 public:
   typedef _Tp value_type;
 
+  static_assert(is_object_v<_Tp> && is_same_v<_Tp, remove_cv_t<_Tp>>,
+                "std::complex<T> requires that T be a cv-unqualified object type");
+
 private:
   value_type __re_;
   value_type __im_;
diff --git a/libcxx/test/std/numerics/complex.number/complex/complex_requires_cv_unqualified_object.verify.cpp b/libcxx/test/std/numerics/complex.number/complex/complex_requires_cv_unqualified_object.verify.cpp
new file mode 100644
index 0000000000000..4c00068ff390f
--- /dev/null
+++ b/libcxx/test/std/numerics/complex.number/complex/complex_requires_cv_unqualified_object.verify.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+// UNSUPPORTED: c++03, c++11, c++14
+
+// <complex>
+
+// template<class T>
+// class complex
+//
+// T shall be a cv-unqualified object type (LWG3133)
+
+#include <complex>
+
+int main(int, char**) {
+  {
+    // expected-error-re at complex:* {{static assertion failed{{.*}}std::complex<T> requires that T be a cv-unqualified object type}}
+    std::complex<const double> c1;
+  }
+  {
+    // expected-error-re at complex:* {{static assertion failed{{.*}}std::complex<T> requires that T be a cv-unqualified object type}}
+    std::complex<volatile int> c2;
+  }
+
+  return 0;
+}



More information about the libcxx-commits mailing list