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

    <tr>
        <th>Summary</th>
        <td>
            Address of overloaded function template is ambiguous when __host__ and __device__ overloads exist
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          lukas-lang
      </td>
    </tr>
</table>

<pre>
    It appears that it is impossible to select either the `__device__` or `__host__` version of an overloaded function template when trying to take its address ([Godbolt Link](https://godbolt.org/z/jcqxKGfo9)):

```cpp
template <typename T> __host__ void foo(T){}
template <typename T> __device__ void foo(T){}

int main()
{
    foo(1);                           // works
    auto bar = (void (*)(int))(&foo); // error
}
```

Removing the template fixes the issue. This seems to be (at least partly) caused by the fact that while `__host__`/`__device__` are considered part of the signature for function overloading, they can't seem to be added to the function pointer type: It doesn't matter where `__host__` is added to the type of the function pointer, it is always ignored with a warning:

```cpp
template <typename T> __host__ void foo(T){}
template <typename T> __device__ void foo(T){}

int main()
{
     auto bar = (__host__ void (*)(int))(&foo);
}
```

> warning: 'host' attribute ignored when parsing type [-Wignored-attributes]
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzdVFFzmzAM_jXw4ksOSAPNAw9ts_V229Oud3vsCRDgxmBmmaTZr59sQtpmt67PyzmALUv6JH1Soatj_sUKGAYEQ8K2YIXkRUJ2gyaShUJhtSBUWFqB0rZo-BqKII0eHyvcyxIfH3kjtJnOWk12OtmjIal7oWsB_OSt0lBhJeqxL62TWOwGBRbFoUXemaPsG-fOwg4ZBwmoKoNEIkiug_Xtva4Kraz4JvtdsN7yYWvtQMHqJkg-82om-VKbhne_-P9U_nz-el_rTZD4xTejbRDNzzSaVjkM08kZULC6s8cBe-hQPASrT2IOTOy15Ai0Zu8PzmR2G2Tbf2vPqXpPf3rK3ooOZO9iZvkk4Vv-Q_BvUo59PLfi778pKeKgzY5etGHkBBfA1VptXV49Hu_rxifpmv2fsuUOU-_NezrZQ2O0mWFtLzL5OpDv2Om9ryjz5ZybWj4j-SNJNOJSPLRMN0LsyJW-QAeGaagQyIoBjFVHBiBKGIm5Uxy9bg1MR0_XQysVXlDPIb3kJxgUpe5JVmjYjjPsmOmMkWx6sCNfqJnFZ3bOjOUQguTO3TwyCq5LZj3eE1zmKNtzrHW4ZuVBcx5drzAPmHaCu6zSSJN2B9bJmPXmErrrvTcWnYEZ6KV1B2tqV1AHOHLXNr120R24UQWIA5jeof8vaP8Hc99i-wiFP8Jah_slb2w2c174JbhoRhYjB3pOsxtbzCTyLHeF4im1-HESL84KxNMqxDxO0yiJ19FVFlb5qtqsNhBaaRXmN6c5x3V-d066SneFbEY90uT9nAToq9f5ns2QwGdJNhyNyi-mJXNkLJal7nij1H5-LQajn3ja89Z3KPHHOouyTdjmRV1Ea9gkWRWX_C5TrONVWnI3xlfrcl2ECgpUlHMagiTp8TA1OX-7DMg8iZIkuo7jOOIspEsooNzERVRDnaURboKrCJkDaulwuDEemtxDKsaGWKg4EnoRArnORfTu2D4TpNWsMe6AFgr6JvTec4_-N_IXKfw">