Clang 17 crashes when requires clause accesses parameter value [C++20] (original) (raw)

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:

#include #include

template struct some_struct { template void test(Type& target, O&& value) & requires std::assignable_from<Type&, decltype(std::forward(value))>; };

template template void some_struct::test(Type& target, O&& value) & requires std::assignable_from<Type&, decltype(std::forward(value))> { target = std::forward(value); }

int main() { some_struct 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