libc++ 持续时间隐藏警告不正确
libc++ duration hiding warnings incorrectly?
以下代码在没有警告的情况下工作:
std::chrono::duration<unsigned int> d{-17};
我希望收到与我相同的警告:
unsigned int x = -17;
以下是相关代码:
template<typename _Rep2, typename = typename
enable_if<is_convertible<_Rep2, rep>::value
&& (treat_as_floating_point<rep>::value
|| !treat_as_floating_point<_Rep2>::value)>::type>
explicit duration(const _Rep2& __rep)
: __r(static_cast<rep>(__rep)) { }
static_cast隐藏了警告,在我看来,标准要求的任何功能都不需要它。这只是一个libc++问题,还是标准要求以这种方式工作?
这是标准预期的行为。对该构造函数的注释是:
此构造函数不应参与重载解析,除非
Rep2
可转换为rep
和
(1.1) —treat_as_floating_point_v<rep>
true
或
(1.2) —treat_as_floating_point_v<Rep2>
false
.
int
隐式转换为unsigned int
,treat_as_floating_point<int>
false
,所以我们很好。
效果是:
后置条件:
count()
==static_cast<rep>(r)
。
libc++ 和 libstdc++ 都通过允许你编写的代码来符合要求。它的格式良好。如果您认为它的格式不正确,则应提交有关它的问题。这不是编译器错误。这可能是一个标准错误。
相关文章:
- 使用2个键的cpp-stl::优先级队列排序不正确
- g++ 在某个类成员未初始化时不发出警告
- 正弦级数方程计算不正确
- 我试图制作一个程序,要求用户输入问题和答案,但程序循环不正确
- 密码登录程序将永远循环并显示不正确的结果
- 在C++中返回不正确的楼层函数值
- 形状对象的旋转和缩放不正确C++
- C++ 读取文件读取文件不正确
- 关于类的 Python 文档 - 对C++的引用不正确
- 特征 LLT 模块给出不正确的结果?
- glibcxx STL 在实现 std::valarray::sum() 时是否不正确?
- 如果语句逻辑不正确
- 来自逆 vp 矩阵和相机位置的光线方向不正确
- 不正确的操作数类型 MSVC
- [[maybe_unused]] 在成员变量上,GCC 警告(不正确?)该属性被忽略
- 如何正确使用ReadProcessMemory而不引发警告
- libc++ 持续时间隐藏警告不正确
- clang和gcc中的这个警告似乎不正确
- 缺少编译器警告,大括号初始值设定项不正确
- libpng 警告:iCCP:已知不正确的 sRGB 配置文件