[clang] [Clang] Improve testing of non std functions with name infinity (PR #123806)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 21 11:14:56 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Amr Hesham (AmrDeveloper)

<details>
<summary>Changes</summary>

Follow up for improving the test after https://github.com/llvm/llvm-project/pull/123417

---
Full diff: https://github.com/llvm/llvm-project/pull/123806.diff


2 Files Affected:

- (modified) clang/test/Sema/warn-infinity-nan-disabled-lnx.cpp (+12-3) 
- (modified) clang/test/Sema/warn-infinity-nan-disabled-win.cpp (+12-3) 


``````````diff
diff --git a/clang/test/Sema/warn-infinity-nan-disabled-lnx.cpp b/clang/test/Sema/warn-infinity-nan-disabled-lnx.cpp
index 4f46b777c88742..b80d6997c71da6 100644
--- a/clang/test/Sema/warn-infinity-nan-disabled-lnx.cpp
+++ b/clang/test/Sema/warn-infinity-nan-disabled-lnx.cpp
@@ -65,7 +65,7 @@ class numeric_limits {
         return _Ty();
     }
 };
-} // namespace )
+} // namespace std
 }
 
 #define NAN (__builtin_nanf(""))
@@ -87,6 +87,7 @@ class std::numeric_limits<double>  {
     }
 };
 
+namespace nonstd {
 template <class _Ty>
 class numeric_limits {
 public:
@@ -110,6 +111,7 @@ class numeric_limits<double>  {
         return __builtin_huge_val();
     }
 };
+} // namespace nonstd
 
 double infinity() { return 0; }
 
@@ -254,16 +256,23 @@ int compareit(float a, float b) {
 // no-inf-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
   double y = i * std::numeric_limits<double>::infinity();
 
-  y = i * numeric_limits<double>::infinity(); // expected-no-diagnostics
+  y = i * nonstd::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 = std::numeric_limits<float>::infinity();
 
-  j = numeric_limits<float>::infinity(); // expected-no-diagnostics
+  j = nonstd::numeric_limits<float>::infinity(); // expected-no-diagnostics
 
   y = infinity(); // expected-no-diagnostics
 
+  {
+    using namespace std;
+    // 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 d = numeric_limits<double>::infinity();
+  }
+
   return 0;
 
 }
diff --git a/clang/test/Sema/warn-infinity-nan-disabled-win.cpp b/clang/test/Sema/warn-infinity-nan-disabled-win.cpp
index 655024f5909b33..e845fa646fccef 100644
--- a/clang/test/Sema/warn-infinity-nan-disabled-win.cpp
+++ b/clang/test/Sema/warn-infinity-nan-disabled-win.cpp
@@ -69,7 +69,7 @@ class numeric_limits {
     }
 };
 
-} // namespace )
+} // namespace std
 }
 
 #define INFINITY ((float)(1e+300 * 1e+300))
@@ -91,6 +91,7 @@ class std::numeric_limits<double>  {
     }
 };
 
+namespace nonstd {
 template <class _Ty>
 class numeric_limits {
 public:
@@ -115,6 +116,8 @@ class numeric_limits<double>  {
     }
 };
 
+} // namespace nonstd
+
 double infinity() { return 0; }
 
 int compareit(float a, float b) {
@@ -246,16 +249,22 @@ int compareit(float a, float b) {
 // no-inf-warning at +1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
   double y = i * std::numeric_limits<double>::infinity();
 
-  y = i * numeric_limits<double>::infinity(); // expected-no-diagnostics
+  y = i * nonstd::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 = std::numeric_limits<float>::infinity();
 
-  j = numeric_limits<float>::infinity(); // expected-no-diagnostics
+  j = nonstd::numeric_limits<float>::infinity(); // expected-no-diagnostics
 
   y = infinity(); // expected-no-diagnostics
 
+  {
+    using namespace std;
+    // 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 d = numeric_limits<double>::infinity();
+  }
   return 0;
 
 }

``````````

</details>


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


More information about the cfe-commits mailing list