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

标签 c++ c++11 g++ tuples language-lawyer

我注意到 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/

相关文章:

c++ - 为什么将引用分配给非引用会改变其动态行为

c++ - 三次贝塞尔曲线是否完全包含在其控制点的边界框内?

python - if 语句范围内的 C++ 宏未编译

C++ Winsock 确定 HTTP 或 HTTPS

c++ - AX 解析器生成器和 mingw gcc 4.6 运算符 &

c++ - 在 G++ 编译命令中包含 -std=c++0x 有什么意义?

c++ - 为什么访问嵌套类型会影响 C++ 中的成员解析?

c++ - 传递带参数的 lambda

C++ - Makefile 良好实践

c++ - gcc/g++ 对空主函数给出不同的响应