Skip to content

[expr] It is underspecified when evaluating an operation whose operands have values designated NaN  #5407

@xmh0511

Description

@xmh0511

Consider this example

auto sNaN = std::numeric_limits<float>::signaling_NaN();
auto r0 = sNaN  +  0;
bool r1 = sNaN  == 0;
bool r2 = sNaN  != sNaN;
auto r3 = sNaN  * 1;
auto r4 = sNaN  / 1;
int n = sNaN ;
unsigned int un = sNaN ;

I only list parts of operators that are unclear to NaN, in every subclause that corresponds to the operator or conversion used the above, we do not have a wording that can define what the result is. The only possible relevant wording is in [expr.pre] p4

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.

It is unclear whether NaN is mathematically defined. If it were not, it would mean that even the following example also is UB

auto sNaN = std::numeric_limits<float>::signaling_NaN();
int c = (sNaN , 10);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions