sizeof int是合法的c语言表达式,不评估应用sizeof的表达式是否合法取消引用C中sizeof中的null或无效指针?...

我相信这个标准现在在

What is the value category of the operands of C++ operators when unspecified?这样的许多问题上已经不明确了.我不认为这是有意的,像hvd指出,这对委员会来说可能是显而易见的.

It is mildly distasteful to dereference a null pointer as part of our specification,as we are playing on the edges of undefined behavIoUr. With the addition of the declval function template,already used in these same expressions,this is no longer necessary.

并提出了一个替代表达式,它指的是这个不再是标准的表达式,但可以在N3090中找到:

noexcept(*(U*)0 = declval())

这个建议被拒绝了,因为它没有引起未定义的行为,因为它不被评估:

There is no undefined behavior because the expression is an unevaluated operand. It’s not at all clear that the proposed change would be clearer.

这个理由也适用于sizeof,因为它的操作数被忽略.

我说不明确,但我不知道这是否由4.1 [conv.lval]涵盖,其中说:

The value contained in the object indicated by the lvalue is the rvalue result. When an lvalue-to-rvalue conversion occurs

within the operand of sizeof (5.3.3) the value contained in the referenced object is not accessed,since that operator

does not evaluate its operand.

它说所包含的值不被访问,如果我们遵循issue 232的逻辑意味着没有未定义的行为:

In other words,it is only the act of “fetching”,of lvalue-to-rvalue conversion,that triggers the ill-formed or undefined behavior

这是有点投机的,因为问题还没有解决.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值