Skip to content

[Clang] Improve testing of non std functions with name infinity #123806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

AmrDeveloper
Copy link
Member

Follow up for improving the test after #123417

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Jan 21, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 21, 2025

@llvm/pr-subscribers-clang

Author: Amr Hesham (AmrDeveloper)

Changes

Follow up for improving the test after #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 --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@+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@+2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
 // no-inf-warning@+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@+2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+    // no-inf-warning@+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@+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@+2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
 // no-inf-warning@+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@+2 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+    // no-inf-warning@+1 {{use of infinity is undefined behavior due to the currently enabled floating-point options}}
+    double d = numeric_limits<double>::infinity();
+  }
   return 0;
 
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants