<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/57632>57632</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang] Crash when parsing invalid constrainted type
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
JMazurkiewicz
</td>
</tr>
</table>
<pre>
### Repro
```c++
template<typename, typename>
concept crash = true;
template <typename>
struct forward_declared;
template <typename>
struct forward_declared { };
int main() {
crash<forward_declared> auto x = 0;
}
```
### Compiler output
```c++
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: /opt/compiler-explorer/clang-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 <source>
1. <source>:11:36: current parser token '='
2. <source>:10:12: parsing function body 'main'
3. <source>:10:12: in compound statement ('{}')
#0 0x00005649ffabbe14 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
#1 0x00005649ffab9c7c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x395cc7c)
#2 0x00005649ff9f7588 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007fe49ca29420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#4 0x00005649ff9ff517 llvm::FoldingSetBase::InsertNode(llvm::FoldingSetBase::Node*, void*, llvm::FoldingSetBase::FoldingSetInfo const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x38a2517)
#5 0x0000564a02c0c5cb clang::ASTContext::getAutoTypeInternal(clang::QualType, clang::AutoTypeKeyword, bool, bool, clang::ConceptDecl*, llvm::ArrayRef<clang::TemplateArgument>, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6aaf5cb)
#6 0x0000564a02c0c71e clang::ASTContext::getAutoType(clang::QualType, clang::AutoTypeKeyword, bool, bool, clang::ConceptDecl*, llvm::ArrayRef<clang::TemplateArgument>) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6aaf71e)
#7 0x0000564a029ee68d GetDeclSpecTypeForDeclarator((anonymous namespace)::TypeProcessingState&, clang::TypeSourceInfo*&) (.constprop.0) SemaType.cpp:0:0
#8 0x0000564a029fcaee clang::Sema::GetTypeForDeclarator(clang::Declarator&, clang::Scope*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x689faee)
#9 0x0000564a02248f9e clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x60ebf9e)
#10 0x0000564a02249dd5 clang::Sema::ActOnDeclarator(clang::Scope*, clang::Declarator&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x60ecdd5)
#11 0x0000564a01f31a77 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5dd4a77)
#12 0x0000564a01f45a36 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5de8a36)
#13 0x0000564a01f46ce8 clang::Parser::ParseSimpleDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, bool, clang::Parser::ForRangeInit*, clang::SourceLocation*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5de9ce8)
#14 0x0000564a01f47200 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5dea200)
#15 0x0000564a01ff06fe clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5e936fe)
#16 0x0000564a01ff0fa3 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5e93fa3)
#17 0x0000564a01ff1ec6 clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5e94ec6)
#18 0x0000564a01ff3292 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5e96292)
#19 0x0000564a01f16274 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5db9274)
#20 0x0000564a01f45b7f clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5de8b7f)
#21 0x0000564a01f108b5 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5db38b5)
#22 0x0000564a01f11830 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.0) Parser.cpp:0:0
#23 0x0000564a01f192f1 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5dbc2f1)
#24 0x0000564a01f1a70a clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5dbd70a)
#25 0x0000564a01f0a0aa clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5dad0aa)
#26 0x0000564a00d213b5 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4bc43b5)
#27 0x0000564a00626011 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x44c9011)
#28 0x0000564a005acb63 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x444fb63)
#29 0x0000564a007091db clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x45ac1db)
#30 0x00005649fd3c8204 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x126b204)
#31 0x00005649fd3c17fb ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#32 0x0000564a00418e99 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#33 0x00005649ff9f7cf7 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x389acf7)
#34 0x0000564a004190cc clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#35 0x0000564a003e4719 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4287719)
#36 0x0000564a003e510d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x428810d)
#37 0x0000564a003ef85c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x429285c)
#38 0x00005649fd3c5f29 clang_main(int, char**) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x1268f29)
#39 0x00007fe49c4d7083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#40 0x00005649fd3c140e _start (/opt/compiler-explorer/clang-trunk/bin/clang+++0x126440e)
```
### Expected behaviour
This code should not compile and we should get nice diagnostic.
### Compiler explorer
https://godbolt.org/z/1W8cM36on
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztWt1y27wRfRr5BiMN_38ufEHLdpqvSe1GnvZSA4KgxIYiWBB05Dx9FwApEbQkOym_TGZaDyVTAAicPbvYXRBIWfZyPXNcfaEvtOZsZt3OrKT7Dix9kZlzIy9VKuiuLrGgM3cpXmpa4R2dOUt0uHfvdDvCKkJrgQjHzRbN3FskeAvVN8Mh-s7QsLe-hwYeIALljH_DPFtnlJSY02yCLtAsvIHP7airohJoh4tq5kQzJ5aNdDmCPyUGDPEazR3CrWBor2S0jl1C9yaNBrcH2pdsVxcl5Yi1om7F2wp4_HSXrO5Q06a7QiCM0naDOK0ZFwhgbIWom5kLA9zDtSnEtk0XhO3gR1k-9__moOp_USLgZ9E0LW3gBuEqQ0VFyjajSGxpp7kUk6-CY6K0XHNpJIQ2DZDYsJbrYvkkbhpGClBEhnhboYbwohYLDXkloBOUtbtaIlNFFlTFj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