[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:08 PDT 2025
https://github.com/Yuzhiy05 created https://github.com/llvm/llvm-project/pull/132528
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)
>From 42e05f2dff7e5e25f1a0a705246c63a33aedd323 Mon Sep 17 00:00:00 2001
From: Yuzhiy <44502685+Yuzhiy05 at users.noreply.github.com>
Date: Sat, 22 Mar 2025 14:21:53 +0800
Subject: [PATCH] [libc++][ranges] add static_assert for ranges::to
fix this [issue](https://github.com/llvm/llvm-project/issues/132133)
---
libcxx/include/__ranges/to.h | 4 ++++
1 file changed, 4 insertions(+)
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 { //
More information about the libcxx-commits
mailing list