【发布时间】:2015-05-15 03:25:34
【问题描述】:
给定以下函数:
void g(int **p1, const int**p2)
{
if (p1 == p2) { }
}
clang(回到版本 3.0) 产生这个警告 (see it live):
warning: comparison of distinct pointer types ('int **' and 'const int **')
uses non-standard composite pointer type 'const int *const *'
[-Wcompare-distinct-pointer-types]
if (p1 == p2) { }
~~ ^ ~~
使用-pedantic-errors 标志会将其变为错误。 gcc(回到 4.3.6) 和 Visual Studio(2013) 都不会产生警告,根据标准,是比较:
p1 == p2
结构良好?
更一般地,如果两个多级指针的 cv-qualifications 不同,而不是在第一级是通过相等运算符或格式良好的关系运算符进行比较?
【问题讨论】:
-
知道非常有用,点赞。希望 msvc 和 g++ 在实现 c++14 时效仿。
-
@Cheersandhth.-如果 Alf gcc 和 VS 在没有警告或错误的情况下允许此代码,则它们已经遵循 C++14;铿锵声需要修复
-
@MattMcNabb:谢谢。我脑子里有一些二进制切换。
-
@Cheersandhth.-Alf 在我的回答中添加了五年前的 clang 提交,表明这被 clang、gcc 和 EDG 视为扩展,我也认为是 VS。会议上注意到它被接受,它表明这改变只是编纂了现有的做法。
标签: c++ c++11 language-lawyer c++14