Skip to content

Commit dad914f

Browse files
committed
fix no_unique_address
1 parent 73a7a48 commit dad914f

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

libcxx/test/libcxx/ranges/range.adaptors/range.chunk/no_unique_address.compile.pass.cpp

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,30 @@
2222
#include "test_iterators.h"
2323
#include "test_range.h"
2424

25-
using input_view = std::views::all_t<test_range<cpp20_input_iterator>>;
25+
struct input_view {
26+
cpp20_input_iterator<int*> begin() const;
27+
sentinel_wrapper<cpp20_input_iterator<int*>> end() const;
28+
};
29+
template <> inline constexpr bool std::ranges::enable_view<input_view> = true;
2630
static_assert(std::ranges::input_range<input_view> && !std::ranges::forward_range<input_view>);
2731

28-
struct forward_view : std::ranges::view_base {
29-
std::string* begin() const;
30-
std::string* end() const;
32+
struct forward_view {
33+
int* begin() const;
34+
int* end() const;
3135
};
36+
template <> inline constexpr bool std::ranges::enable_view<forward_view> = true;
3237
static_assert(std::ranges::forward_range<forward_view>);
33-
static_assert(std::is_reference_v<std::ranges::range_reference_t<forward_view>>);
34-
35-
template <class View>
36-
struct Test {
37-
[[no_unique_address]] View view;
38-
unsigned char pad;
39-
};
4038

4139
using CV1 = std::ranges::chunk_view<input_view>;
4240
// Expected CV1 (with View == input) layout:
43-
// [[no_unique_address]] _View __base_ // offset: 0
44-
// [[no_unique_address]] range_difference_t<_View> __n_ // offset: sizeof(std::ptrdiff_t)
45-
// [[no_unique_address]] range_difference_t<_View> __remainder_ // offset: sizeof(std::ptrdiff_t)
46-
// [[no_unique_address]] __non_propagating_cache<iterator_t<_View>> __current_ // offset: ?
47-
// TODO: hmmm I'm a pure new C++ learner (having been exposed to C++ for 2 years)
48-
// and I do not know about the memory layout here too...
49-
// What is the layout like?
41+
// [[no_unique_address]] _View __base_ // size: 0
42+
// [[no_unique_address]] range_difference_t<_View> __n_ // size: sizeof(ptrdiff_t)
43+
// [[no_unique_address]] range_difference_t<_View> __remainder_ // size: sizeof(ptrdiff_t)
44+
// [[no_unique_address]] __non_propagating_cache<iterator_t<_View>> __current_ // size: sizeof(__non_propagating_cache<cpp20_input_iterator<int*>>), align: std::ptrdiff_t
45+
static_assert(sizeof(CV1) == /*sizeof(__base_) == 0 + */ sizeof(std::ptrdiff_t) * 2 + sizeof(std::ranges::__non_propagating_cache<cpp20_input_iterator<int*>>));
5046

5147
using CV2 = std::ranges::chunk_view<forward_view>;
5248
// Expected CV2 (with View >= forward) layout:
53-
// [[no_unique_address]] _View __base_ // offset: 0
54-
// [[no_unique_address]] range_difference_t<_View> // offset: sizeof(std::ptrdiff_t)
55-
static_assert(sizeof(CV2) == sizeof(std::ptrdiff_t));
56-
static_assert(sizeof(Test<CV2>) == sizeof(std::ptrdiff_t) * 2);
49+
// [[no_unique_address]] _View __base_ // size: 0
50+
// [[no_unique_address]] range_difference_t<_View> // size: sizeof(ptrdiff_t)
51+
static_assert(sizeof(CV2) == /*sizeof(__base_) == 0 + */ sizeof(std::ptrdiff_t));

0 commit comments

Comments
 (0)