[clang] [Clang] Fix warning for non std functions with name `infinity` (PR #123417)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 21 06:43:35 PST 2025


================
@@ -216,11 +244,18 @@ int compareit(float a, float b) {
 
 // no-inf-no-nan-warning at +2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
 // no-inf-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
-  double y = i * numeric_limits<double>::infinity();
+  double y = i * std::numeric_limits<double>::infinity();
+
+  y = i * numeric_limits<double>::infinity(); // expected-no-diagnostics
 
 // no-inf-no-nan-warning at +2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
 // no-inf-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
-  j = numeric_limits<float>::infinity();
+  j = std::numeric_limits<float>::infinity();
+
+  j = numeric_limits<float>::infinity(); // expected-no-diagnostics
+
+  y = infinity(); // expected-no-diagnostics
+
----------------
erichkeane wrote:

I would like a dependent test or two, to make sure we don't get this wrong/double-diagnose :

```
template<typename T>
void foo() {
  std::numeric_limits<T>::infinity();
  std::numeric_limits<double>::infinity();
}

foo<float>();
```

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


More information about the cfe-commits mailing list