gpt4 book ai didi

c++ - libstdc++ 拒绝将 volatile 右值分配给 std::ignore 是错误的吗?

转载 作者:可可西里 更新时间:2023-11-01 18:38:59 26 4
gpt4 key购买 nike

我注意到 libstdc++ 的 std::ignore 实现采用了 const T& 参数,它不能绑定(bind)到 volatile 右值。因此,以下代码无法编译:

#include <tuple>
#include <utility>
struct C {};
using VC = C volatile;
int main() {
std::tuple<VC> t;
std::tie(std::ignore) = std::move(t);
}

( http://coliru.stacked-crooked.com/a/7bfc499c1748e59e )

这是否违反了标准,或者是否存在导致这种未定义行为的条款?

最佳答案

我不是语言律师,所以我将尽可能直接地回答这个问题。

ignore可在 tuple 的概要中找到在 tuple.general 因此:

// [tuple.creation], tuple creation functions:
const unspecified ignore;

如您所见,libstdc++实现定义 ignore像这样:

  // A class (and instance) which can be used in 'tie' when an element
// of a tuple is not required
struct _Swallow_assign
{
template<class _Tp>
const _Swallow_assign&
operator=(const _Tp&) const
{ return *this; }
};

libc++版本定义如下:

template <class _Up>
struct __ignore_t
{
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
const __ignore_t& operator=(_Tp&&) const {return *this;}
};

因此,它在 libc++ 中编译。现在定义 std::tie 可以在 [tuple.creation] 中找到:

Returns: tuple<Types&...>(t...). When an argument in t is ignore, assigning any value to the corresponding tuple element has no effect.

这并没有说明 ignore本身,所以我要把这归因于未指定的行为。您可以通过遗漏争辩说它是未定义行为,但这可能会夸大其词。

关于c++ - libstdc++ 拒绝将 volatile 右值分配给 std::ignore 是错误的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37932676/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com