Skip to content

Commit 3a73fac

Browse files
committed
Usa [[no_unique_address]] in join_with_view::sentinel
1 parent 6778426 commit 3a73fac

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

libcxx/include/__ranges/join_with_view.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ struct join_with_view<_View, _Pattern>::__sentinel {
400400
using _Parent = __maybe_const<_Const, join_with_view>;
401401
using _Base = __maybe_const<_Const, _View>;
402402

403-
sentinel_t<_Base> __end_ = sentinel_t<_Base>();
403+
_LIBCPP_NO_UNIQUE_ADDRESS sentinel_t<_Base> __end_ = sentinel_t<_Base>();
404404

405405
_LIBCPP_HIDE_FROM_ABI constexpr explicit __sentinel(_Parent& __parent) : __end_(ranges::end(__parent.__base_)) {}
406406

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10+
11+
// XFAIL: msvc
12+
13+
// <ranges>
14+
15+
// This test ensures that we use `[[no_unique_address]]` in `join_with_view::sentinel`.
16+
17+
#include <cstddef>
18+
#include <ranges>
19+
#include <string_view>
20+
21+
template <bool Const>
22+
struct Iter {
23+
using value_type = std::string_view;
24+
using difference_type = std::ptrdiff_t;
25+
26+
Iter& operator++();
27+
Iter operator++(int);
28+
value_type& operator*() const;
29+
bool operator==(const Iter&) const;
30+
bool operator==(std::default_sentinel_t) const;
31+
};
32+
33+
struct View : std::ranges::view_base {
34+
Iter<false> begin();
35+
Iter<true> begin() const;
36+
std::default_sentinel_t end() const;
37+
};
38+
39+
using JWV = std::ranges::join_with_view<View, std::string_view>;
40+
41+
template <class View>
42+
struct Test {
43+
[[no_unique_address]] std::ranges::sentinel_t<View> se;
44+
unsigned char pad;
45+
};
46+
47+
static_assert(sizeof(Test<JWV>) == 1);
48+
static_assert(sizeof(Test<const JWV>) == 1);

0 commit comments

Comments
 (0)