[libcxx-commits] [libcxx] [libc++] Implement LWG3133: Modernizing numeric type requirements (PR #208145)
Yordan Vásquez via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jul 8 00:17:21 PDT 2026
https://github.com/vyordan updated https://github.com/llvm/llvm-project/pull/208145
>From cb1a4be06fb739c649cd28828b56eaffc0072bff 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 | 5 ++++
..._requires_cv_unqualified_object.verify.cpp | 27 +++++++++++++++++++
3 files changed, 33 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..37dfc747b712e 100644
--- a/libcxx/include/complex
+++ b/libcxx/include/complex
@@ -266,6 +266,8 @@ 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_unqualified.h>
# include <__utility/move.h>
# include <cmath>
# include <version>
@@ -307,6 +309,9 @@ class complex {
public:
typedef _Tp value_type;
+ static_assert(is_object<_Tp>::value && __is_unqualified_v<_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..da87ea62cd4c4
--- /dev/null
+++ b/libcxx/test/std/numerics/complex.number/complex/complex_requires_cv_unqualified_object.verify.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// XFAIL: FROZEN-CXX03-HEADERS-FIXME
+
+// <complex>
+
+// template<class T>
+// class complex
+//
+// T shall be a cv-unqualified object type (LWG3133)
+
+#include <complex>
+
+void test() {
+ // 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;
+ // expected-error-re at complex:* {{static assertion failed{{.*}}std::complex<T> requires that T be a cv-unqualified object type}}
+ std::complex<const volatile float> c3;
+}
More information about the libcxx-commits
mailing list