[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

Piotr Zegar via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 9 00:01:46 PST 2023


https://github.com/PiotrZSL requested changes to this pull request.

Example:
```
llvm/include/llvm/Support/MathExtras.h:59:31: warning: prefer std::numbers math constant [modernize-use-std-numbers]
   59 |                 inv_sqrt3f  = .577350269F, // (0x1.279a74P-1)
      |                               ^~~~~~~~~~~
      |                               std::numbers::egamma_v<float>
```

```
egammaf     = .577215665F
```

Looks like having this check implemented as an multiple matchers isn't a good idea, simply because we pickup first one that match instead a nearest one. This leads to bugs when dealing with proper values.

In ideal conditions something like x* 3.14 should be even detected as PI. 
Also warning message should already say what from std::numbers should be used and how far are current and proposed values from them self.

https://github.com/llvm/llvm-project/pull/66583


More information about the cfe-commits mailing list