[libcxx] Wrap [[no_unique_address]] in a macro, for clang-cl

This should silence all remaining clang-cl build warnings.

Differential Revision: https://reviews.llvm.org/D119430
This commit is contained in:
Martin Storsjö 2022-02-10 13:23:40 +02:00
parent 99ed84242f
commit 8a0a706f09
13 changed files with 46 additions and 24 deletions

View File

@ -26,9 +26,9 @@ namespace ranges {
template <class _I1, class _I2, class _O1>
struct in_in_out_result {
[[no_unique_address]] _I1 in1;
[[no_unique_address]] _I2 in2;
[[no_unique_address]] _O1 out;
_LIBCPP_NO_UNIQUE_ADDRESS _I1 in1;
_LIBCPP_NO_UNIQUE_ADDRESS _I2 in2;
_LIBCPP_NO_UNIQUE_ADDRESS _O1 out;
template <class _II1, class _II2, class _OO1>
requires convertible_to<const _I1&, _II1> && convertible_to<const _I2&, _II2> && convertible_to<const _O1&, _OO1>

View File

@ -26,8 +26,8 @@ namespace ranges {
template <class _I1, class _I2>
struct in_in_result {
[[no_unique_address]] _I1 in1;
[[no_unique_address]] _I2 in2;
_LIBCPP_NO_UNIQUE_ADDRESS _I1 in1;
_LIBCPP_NO_UNIQUE_ADDRESS _I2 in2;
template <class _II1, class _II2>
requires convertible_to<const _I1&, _II1> && convertible_to<const _I2&, _II2>

View File

@ -25,9 +25,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
namespace ranges {
template <class _I1, class _O1, class _O2>
struct in_out_out_result {
[[no_unique_address]] _I1 in;
[[no_unique_address]] _O1 out1;
[[no_unique_address]] _O2 out2;
_LIBCPP_NO_UNIQUE_ADDRESS _I1 in;
_LIBCPP_NO_UNIQUE_ADDRESS _O1 out1;
_LIBCPP_NO_UNIQUE_ADDRESS _O2 out2;
template <class _II1, class _OO1, class _OO2>
requires convertible_to<const _I1&, _II1> && convertible_to<const _O1&, _OO1> && convertible_to<const _O2&, _OO2>

View File

@ -26,8 +26,8 @@ namespace ranges {
template<class _InputIterator, class _OutputIterator>
struct in_out_result {
[[no_unique_address]] _InputIterator in;
[[no_unique_address]] _OutputIterator out;
_LIBCPP_NO_UNIQUE_ADDRESS _InputIterator in;
_LIBCPP_NO_UNIQUE_ADDRESS _OutputIterator out;
template <class _InputIterator2, class _OutputIterator2>
requires convertible_to<const _InputIterator&, _InputIterator2> && convertible_to<const _OutputIterator&,

View File

@ -1398,6 +1398,28 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */
#endif
#if __has_cpp_attribute(msvc::no_unique_address)
// MSVC implements [[no_unique_address]] as a silent no-op currently.
// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.)
// However, MSVC implements [[msvc::no_unique_address]] which does what
// [[no_unique_address]] is supposed to do, in general.
// Clang-cl does not yet (14.0) implement either [[no_unique_address]] or
// [[msvc::no_unique_address]] though. If/when it does implement
// [[msvc::no_unique_address]], this should be preferred though.
# define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
#elif __has_cpp_attribute(no_unique_address)
# define _LIBCPP_NO_UNIQUE_ADDRESS [[no_unique_address]]
#else
# define _LIBCPP_NO_UNIQUE_ADDRESS /* nothing */
// Note that this can be replaced by #error as soon as clang-cl
// implements msvc::no_unique_address, since there should be no C++20
// compiler that doesn't support one of the two attributes at that point.
// We geenrally don't want to use this macro outside of C++20-only code,
// because using it conditionally in one language version only would make
// the ABI inconsistent.
#endif
#endif // __cplusplus
#endif // _LIBCPP_CONFIG

View File

@ -65,7 +65,7 @@ class counted_iterator
, public __counted_iterator_value_type<_Iter>
{
public:
[[no_unique_address]] _Iter __current_ = _Iter();
_LIBCPP_NO_UNIQUE_ADDRESS _Iter __current_ = _Iter();
iter_difference_t<_Iter> __count_ = 0;
using iterator_type = _Iter;

View File

@ -41,7 +41,7 @@ namespace ranges {
// Primary template - uses std::optional and introduces an empty state in case assignment fails.
template<__copy_constructible_object _Tp>
class __copyable_box {
[[no_unique_address]] optional<_Tp> __val_;
_LIBCPP_NO_UNIQUE_ADDRESS optional<_Tp> __val_;
public:
template<class ..._Args>
@ -116,7 +116,7 @@ namespace ranges {
template<__copy_constructible_object _Tp>
requires __doesnt_need_empty_state_for_copy<_Tp> && __doesnt_need_empty_state_for_move<_Tp>
class __copyable_box<_Tp> {
[[no_unique_address]] _Tp __val_;
_LIBCPP_NO_UNIQUE_ADDRESS _Tp __val_;
public:
template<class ..._Args>

View File

@ -45,7 +45,7 @@ namespace ranges {
// one can't call begin() on it more than once.
static constexpr bool _UseCache = forward_range<_View> && !(random_access_range<_View> && sized_range<_View>);
using _Cache = _If<_UseCache, __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
[[no_unique_address]] _Cache __cached_begin_ = _Cache();
_LIBCPP_NO_UNIQUE_ADDRESS _Cache __cached_begin_ = _Cache();
range_difference_t<_View> __count_ = 0;
_View __base_ = _View();

View File

@ -67,7 +67,7 @@ namespace ranges {
static constexpr bool _UseCache = !is_reference_v<_InnerRange>;
using _Cache = _If<_UseCache, __non_propagating_cache<remove_cvref_t<_InnerRange>>, __empty_cache>;
[[no_unique_address]] _Cache __cache_;
_LIBCPP_NO_UNIQUE_ADDRESS _Cache __cache_;
_View __base_ = _View(); // TODO: [[no_unique_address]] makes clang crash! File a bug :)
public:

View File

@ -43,8 +43,8 @@ namespace ranges {
// amortized O(1) begin() method.
static constexpr bool _UseCache = !random_access_range<_View> && !common_range<_View>;
using _Cache = _If<_UseCache, __non_propagating_cache<reverse_iterator<iterator_t<_View>>>, __empty_cache>;
[[no_unique_address]] _Cache __cached_begin_ = _Cache();
[[no_unique_address]] _View __base_ = _View();
_LIBCPP_NO_UNIQUE_ADDRESS _Cache __cached_begin_ = _Cache();
_LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View();
public:
_LIBCPP_HIDE_FROM_ABI

View File

@ -82,9 +82,9 @@ namespace ranges {
static constexpr bool _MustProvideSizeAtConstruction = !_StoreSize; // just to improve compiler diagnostics
struct _Empty { constexpr _Empty(auto) noexcept { } };
using _Size = conditional_t<_StoreSize, make_unsigned_t<iter_difference_t<_Iter>>, _Empty>;
[[no_unique_address]] _Iter __begin_ = _Iter();
[[no_unique_address]] _Sent __end_ = _Sent();
[[no_unique_address]] _Size __size_ = 0;
_LIBCPP_NO_UNIQUE_ADDRESS _Iter __begin_ = _Iter();
_LIBCPP_NO_UNIQUE_ADDRESS _Sent __end_ = _Sent();
_LIBCPP_NO_UNIQUE_ADDRESS _Size __size_ = 0;
public:
_LIBCPP_HIDE_FROM_ABI

View File

@ -39,7 +39,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
namespace ranges {
template<view _View>
class take_view : public view_interface<take_view<_View>> {
[[no_unique_address]] _View __base_ = _View();
_LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View();
range_difference_t<_View> __count_ = 0;
template<bool> class __sentinel;
@ -136,7 +136,7 @@ namespace ranges {
using _Base = __maybe_const<_Const, _View>;
template<bool _OtherConst>
using _Iter = counted_iterator<iterator_t<__maybe_const<_OtherConst, _View>>>;
[[no_unique_address]] sentinel_t<_Base> __end_ = sentinel_t<_Base>();
_LIBCPP_NO_UNIQUE_ADDRESS sentinel_t<_Base> __end_ = sentinel_t<_Base>();
template<bool>
friend class take_view<_View>::__sentinel;

View File

@ -61,8 +61,8 @@ class transform_view : public view_interface<transform_view<_View, _Fn>> {
template<bool> class __iterator;
template<bool> class __sentinel;
[[no_unique_address]] __copyable_box<_Fn> __func_;
[[no_unique_address]] _View __base_ = _View();
_LIBCPP_NO_UNIQUE_ADDRESS __copyable_box<_Fn> __func_;
_LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View();
public:
_LIBCPP_HIDE_FROM_ABI