为什么(int&)0格式不正确?

Bri*_*ian 24 c++ casting const-cast static-cast language-lawyer

根据[expr.cast]/4,C风格的强制转换按顺序尝试以下强制转换:

  1. const_cast
  2. static_cast
  3. static_cast 其次是 const_cast
  4. reinterpret_cast
  5. reinterpret_cast 其次是 const_cast

以下演员表格很好:

const_cast<int&>(static_cast<const int&>(0))
Run Code Online (Sandbox Code Playgroud)

然而,GCC和Clang都拒绝演员(int&)0.为什么?

eca*_*mur 4

这是gccclang中的错误。

根据CWG 909,在为 C 风格演员阵容生成演员阵容时应使用“措辞的直接解释”;在那里,第一次转换调用转换运算符,但是没有理由认为当第一次转换是引用绑定临时值时它应该有任何不同。

我已经向 gcc 邮件列表发布了一个从这个 git 分支生成的补丁,但到目前为止它还没有受到任何关注。


归档时间:

查看次数:

434 次

最近记录:

7 年,9 月 前