[clang-tools-extra] [clang-tidy] add modernize-use-constexpr check (PR #146553)
Sean McBride via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 2 07:26:20 PDT 2025
seanm wrote:
Another compiler error after transformation:
It made this constexpr:
```c++
PUGI_IMPL_FN constexpr bool is_nan(double value)
{
#if defined(PUGI_IMPL_MSVC_CRT_VERSION) || defined(__BORLANDC__)
return !!_isnan(value);
#elif defined(fpclassify) && defined(FP_NAN)
return fpclassify(value) == FP_NAN;
#else
// fallback
const volatile double v = value;
return v != v;
#endif
}
```
But then:
```
/Users/sean/external/VTK/ThirdParty/pugixml/vtkpugixml/src/pugixml.cpp:8413:30: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
8413 | PUGI_IMPL_FN constexpr bool is_nan(double value)
| ^~~~~~
/Users/sean/external/VTK/ThirdParty/pugixml/vtkpugixml/src/pugixml.cpp:8422:15: note: read of volatile-qualified type 'const volatile double' is not allowed in a constant expression
8422 | return v != v;
| ^
```
https://github.com/llvm/llvm-project/pull/146553
More information about the cfe-commits
mailing list