<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/55315>55315</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang++ compiler error about static constexpr member function
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
akr-akari
</td>
</tr>
</table>
<pre>
The code is as follows.
```
struct Test
{
static constexpr void foo1() noexcept
{
fooImpl(2022);
}
static constexpr void foo2() noexcept
{
fooImpl(3.14);
}
template<class T>
static constexpr void fooImpl(T value) noexcept
{
}
};
int main()
{
Test t;
t.foo1();
t.foo2();
}
```
In gcc, it compiles successfully. But in clang, the compilation fails and the output is as follows.
```
>clang++ main.cc -omain.exe
main.cc:19:27: warning: inline function 'Test::fooImpl<int>' is not defined
[-Wundefined-inline]
static constexpr void fooImpl(T value) noexcept
^
main.cc:10:9: note: used here
fooImpl(2022);
^
main.cc:19:27: warning: inline function 'Test::fooImpl<double>' is not defined
[-Wundefined-inline]
static constexpr void fooImpl(T value) noexcept
^
main.cc:15:9: note: used here
fooImpl(3.14);
^
2 warnings generated.
C:/Users/XIANG/winlibs/mingw64/bin/ld: C:/Users/XIANG/AppData/Local/Temp/main-640e60.o:main.cc:(.text$_ZN4Test4foo1Ev[_ZN4Test4foo1Ev]+0xa): undefined reference to `void Test::fooImpl<int>(int)'
C:/Users/XIANG/winlibs/mingw64/bin/ld: C:/Users/XIANG/AppData/Local/Temp/main-640e60.o:main.cc:(.text$_ZN4Test4foo2Ev[_ZN4Test4foo2Ev]+0xd): undefined reference to `void Test::fooImpl<double>(double)'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
```
But I put `fooImpl()` at the top and it compiles successfully.
The code is as follows.
```
struct Test
{
template<class T>
static constexpr void fooImpl(T value) noexcept
{
}
static constexpr void foo1() noexcept
{
fooImpl(2022);
}
static constexpr void foo2() noexcept
{
fooImpl(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