<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/74447>74447</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang 17 crashes when `requires` clause accesses parameter value [C++20]
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Curve
</td>
</tr>
</table>
<pre>
When a templated class with a templated method uses a `requires` clause which references a method argument the compiler crashes.
Tested on: Clang 17.0.5, 17.0.6, Trunk
This **did not happen on Clang 16**.
> [!NOTE]
> This **only happens** when the class the method resides in is templated as well
Reproduction Example:
```cpp
#include <concepts>
#include <utility>
template <typename Type>
struct some_struct
{
template <typename O>
void test(Type& target, O&& value) &
requires std::assignable_from<Type&, decltype(std::forward<O>(value))>;
};
template <typename Type>
template <typename O>
void some_struct<Type>::test(Type& target, O&& value) &
requires std::assignable_from<Type&, decltype(std::forward<O>(value))>
{
target = std::forward<O>(value);
}
int main()
{
some_struct<int> a;
int val = 10;
a.test(val, 20);
return 0;
}
```
Crash Log:
```
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: /usr/lib/llvm17/bin/clang++ -cc1 -triple x86_64-alpine-linux-musl -emit-obj -mrelax-all -dumpdir a- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name reprod.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -ffp-contract=on -fno-rounding-math -mconstructor-alia/work # clang++ -std=c++20 reprod.cpp
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: /usr/lib/llvm17/bin/clang++ -cc1 -triple x86_64-alpine-linux-musl -emit-obj -mrelax-all -dumpdir a- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name reprod.cpp -m/work # clang++ -std=c++20 reprod.cpp
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: /usr/lib/llvm17/bin/clang++ -cc1 -triple x86_64-alpine-linux-musl -emit-obj -mrelax-all -dumpdir a- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name reprod.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/work -resource-dir /usr/lib/llvm17/lib/clang/17 -internal-isystem /usr/bin/../lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../include/c++/13.2.1 -internal-isystem /usr/bin/../lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../include/c++/13.2.1/x86_64-alpine-linux-musl -internal-isystem /usr/bin/../lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../include/c++/13.2.1/backward -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/include -internal-externc-isystem /usr/include/fortify -internal-externc-isystem /usr/include -internal-isystem /usr/lib/llvm17/lib/clang/17/include -std=c++20 -fdeprecated-macro -fdebug-compilation-dir=/work -ferror-limit 19 -stack-protector 2 -fgnuc-version=4.2.1 -fno-implicit-modules -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/reprod-4033ce.o -x c++ reprod.cpp
1. reprod.cpp:16:1: current parser token '{'
clang++: error: unable to execute command: Segmentation fault (core dumped)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Alpine clang version 17.0.5
Target: x86_64-alpine-linux-musl
Thread model: posix
InstalledDir: /usr/bin
Configuration file: /etc/clang17/x86_64-alpine-linux-musl.cfg
clang++: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang++: note: diagnostic msg: /tmp/reprod-2638ac.cpp
clang++: note: diagnostic msg: /tmp/reprod-2638ac.sh
clang++: note: diagnostic msg:
********************
```
Godbolt Reproduction Example: https://godbolt.org/z/Yv7oKK4KM
[files.zip](https://github.com/llvm/llvm-project/files/13558779/files.zip)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWN1zGykS_2vwSxeqEaMvP-hB1keSSnadSnyXuicXYnpGrBmYA0aW96-_amYky4nty2av9rZuz6UaQ0M33T_6A5Ah6Moiztn4io1XF7KNO-fny9bv8WLriof5lx1akBCxboyMWIAyMgS413H3hFxj3LkC2oABJLBJ5vGfrfYY2CQjnjYg3O-02oHHEj1alSb2bNJXbY02QtwhKFc32qAH5WXYYRiwbMWyRfe9wUDLOcvyBSyNtBUMp4NsMGZi2bUm1Lrxrb17wrfTAZhYMLEodAHWRdjJpkELzh7lTLrxJ-uxfA0Ejhj-fH2zZuMVwOPAmVBnzUMvMXQUuCfokkEJMmr15noMusAA2oIOZyDKAPdozPn6n7DxrmhV1M7C-iDrxiDLF09UnGTdTzVNTxG5tsq0BQLLl8pZhU0MLF8_N9xGbXR8eBw9-x5Vo3nxoUEra4SbhwZPs0P0rYoQXI23Xbvnn151DQCAZ8Vcn2TQlL3TBUQMkYlZWkBMIEpfYaTtvGZiQpS9NC0ycQnUP_HS39HdIMSC8MkXnW_LrcHb0rua5cteLgksUJmYurMTQ-n8vfQFy5dJNTE7rka_fM3yq6Npq8f2d8L0bxBI1p9j2CtLq5JqPwjMHwDKM5udlAOWr-A7pJyDeoaothFqqS0TM5r17SpPwdI2UjzKr_aFJpKkvTRJn2F2mkBDctDjupeG7BfZE43OYIytt5A9o-wx9M5ZlpS24IOrXorTrvvxw3rxeQ2h3dY6goRtW4HHxvkI0cEuxiaQALFhYlPpuGu3A-VqJjbG7I__eO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