Skip to content

[C23] constexpr incorrectly rejects infinity and nan #101499

Open
@AaronBallman

Description

@AaronBallman

Consider:

constexpr float inf = 1.0f / 0.0f;
constexpr float nan = 0.0f / 0.0f;

Clang currently rejects these, while GCC accepts: https://godbolt.org/z/oG4sP9TMc

I believe Clang is wrong to reject, per C23 6.5.6p6-7 for division, 5.2.5.3.3p19 for infinity being a valid value, 6.7.2p5-6 for constexpr requirements, and 6.6p4 for constant initialization requirements.

Note, __builtin_inff() and __builtin_nan() both work as an initializer for a constexpr variable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c23clang:frontendLanguage frontend issues, e.g. anything involving "Sema"constexprAnything related to constant evaluationrejects-valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions