[libcxx-commits] [libcxx] [libc++][ranges] add static_assert for ranges::to (PR #132528)

via libcxx-commits libcxx-commits at lists.llvm.org
Fri Mar 21 23:37:52 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: Yuzhiy (Yuzhiy05)

<details>
<summary>Changes</summary>

add static_assert  using  is_class_v to  reject no-class type template parameter
fix this [issue](https://github.com/llvm/llvm-project/issues/132133)

---
Full diff: https://github.com/llvm/llvm-project/pull/132528.diff


1 Files Affected:

- (modified) libcxx/include/__ranges/to.h (+4) 


``````````diff
diff --git a/libcxx/include/__ranges/to.h b/libcxx/include/__ranges/to.h
index c937b0656de87..74af572bd0319 100644
--- a/libcxx/include/__ranges/to.h
+++ b/libcxx/include/__ranges/to.h
@@ -81,6 +81,8 @@ template <class _Container, input_range _Range, class... _Args>
   static_assert(!is_const_v<_Container>, "The target container cannot be const-qualified, please remove the const");
   static_assert(
       !is_volatile_v<_Container>, "The target container cannot be volatile-qualified, please remove the volatile");
+  static_assert(
+      is_class_v<_Container>, "The target must be a class type");
 
   // First see if the non-recursive case applies -- the conversion target is either:
   // - a range with a convertible value type;
@@ -208,6 +210,8 @@ template <class _Container, class... _Args>
   static_assert(!is_const_v<_Container>, "The target container cannot be const-qualified, please remove the const");
   static_assert(
       !is_volatile_v<_Container>, "The target container cannot be volatile-qualified, please remove the volatile");
+    static_assert(
+      is_class_v<_Container>, "The target must be a class type");
 
   auto __to_func = []<input_range _Range, class... _Tail>(_Range&& __range, _Tail&&... __tail) static
     requires requires { //

``````````

</details>


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


More information about the libcxx-commits mailing list