Skip to content

Commit 521114d

Browse files
authored
[SYCL][NVPTX][AMDGCN] Don't pollute global namespace in cmath wrappers (#19620)
Before this change we defined cmath overloads like `float fabs(float)`, `float fabsf(float)`, `double fabs(double)` in the global namespace. Normally, standard libraries only define the C functions there (`float fabsf(float)`, `double fabs(double)`) when including `<cmath>`. By defining all overloads in the global namespace, we were failing to compile the following code in SYCL mode that works under normal C++ compilation (without offloading): ```cpp #include <cmath> void f(long double x) { // This call is ambiguous, because both `double fabs(double)` and // `float fabs(float)` are defined in the global namespace, but not // `long double fabs(long double)`. auto y = fabs(x); // Note that this works both before and after this change: auto z = std::fabs(x); } ``` This was spotted in Intel internal code, and while it could be argued that this is a bug in that code, I believe we should only break compatibility when it is necessary. This change moves the overloads and templates that are C++-only into the `std` namespace, while keeping the C functions in the global namespace. This is the same behavior as libstdc++ and libc++.
1 parent 730ac88 commit 521114d

File tree

2 files changed

+242
-211
lines changed

2 files changed

+242
-211
lines changed

0 commit comments

Comments
 (0)