<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/61629>61629</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            CUDA/Clang-16/C++2b: std::isfinite is incorrectly resolved as isfinite from __clang_cuda_cmath.h
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          andrewcorrigan
      </td>
    </tr>
</table>

<pre>
    I have a minimal reproducer below which fails with:
- `clang-16`, `-std=c++2b`

But, compiles with:
- `clang-16`, `-std=c++20`
- `clang-15`, `-std=c++20`
- `clang-15`, `-std=c++2b`

Minimal reproducer:

```cpp
#include <cuda.h>
#include <cuda_runtime_api.h>

#include <numeric>

int main(int argc, char** argv)
{
    auto test = [&](auto x)
    {
        return std::isfinite(x);
    };

 test(-1.0f);

    return 0;
}
```

This compiles in C++20 mode with Clang-16, as well as both C++20 and C++2b mode with Clang-15:
```
% /install/llvm-16.0.0/bin/clang++ -std=c++2b -x cuda test.cpp 
% /install/llvm-15.0.0/bin/clang++ -std=c++2b -x cuda test.cpp 
% /install/llvm-15.0.0/bin/clang++ -std=c++20 -x cuda test.cpp 
```

However, the reproducer above fails to compile in C++2b mode with Clang-16
```
% /install/llvm-16.0.0/bin/clang++ -std=c++2b -x cuda test.cpp 
test.cpp:10:21: error: reference to __device__ function 'isfinite' in __host__ __device__ function
        return std::isfinite(x);
                    ^
test.cpp:13:9: note: called by 'main'
    test(-1.0f);
 ^
/install/llvm-16.0.0/lib/clang/16/include/__clang_cuda_cmath.h:103:17: note: 'isfinite' declared here
__DEVICE__ bool isfinite(float __x) { return ::__finitef(__x); }
                ^
test.cpp:10:21: error: reference to __device__ function 'isfinite' in __host__ __device__ function
        return std::isfinite(x);
 ^
test.cpp:14:9: note: called by 'main'
    test(-2.0);
 ^
/install/llvm-16.0.0/lib/clang/16/include/__clang_cuda_cmath.h:107:17: note: 'isfinite' declared here
__DEVICE__ bool isfinite(double __x) { return ::__isfinited(__x); }
                ^
2 errors generated when compiling for host.
```



</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVk2vozYU_TXO5iqRMYGEBQuSPNRZdNd2axlzCa6MHRmTzPz7ypCENC_z1D6Npo0iPuxzL9fnHF8Qfa-OBjEnyY4kh4UYfGtdLkzt8CKtc-oozKKy9bf8C7TijCCgU0Z1QoPDk7P1INFBhdpe4NIq2UIjlO7honxL4oLQA6HFEkhKpRbmuIxSklLC9mFk2fuaxAdJ2I6wHavCzIifjrvBB6C03Ulp_FRKek_5iE9-GP655F_fUXMv-HpM6fSXp9N1hMXKSD3UCCTey6EWq5bEb9-b5G4wXnXIxUk9Al_AzdChU_IJo4yHTihD2DZcCneUI8utcIQVhBVh6ExYdg3a7KYLAAAxeAseew8kPkCwDEtJciBsO858vUcF8N8iw8-hH5yBkcGCxIXqG2WUR8K2Y2S8eww-3O-vo-G5hG2X0Yo2j_A56PoAOk9tDk-0P4b81qp-dpcysL-5ADpb4-g32N8sxvYgerig1uFc2TB3xwtT3--q99HJ7IKnQlgChJXK9F5oTVip9blbRumKrihhZRVkKkcXTsnh2X-w_ArBFiM7K3k6wYeJk_88Mf1u4lcS_WIveEYXyPctPnYcUdkzXnuNtzcZH1V8oUP6c0W43ZK4iCiJCxaRuAB0zoa2AA4bdGgkhgVwXuNZSeQcmsFIr6wBwjbzHtmEtXHe2t5z_gr--c32_CPJ2_sFxCQuslC2sR7DWQqtsYbqW6hz6iibOef3duuc_APKtapmysuw-cprXyOs5Hyc4GM3lJ3wbeiDRURDhdHmscQnAmuUWjisoUWHUxGcH97--LJ_4xwqazU80NRoKzxwHugKzexG6cQn5xOwIWw7YUi8g3vD-UeU_m898bLa9ecMwIKiP0X_zY_Vv7ZDpfEDA9yw9b-0AJvk7uGIBp3wWMOlRXPtYcocobEOgqirD1rjdFzUeVxncSYWmEf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