[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)
Julian Schmidt via cfe-commits
cfe-commits at lists.llvm.org
Sun Dec 3 13:08:22 PST 2023
================
@@ -128,169 +128,169 @@ void foo(){
const auto Actually2 = 2;
bar::sqrt(Actually2);
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer 'std::numbers::sqrt2' math constant [modernize-use-std-numbers]
// CHECK-FIXES: std::numbers::sqrt2;
exp(1);
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer 'std::numbers::e' math constant [modernize-use-std-numbers]
// CHECK-FIXES: std::numbers::e;
exp(One);
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer 'std::numbers::e' math constant [modernize-use-std-numbers]
// CHECK-FIXES: std::numbers::e;
exp(1.00000000000001);
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer 'std::numbers::e' math constant [modernize-use-std-numbers]
// CHECK-FIXES: std::numbers::e;
log2(exp(1));
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer std::numbers math constant [modernize-use-std-numbers]
- // CHECK-MESSAGES: :[[@LINE-2]]:10: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer 'std::numbers::log2e' math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-2]]:10: warning: prefer 'std::numbers::e' math constant [modernize-use-std-numbers]
// CHECK-FIXES: std::numbers::log2e;
log2(Euler);
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer 'std::numbers::log2e' math constant [modernize-use-std-numbers]
// CHECK-FIXES: std::numbers::log2e;
log2(bar::e);
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer 'std::numbers::log2e' math constant [modernize-use-std-numbers]
// CHECK-FIXES: std::numbers::log2e;
log2(Euler5);
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer 'std::numbers::log2e' math constant [modernize-use-std-numbers]
// CHECK-FIXES: std::numbers::log2e;
log2(Euler6);
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer 'std::numbers::log2e_v<float>' math constant [modernize-use-std-numbers]
// CHECK-FIXES: std::numbers::log2e_v<float>;
log2(NotEuler7);
auto log2e = 1.4426950;
- // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: prefer 'std::numbers::log2e' math constant [modernize-use-std-numbers]
// CHECK-FIXES: auto log2e = std::numbers::log2e;
floatSink(log2(Euler));
- // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'std::numbers::log2e_v<float>' math constant [modernize-use-std-numbers]
// CHECK-FIXES: floatSink(std::numbers::log2e_v<float>);
floatSink(static_cast<float>(log2(Euler)));
- // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer std::numbers math constant [modernize-use-std-numbers]
- // CHECK-MESSAGES: :[[@LINE-2]]:34: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'std::numbers::log2e_v<float>' math constant [modernize-use-std-numbers]
// CHECK-FIXES: floatSink(std::numbers::log2e_v<float>);
floatSink(1.4426950);
- // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'std::numbers::log2e_v<float>' math constant [modernize-use-std-numbers]
// CHECK-FIXES: floatSink(std::numbers::log2e_v<float>);
floatSink(static_cast<float>(1.4426950));
- // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer std::numbers math constant [modernize-use-std-numbers]
- // CHECK-MESSAGES: :[[@LINE-2]]:34: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'std::numbers::log2e_v<float>' math constant [modernize-use-std-numbers]
// CHECK-FIXES: floatSink(std::numbers::log2e_v<float>);
floatSink(log2(static_cast<float>(Euler)));
- // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'std::numbers::log2e_v<float>' math constant [modernize-use-std-numbers]
// CHECK-FIXES: floatSink(std::numbers::log2e_v<float>);
floatSink(static_cast<float>(log2(static_cast<float>(Euler))));
- // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer std::numbers math constant [modernize-use-std-numbers]
- // CHECK-MESSAGES: :[[@LINE-2]]:34: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'std::numbers::log2e_v<float>' math constant [modernize-use-std-numbers]
// CHECK-FIXES: floatSink(std::numbers::log2e_v<float>);
floatSink(static_cast<float>(log2(static_cast<int>(Euler))));
floatSink(static_cast<int>(log2(static_cast<float>(Euler))));
- // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: prefer 'std::numbers::log2e_v<float>' math constant [modernize-use-std-numbers]
// CHECK-FIXES: floatSink(static_cast<int>(std::numbers::log2e_v<float>));
floatSink(1.4426950F);
- // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'std::numbers::log2e_v<float>' math constant [modernize-use-std-numbers]
// CHECK-FIXES: floatSink(std::numbers::log2e_v<float>);
floatSink(static_cast<double>(1.4426950F));
- // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer std::numbers math constant [modernize-use-std-numbers]
- // CHECK-MESSAGES: :[[@LINE-2]]:35: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'std::numbers::log2e_v<float>' math constant [modernize-use-std-numbers]
// CHECK-FIXES: floatSink(std::numbers::log2e_v<float>);
floatSink(static_cast<int>(1.4426950F));
- // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: prefer 'std::numbers::log2e_v<float>' math constant [modernize-use-std-numbers]
// CHECK-FIXES: floatSink(static_cast<int>(std::numbers::log2e_v<float>));
log10(exp(1));
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer std::numbers math constant [modernize-use-std-numbers]
- // CHECK-MESSAGES: :[[@LINE-2]]:11: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer 'std::numbers::log10e' math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-2]]:11: warning: prefer 'std::numbers::e' math constant [modernize-use-std-numbers]
// CHECK-FIXES: std::numbers::log10e;
log10(Euler);
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer 'std::numbers::log10e' math constant [modernize-use-std-numbers]
// CHECK-FIXES: std::numbers::log10e;
log10(bar::e);
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer 'std::numbers::log10e' math constant [modernize-use-std-numbers]
// CHECK-FIXES: std::numbers::log10e;
auto log10e = .434294;
- // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: prefer 'std::numbers::log10e' math constant [modernize-use-std-numbers]
// CHECK-FIXES: auto log10e = std::numbers::log10e;
auto egamma = 0.5772156 * 42;
- // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: prefer 'std::numbers::egamma' math constant [modernize-use-std-numbers]
// CHECK-FIXES: auto egamma = std::numbers::egamma * 42;
sink(InvPi);
sink(1 / Pi);
- // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: prefer 'std::numbers::inv_pi' math constant [modernize-use-std-numbers]
// CHECK-FIXES: sink(std::numbers::inv_pi);
sink(1 / bar::sqrt(Pi));
- // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: prefer 'std::numbers::inv_sqrtpi' math constant [modernize-use-std-numbers]
// CHECK-FIXES: sink(std::numbers::inv_sqrtpi);
sink(1 / bar::sqrt(MY_PI));
- // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: prefer std::numbers math constant [modernize-use-std-numbers]
- // CHECK-MESSAGES: :[[@LINE-2]]:24: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: prefer 'std::numbers::inv_sqrtpi' math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-2]]:24: warning: prefer 'std::numbers::pi' math constant [modernize-use-std-numbers]
// CHECK-FIXES: sink(std::numbers::inv_sqrtpi);
log(2);
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer 'std::numbers::ln2' math constant [modernize-use-std-numbers]
// CHECK-FIXES: std::numbers::ln2;
log(10);
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer 'std::numbers::ln10' math constant [modernize-use-std-numbers]
// CHECK-FIXES: std::numbers::ln10;
bar::sqrt(2);
- // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer 'std::numbers::sqrt2' math constant [modernize-use-std-numbers]
// CHECK-FIXES: std::numbers::sqrt2;
sink(1 / bar::sqrt(3));
- // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: prefer std::numbers math constant [modernize-use-std-numbers]
- // CHECK-MESSAGES: :[[@LINE-2]]:14: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: prefer 'std::numbers::inv_sqrt3' math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-2]]:14: warning: prefer 'std::numbers::sqrt3' math constant [modernize-use-std-numbers]
// CHECK-FIXES: sink(std::numbers::inv_sqrt3);
sink(INV_SQRT3);
- // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: prefer std::numbers math constant [modernize-use-std-numbers]
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: prefer 'std::numbers::inv_sqrt3' math constant [modernize-use-std-numbers]
// CHECK-FIXES: sink(std::numbers::inv_sqrt3);
+ const auto inv_sqrt3f = .577350269F;
----------------
5chmidti wrote:
> Example: [...]
I have added a test for this case
https://github.com/llvm/llvm-project/pull/66583
More information about the cfe-commits
mailing list