Skip to content

Clang 17 crashes when requires clause accesses parameter value [C++20] #74447

@Curve

Description

@Curve

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 <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

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"conceptsC++20 conceptscrashPrefer [crash-on-valid] or [crash-on-invalid]

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions