Skip to content

Commit ec5c94a

Browse files
committed
format file and test for other type be rejected
1 parent f2c5057 commit ec5c94a

File tree

2 files changed

+64
-12
lines changed
  • libcxx

2 files changed

+64
-12
lines changed

libcxx/include/__ranges/to.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
#include <__ranges/size.h>
2727
#include <__ranges/transform_view.h>
2828
#include <__type_traits/add_pointer.h>
29-
#include <__type_traits/is_const.h>
30-
#include <__type_traits/is_volatile.h>
3129
#include <__type_traits/is_class.h>
30+
#include <__type_traits/is_const.h>
3231
#include <__type_traits/is_union.h>
32+
#include <__type_traits/is_volatile.h>
3333
#include <__type_traits/type_identity.h>
3434
#include <__utility/declval.h>
3535
#include <__utility/forward.h>
@@ -83,7 +83,7 @@ template <class _Container, input_range _Range, class... _Args>
8383
static_assert(!is_const_v<_Container>, "The target container cannot be const-qualified, please remove the const");
8484
static_assert(
8585
!is_volatile_v<_Container>, "The target container cannot be volatile-qualified, please remove the volatile");
86-
static_assert(is_class_v<_Container>||is_union_v<_Container>, "The target must be a class type");
86+
static_assert(is_class_v<_Container> || is_union_v<_Container>, "The target must be a class type");
8787
// First see if the non-recursive case applies -- the conversion target is either:
8888
// - a range with a convertible value type;
8989
// - a non-range type which might support being created from the input argument(s) (e.g. an `optional`).
@@ -210,7 +210,7 @@ template <class _Container, class... _Args>
210210
static_assert(!is_const_v<_Container>, "The target container cannot be const-qualified, please remove the const");
211211
static_assert(
212212
!is_volatile_v<_Container>, "The target container cannot be volatile-qualified, please remove the volatile");
213-
static_assert(is_class_v<_Container>||is_union_v<_Container>, "The target must be a class type");
213+
static_assert(is_class_v<_Container> || is_union_v<_Container>, "The target must be a class type");
214214
auto __to_func = []<input_range _Range, class... _Tail>(_Range&& __range, _Tail&&... __tail) static
215215
requires requires { //
216216
/**/ ranges::to<_Container>(std::forward<_Range>(__range), std::forward<_Tail>(__tail)...);

libcxx/test/libcxx/ranges/range.utility/range.utility.conv/to.verify.cpp

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,72 @@
88

99
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
1010

11-
1211
// Test that the "mandates" requirements on the given class are checked using `static_assert`.
1312
#include <ranges>
14-
13+
void ff() {}
1514
void test() {
15+
struct C {
16+
int member;
17+
int f() { return 0; }
18+
};
19+
20+
enum color { red, green, blue };
21+
using member_func_ptr = decltype(&C::f);
22+
using member_ptr = decltype(&C::member);
23+
using func_ptr = decltype(&ff);
24+
using func_t = decltype(ff);
25+
1626
struct R {
17-
int* begin() const { reurn nullptr; };
27+
int* begin() const { return nullptr; };
1828
int* end() const { return nullptr; };
1929

2030
operator int() const { return 0; }
31+
operator int*() const { return nullptr; }
32+
operator func_ptr() const { return nullptr; }
33+
operator void() const {}
34+
operator member_func_ptr() const { return nullptr; }
35+
operator member_ptr() const { return nullptr; }
36+
operator color() const { return color::red; }
2137
};
22-
(void)std::ranges::to<int>(R{});
23-
//expected-error-re@*:* {{static assertion failed{{.*}}The target must be a class type}}
24-
(void)(R{} | std::ranges::to<int>());
25-
//expected-error-re@*:* {{static assertion failed{{.*}}The target must be a class type}}
26-
38+
(void)std::ranges::to<int>(
39+
R{}); //expected-error-re@*:* {{static assertion failed{{.*}}The target must be a class type}}
40+
(void)(R{} | std::ranges::to<
41+
int>()); //expected-error-re@*:* {{static assertion failed{{.*}}The target must be a class type}}
42+
(void)std::ranges::to<int*>(
43+
R{}); //expected-error-re@*:* {{static assertion failed{{.*}}The target must be a class type}}
44+
(void)(R{} | std::ranges::to<
45+
int*>()); //expected-error-re@*:* {{static assertion failed{{.*}}The target must be a class type}}
46+
(void)std::ranges::to<func_ptr>(
47+
R{}); //expected-error-re@*:* {{static assertion failed{{.*}}The target must be a class type}}
48+
(void)(R{} |
49+
std::ranges::to<
50+
func_ptr>()); //expected-error-re@*:* {{static assertion failed{{.*}}The target must be a class type}}
51+
52+
(void)std::ranges::to<void>(
53+
R{}); //expected-error-re@*:* {{static assertion failed{{.*}}The target must be a class type}}
54+
(void)(R{} | std::ranges::to<
55+
void>()); //expected-error-re@*:* {{static assertion failed{{.*}}The target must be a class type}}
56+
(void)std::ranges::to<member_ptr>(
57+
R{}); //expected-error-re@*:* {{static assertion failed{{.*}}The target must be a class type}}
58+
(void)(R{} |
59+
std::ranges::to<
60+
member_ptr>()); //expected-error-re@*:* {{static assertion failed{{.*}}The target must be a class type}}
61+
(void)std::ranges::to<member_func_ptr>(
62+
R{}); //expected-error-re@*:* {{static assertion failed{{.*}}The target must be a class type}}
63+
(void)(R{} |
64+
std::ranges::to<
65+
member_func_ptr>()); //expected-error-re@*:* {{static assertion failed{{.*}}The target must be a class type}}
66+
(void)std::ranges::to<func_ptr>(
67+
R{}); //expected-error-re@*:* {{static assertion failed{{.*}}The target must be a class type}}
68+
(void)(R{} |
69+
std::ranges::to<
70+
func_ptr>()); //expected-error-re@*:* {{static assertion failed{{.*}}The target must be a class type}}
71+
(void)std::ranges::to<color>(
72+
R{}); //expected-error-re@*:* {{static assertion failed{{.*}}The target must be a class type}}
73+
(void)(R{} | std::ranges::to<
74+
color>()); //expected-error-re@*:* {{static assertion failed{{.*}}The target must be a class type}}
75+
(void)std::ranges::to<func_t>(
76+
R{}); //expected-error-re@*:* {{static assertion failed{{.*}}The target must be a class type}}
77+
(void)(R{} | std::ranges::to<
78+
func_t>()); //expected-error-re@*:* {{static assertion failed{{.*}}The target must be a class type}}
2779
}

0 commit comments

Comments
 (0)