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

    <tr>
        <th>Summary</th>
        <td>
            [Clang] Build fails when forward declared static template function used in std::visit
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

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

<pre>
    Code:
```cpp
#include <variant>

template<typename T>
static T funcT(const T t);

int main()
{
    std::variant<int, double> v{1};

    return std::visit([&](auto& a) -> int
    {
        return funcT<>(a);
    }, v);
}

template<typename T>
static T funcT(const T t) {
    return t;
}
```
Output:

```
<source>:4:10: warning: function 'funcT<int>' has internal linkage but is not defined [-Wundefined-internal]
    4 | static T funcT(const T t);
      |          ^
<source>:12:16: note: used here
   12 |         return funcT<>(a);
      |                ^
<source>:4:10: warning: function 'funcT<double>' has internal linkage but is not defined [-Wundefined-internal]
    4 | static T funcT(const T t);
      | ^
<source>:12:16: note: used here
   12 |         return funcT<>(a);
 |                ^
2 warnings generated.
ASM generation compiler returned: 0
<source>:4:10: warning: function 'funcT<int>' has internal linkage but is not defined [-Wundefined-internal]
    4 | static T funcT(const T t);
 |          ^
<source>:12:16: note: used here
   12 |         return funcT<>(a);
      |                ^
<source>:4:10: warning: function 'funcT<double>' has internal linkage but is not defined [-Wundefined-internal]
    4 | static T funcT(const T t);
      | ^
<source>:12:16: note: used here
   12 |         return funcT<>(a);
 |                ^
2 warnings generated.
/opt/compiler-explorer/gcc-14.2.0/lib/gcc/x86_64-linux-gnu/14.2.0/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-8f2a9c.o: in function `int main::$_0::operator()<int>(int&) const':
<source>:12:(.text+0x257): undefined reference to `int funcT<int>(int)'
/opt/compiler-explorer/gcc-14.2.0/lib/gcc/x86_64-linux-gnu/14.2.0/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-8f2a9c.o: in function `int main::$_0::operator()<double>(double&) const':
<source>:12:(.text+0x309): undefined reference to `double funcT<double>(double)'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
Execution build compiler returned: 1
```

Demo: https://godbolt.org/z/d18dvc56E
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsVs2O4zYMfhrmQiSwqdiODzk4yfhW9NABelzIFpNoV5EMWc5k-_SF7CTzs9N20AIt2m5gOLIk8hM_kiJl3-uDZV5DtoFsN5NDODq_Viy_GPnZ9bPGqa_rrVMMooKkgjyZnrbr4icJbVszKEYQ27P0WtoA4iEuJVXgU2dkYBDb8LVjK0-Mj9NqH2TQLT7ifrDtI9CqdbYP-IgBqASxmRRoG_AktQVaxemkgiKuICL2QcUTieoOutU2AG1RuaExDOIBz1BsUih2d31R0HMYvH0hr3sdIkC2Acoh2wGt5BAcUI4SqMR5VBV1T_LPR3ihbbJCbKNxtJJ3GyaBXTzW-dmwYvfX-Hlxhit-eKX55iNIqh-H0A3h6rvXSyC2vRt8G6kCUS1BVGkCosIn6a22hziM6EE7i0DFzUY9eZgKPMo-EsPeSoNG2y_ywNgMAXWP1gVUvNeWFUK2mf882Ovn_CYSuZ6sWCIUW_xATEykx833H2QP3xqTUnzl0QTrIsEVDj0rPLLnSU1Kr9R8wI9vcH8H_cNU3kP1n2bz7yHxN_mjG1E9Htiyl4HVApKq-umH20RkrnWnThv2VyCOGYz_2lD-HsX_kygGql0XgOpb_M750hnn2QPVh7adp8sFLRKg2uhmmgKqL6v8U76cG22Hy_xgB6D6vm-x-Pb1zv4mVs7ajGkCVIdTB1TzRZ46w_PVnmTZLlxc1PaFY_PkXnbHAgm0_JRMQ9dFq5y_1uPnBFqNtTePtWl0EFBxrTnvOANotQh8CUCb5EJZMaqq8B4M6HnPnm3LGNztPG9TdkIsI9B_muEXybW6jv8UzyIp_5DnST--k9d36CvhrZH2ALSJj6iQvXc-DmLCs48X9UlahXupDSt80u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