<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/99344>99344</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
"requires expression" contained in exported symbol name
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Ecordonnier
</td>
</tr>
</table>
<pre>
[clang-test.zip](https://github.com/user-attachments/files/16268452/clang-test.zip)
See the test code that I attached. It compiles fine with clang++17, but fails with clang++18.
test.cpp defines a template specialization, and main.cpp calls this function:
test.cpp:
```
template<class T>
requires(!std::is_same_v<T, std::string>)
std::optional<T> myFunction(std::string arg) {
return std::optional<T>{};
}
template std::optional<int> myFunction<int>(std::string arg);
```
main.cpp:
```
int main()
{
std::optional<int> foobar = myFunction<int>("foobar");
}
```
This gets compiled correctly with clang++17:
```
0000000000000000 W std::optional<int> myFunction<int>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)
```
however with clang++18 the symbol name also contains the requires expression after the correct name of the function:
```
0000000000000000 W std::optional<int> myFunction<int>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) requires !(std::is_same_v<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >)
```
For that reason, the linker fails to find the symbol.
```
$ ./test.sh
+ clang++-17 --version
Ubuntu clang version 17.0.6 (9ubuntu1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
+ clang++-17 -std=c++20 -c test.cpp -o test-clang-17.o
+ clang++-17 -std=c++20 -c main.cpp -o main-clang.o
+ clang++-17 main-clang.o test-clang-17.o -o main-clang-17
+ nm --demangle test-clang-17.o
+ grep -i myFunc
0000000000000000 W std::optional<int> myFunction<int>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)
+ clang++-19 --version
Ubuntu clang version 19.0.0 (++20240516083551+51403ada789e-1~exp1~20240516083654.504)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-19/bin
+ clang++-19 -std=c++20 -c test.cpp -o test-clang-19.o
+ clang++-19 -std=c++20 -c main.cpp -o main-clang.o
+ clang++-19 main-clang.o test-clang-19.o -o main-clang-19
/usr/bin/ld: main-clang.o: in function `main':
main.cpp:(.text+0x2f): undefined reference to `std::optional<int> myFunction<int>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
clang++-19: error: linker command failed with exit code 1 (use -v to see invocation)
+ + nm --demangle test-clang-19.o
grep -i myFunc
0000000000000000 W std::optional<int> myFunction<int>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) requires !(std::is_same_v<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcV02P4joW_TVmc5UocT4gCxZQNFKvp0azRI5zAc84dsZ2aKoX_duf7BAIVFF6raf3pO5WKxV87ePj63M_wqwVB4W4JMWaFJsZ691Rm-UXrk2jlRJoZrVu3ryZS6YOkUPr4u-iI8WG0MXRuc6SbEXoltDtQbhjX8dct4Rue4smYs4xfmxROUvodi8k-r9pSctFXlBCtw-gtCLJhiSr4fkvRHBHBG8Grhv_izn4CgMsNjF89Ya288CwFwrhm3BHCKiErgldp3NCX6DuHeyZkPa9fREPmwUOvOugQQ9kgYHDtpPMIdgOuWBSfGdOaOUBmWqgZUKFFZxJacEdhYV9r3iYk63uYa8DpEwu_y_2YQ-SvXDJrIVXkn0ZTGDw_70w3mULQlPrGg-SrYTdWdbi7kSyl1dP5mqxzgh18ACjI68m3XlaTIY12Rdo37YjVbp4AABmDoRWQObrCxMAMOh6o-AZoJ8735DsssK_T27y5skPlgvlHhiNY0-p3fa59-Z4Jc-8LZQL1xY8OmptespP-O21rpkBkm2eUCWUDnMIpXccr764JzM8X71sDujsKOQGuDYGuZNvH6n5ycmSh3_wn7_g692On89pOvyomRV8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