<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/65522>65522</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Clang] Ill-formed default argument treated as building a deduction guide causes crash
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang,
            clang:frontend,
            crash-on-invalid,
            new issue,
            confirmed
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          shafik
      </td>
    </tr>
</table>

<pre>
    Given the following C++:

```cpp
template<typename A3>
class B3 : A3 {
 template<bool = C3<B3>()> 
  B3();
}; B3(); 
```

This causes a crash on clang trunk: https://godbolt.org/z/dK43xx1KT

This was introduced by: https://reviews.llvm.org/D139837 and is currently blocking: https://reviews.llvm.org/D148474

Unreachable hit:

```console
UNREACHABLE executed at /root/llvm-project/clang/lib/Sema/SemaTemplateInstantiate.cpp:1068!
```

Backtrace:

```console
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-assertions-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++17 <source>
1.      <source>:5:8: current parser token ';'
 #0 0x00000000036bc8f8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x36bc8f8)
 #1 0x00000000036ba5bc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x36ba5bc)
 #2 0x00000000036039d8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f2295820420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f22952e300b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007f22952c2859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x000000000360ec8a (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x360ec8a)
 #7 0x0000000006920118 clang::Sema::PrintInstantiationStack() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6920118)
 #8 0x0000000005f78090 clang::Sema::EmitCurrentDiagnostic(unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5f78090)
 #9 0x0000000005f783d1 clang::Sema::ImmediateDiagBuilder::~ImmediateDiagBuilder() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5f783d1)
#10 0x0000000005f78c20 clang::Sema::SemaDiagnosticBuilder::~SemaDiagnosticBuilder() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5f78c20)
#11 0x00000000063c15f6 clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x63c15f6)
#12 0x0000000006932db0 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCallExpr(clang::CallExpr*) SemaTemplateInstantiate.cpp:0:0
#13 0x0000000006929238 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#14 0x000000000695b288 clang::Sema::SubstExpr(clang::Expr*, clang::MultiLevelTemplateArgumentList const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x695b288)
#15 0x00000000069703a4 clang::TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl(clang::NonTypeTemplateParmDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x69703a4)
#16 0x00000000069bdb34 void llvm::function_ref<void ()>::callback_fn<clang::Sema::SubstDecl(clang::Decl*, clang::DeclContext*, clang::MultiLevelTemplateArgumentList const&)::'lambda'()>(long) SemaTemplateInstantiateDecl.cpp:0:0
#17 0x0000000005f67b51 clang::Sema::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5f67b51)
#18 0x000000000696ddaa clang::Sema::SubstDecl(clang::Decl*, clang::DeclContext*, clang::MultiLevelTemplateArgumentList const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x696ddaa)
#19 0x0000000006869add clang::Sema::DeclareImplicitDeductionGuides(clang::TemplateDecl*, clang::SourceLocation) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6869add)
#20 0x00000000065b2a37 LookupDirect(clang::Sema&, clang::LookupResult&, clang::DeclContext const*) SemaLookup.cpp:0:0
#21 0x00000000065b36fe CppNamespaceLookup(clang::Sema&, clang::LookupResult&, clang::ASTContext&, clang::DeclContext const*, (anonymous namespace)::UnqualUsingDirectiveSet&) (.isra.0) SemaLookup.cpp:0:0
#22 0x00000000065a1429 clang::Sema::CppLookupName(clang::LookupResult&, clang::Scope*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x65a1429)
#23 0x00000000065a2195 clang::Sema::LookupName(clang::LookupResult&, clang::Scope*, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x65a2195)
#24 0x000000000618e430 clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x618e430)
#25 0x000000000618f2f1 clang::Sema::ActOnDeclarator(clang::Scope*, clang::Declarator&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x618f2f1)
#26 0x0000000005e3e9a0 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e3e9a0)
#27 0x0000000005e4c7e0 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e4c7e0)
#28 0x0000000005e197bb clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e197bb)
#29 0x0000000005e19eef clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.0) Parser.cpp:0:0
#30 0x0000000005e20604 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e20604)
#31 0x0000000005e20e0d clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e20e0d)
#32 0x0000000005e1516a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e1516a)
#33 0x000000000491dcf8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x491dcf8)
#34 0x000000000417be69 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x417be69)
#35 0x00000000040fe7be clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x40fe7be)
#36 0x000000000425c386 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x425c386)
#37 0x0000000000bd4b6e cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbd4b6e)
#38 0x0000000000bcd22a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#39 0x0000000003f5f5f9 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#40 0x0000000003603e84 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3603e84)
#41 0x0000000003f5fbef clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#42 0x0000000003f27f75 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f27f75)
#43 0x0000000003f289dd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f289dd)
#44 0x0000000003f30905 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f30905)
#45 0x0000000000bd2e0c clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbd2e0c)
#46 0x0000000000aced61 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xaced61)
#47 0x00007f22952c4083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#48 0x0000000000bccd0e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbccd0e)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkW99326i2_muUF5azJPTD0kMeHDvp6ZzOtKvOnPvohdCWza0MGkCpcx_u334XINtCttPMNO7L7UobGxB838dm7w2iRCm25gB3QXofpIsb0umNkHdqQ2r27aYU1cvdB_YMHOkNoFo0jfjO-BrNA3xvfuJZEC6CcP9vFrof2rauRMO2bYiGIJ7rlxY42QKaxUH84KppQ5RC9zEK4hmaxSiY3rsKNHiwFKJBQbxA8ziI5_f2aZwHuAjiB9Q3R_fxvqzvIZgugvh-WI5GIIfInzZMIUo6BQoRRCVRGyQ4og3ha6Rlx78ZhButW2U448cAP65FVYpG3wq5DvDj_wT4sfp3Eu920b-fTrr-ThRiXEtRdRQqVL6cdifhmcF3dds0z9u-z0UUF3k8RYRXyODrpASumxdUNoJ-Y3z9xl6SPJkmQ0x_cgmEbkjZANowfXEaBVeigf6ZP74-zOb_mt1_ekCwA9ppqBDRyAwqhA7woxlz0krx30DNVyueKWZlgB-XsCX9r6d-bj9ypQnXjGi4NRYTz6IwywMcvTJR94R-05JQeBPmL58eZssHpLpyyzQiqOzWSEIrpEZajKeT6U1X3lKx7amcMmJKdaAC_OhmhNOmq8CuDGcx5QEcnqNWQisFBaWgQkp00hWbJ4lSghraFZIdR4pK1upbB3mpCf2Gqm7bHhiGt0FYfJFiLckWEbnutsC1AW60F63VWmxb1oCcwK5thAS5139ClAKpmeBq4uwYP5aMH6fHLGM0WVffiawnCZqs0USYfknbmt473Xb6VqHJ1miBJpNdnk2I2k7UC9dkF8QLxjU0aLJEk8ma0okWoqEbwngQL16FZxorTlq1ERpNaioaIScVI2sulGZUoUnNxcQK6xcrXQXxgjro0RQF8byXd-9WIiOYVxzP0iCe5UazfhWhlkgFEmnxDTgK8NR4Djzt_UmA4xCFu3D_J85Kmtc5snYRz4J4pl6U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