Infinity not constexpr

会有一股神秘感。 提交于 2019-12-03 11:47:29
Barry

I'm not particularly familiar with floating point rules, but I'd suspect that we might be running afoul of [expr]/4:

If during the evaluation of an expression, the result is not mathematically defined or not in the range of representable values for its type, the behavior is undefined.

Which, in turn, means we run afoul of [expr.const]/2.6:

An expression e is a core constant expression unless the evaluation of e, following the rules of the abstract machine, would evaluate one of the following expressions: [...] an operation that would have undefined behavior as specified in [intro] through [cpp] of this document

That means the initializer for foo isn't a constant expression, so we can't initialize a constexpr object with it.


If infinity() - epsilon() is well-defined for float, this is a clang bug, the code is well-formed. If it's not well-defined for float, this is a gcc bug.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!