Skip to content

Duplicate diagnostics on use of NAN #98018

Closed
@AaronBallman

Description

@AaronBallman

When in finite math-only mode, we issue two diagnostics for use of NAN but only one for use of INFINITY: https://godbolt.org/z/4YYhaTzx9

#include <math.h>

_Static_assert(_Generic(INFINITY, float : 1, default : 0), "");
_Static_assert(_Generic(NAN, float : 1, default : 0), "");

produces:

<source>:3:25: warning: use of infinity via a macro is undefined behavior due to the currently enabled floating-point options [-Wnan-infinity-disabled]
    3 | _Static_assert(_Generic(INFINITY, float : 1, default : 0), "");
      |                         ^
<source>:4:25: warning: use of NaN via a macro is undefined behavior due to the currently enabled floating-point options [-Wnan-infinity-disabled]
    4 | _Static_assert(_Generic(NAN, float : 1, default : 0), "");
      |                         ^
<source>:4:25: warning: use of NaN is undefined behavior due to the currently enabled floating-point options [-Wnan-infinity-disabled]
    4 | _Static_assert(_Generic(NAN, float : 1, default : 0), "");
      |                         ^~~
/usr/include/math.h:98:16: note: expanded from macro 'NAN'
   98 | #  define NAN (__builtin_nanf (""))
      |                ^~~~~~~~~~~~~~~~~~~
3 warnings generated.

Metadata

Metadata

Assignees

Labels

c23clang:headersHeaders provided by Clang, e.g. for intrinsics

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions