[英]Iterator traits on pointer to volatile
This code这段代码
#include <iterator>
#include <type_traits>
static_assert(std::is_same_v<typename std::iterator_traits<volatile int *>::value_type, volatile int>);
compiles on latest GCC and clang, but fails on MSVC 2019, that seems to remove volatile
qualifier.在最新的 GCC 和 clang 上编译,但在 MSVC 2019 上失败,这似乎删除了
volatile
限定符。 See here on godbolt .在 godbolt 上看到这里。
The const
is removed, due to the standard specialization of std::iterator_traits for const T*
and T*
, but I think volatile
should be kept.由于
const T*
和T*
的std::iterator_traits的标准专业化, const
被删除,但我认为volatile
应该保留。
Who is right?谁是对的?
Edit: I'm compiling with C++17.编辑:我正在编译 C++17。
Extending the link comment by @康桓瑋 to an answer:将@康汤唯的链接评论扩展为一个答案:
This is LWG issue 2952 .这是LWG 问题 2952 。 Before its resolution
value_type
would be volatile
-qualified, but its resolution changes it to remove the volatile
qualification.在其解析之前
value_type
是volatile
限定的,但其解析将其更改为删除volatile
限定。
The resolution is incorporated into C++20 and MSVC, GCC and Clang all seem to implement it as such.该决议已纳入 C++20 和 MSVC,GCC 和 Clang 似乎都这样实现。 (Meaning that the
static_assert
in the question fails when the compiler is set to C++20 mode.) (这意味着当编译器设置为 C++20 模式时,问题中的
static_assert
失败。)
With regards to whether the resolution should be applied as a defect report to previous revisions of the standard, you can read some discussion here: https://github.com/microsoft/STL/issues/2612 .关于该决议是否应作为标准先前修订版的缺陷报告应用,您可以在此处阅读一些讨论: https://github.com/microsoft/STL/issues/2612 。
It seems that Microsoft's standard library implementation as well as LLVM's libc++ apply the issue resolution also to previous standard revision modes, while GCC's libstdc++ doesn't.似乎 Microsoft 的标准库实现以及 LLVM 的 libc++ 也将问题解决应用于以前的标准修订模式,而 GCC 的 libstdc++ 则没有。 I could not find any bug report or similar discussing the latter's choice.
我找不到任何错误报告或类似的讨论后者的选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.