Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<cmath>: can't pass integer types to std::isnan #4747

Closed
zygoloid opened this issue Jun 25, 2024 · 3 comments
Closed

<cmath>: can't pass integer types to std::isnan #4747

zygoloid opened this issue Jun 25, 2024 · 3 comments
Labels
bug Something isn't working fixed Something works now, yay!

Comments

@zygoloid
Copy link

Describe the bug

std::isnan fails to compile when passed an argument of integer type.

Command-line test case

#include <cmath>
bool b = std::isnan(0);

results in:

/opt/compiler-explorer/windows/10.0.10240.0/ucrt/math.h(403): error C2668: 'fpclassify': ambiguous call to overloaded function
/opt/compiler-explorer/windows/10.0.10240.0/ucrt/math.h(288): note: could be 'int fpclassify(long double) noexcept'
/opt/compiler-explorer/windows/10.0.10240.0/ucrt/math.h(283): note: or       'int fpclassify(double) noexcept'
/opt/compiler-explorer/windows/10.0.10240.0/ucrt/math.h(278): note: or       'int fpclassify(float) noexcept'
/opt/compiler-explorer/windows/10.0.10240.0/ucrt/math.h(403): note: while trying to match the argument list '(int)'
<source>(3): note: see reference to function template instantiation 'bool isnan<int>(_Ty) noexcept' being compiled
        with
        [
            _Ty=int
        ]
Compiler returned: 2

Live on compiler explorer

Expected behavior

<cmath> is required to provide sufficient additional overloads such that std::isnan can be applied to integer types, with the behavior that the integer value is implicitly converted to double (so that std::isnan(0) returns false). This doesn't appear to work under MSVC.

@zygoloid
Copy link
Author

Relevant standard rule

@frederick-vs-ja
Copy link
Contributor

frederick-vs-ja commented Jun 25, 2024

Duplicate of #519. Other duplicates: #908, #3400.

This is (partially) fixed by #4537. The remain issue, additional overloads missing in <math.h> in C++ mode, is out of the scope of this repo. I opened DevCom-10294165 but it was recently closed as Lower Priority...

@StephanTLavavej StephanTLavavej added bug Something isn't working fixed Something works now, yay! labels Jun 26, 2024
@StephanTLavavej
Copy link
Member

Yep, @frederick-vs-ja is correct, this is fixed for <cmath>. #4537 shipped in VS 2022 17.11 Preview 2 which is available now. (Compiler Explorer got actual MSVC compilation and execution back 🎉 but is currently limited to 17.8).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed Something works now, yay!
Projects
None yet
Development

No branches or pull requests

3 participants