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

    <tr>
        <th>Summary</th>
        <td>
            [clang assertion trunk] unexpected conversion required for non-type template argument
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:frontend,
            crash-on-invalid,
            clang:frontend:fuzzer
      </td>
    </tr>

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

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

<pre>
    **This testcase is generated by a fuzzer.**

Compiler Explorer: [https://godbolt.org/z/Yveq389db](https://godbolt.org/z/Yveq389db)

This valid code will crash on Clang Assertion Trunk. It seems that this goes back to clang-15:
```cpp
template <typename T, int (*F)(T)>
int fun_tmpl_recurse(T t) {
  return F(t, 1);
}
int ident(int x) { return 0; }
void foo() {
  fun_tmpl_recurse<int, fun_tmpl_recurse<int, ident> >(0);
}
```

Stack dump:
```
unexpected conversion required for non-type template argument
UNREACHABLE executed at /root/llvm-project/clang/lib/Sema/SemaTemplate.cpp:7519!
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 -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics <source>
1.      <eof> parser at end of file
2.      <source>:2:5: instantiating function definition 'fun_tmpl_recurse<int, &fun_tmpl_recurse>'
 #0 0x0000000003baa4b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3baa4b8)
 #1 0x0000000003ba817c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ba817c)
 #2 0x0000000003af53d8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x0000706ddea42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x0000706ddea969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x0000706ddea42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x0000706ddea287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x0000000003b00caa (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3b00caa)
 #8 0x00000000071951fc clang::Sema::BuildExpressionFromDeclTemplateArgument(clang::TemplateArgument const&, clang::QualType, clang::SourceLocation, clang::NamedDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71951fc)
 #9 0x00000000073cb16a (anonymous namespace)::TemplateInstantiator::transformNonTypeTemplateParmRef(clang::Decl*, clang::NonTypeTemplateParmDecl const*, clang::SourceLocation, clang::TemplateArgument, std::optional<unsigned int>) SemaTemplateInstantiate.cpp:0:0
#10 0x00000000073dd2ad (anonymous namespace)::TemplateInstantiator::TransformDeclRefExpr(clang::DeclRefExpr*) SemaTemplateInstantiate.cpp:0:0
#11 0x00000000073b1897 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#12 0x00000000073bf07e clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCallExpr(clang::CallExpr*) SemaTemplateInstantiate.cpp:0:0
#13 0x00000000073b17c4 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#14 0x00000000073b4228 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformInitializer(clang::Expr*, bool) (.part.0) SemaTemplateInstantiate.cpp:0:0
#15 0x00000000073b45dc clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformReturnStmt(clang::ReturnStmt*) SemaTemplateInstantiate.cpp:0:0
#16 0x00000000073ec0d4 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*, bool) SemaTemplateInstantiate.cpp:0:0
#17 0x00000000073f4434 clang::Sema::SubstStmt(clang::Stmt*, clang::MultiLevelTemplateArgumentList const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x73f4434)
#18 0x000000000745f085 clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x745f085)
#19 0x000000000745d31f clang::Sema::PerformPendingInstantiations(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x745d31f)
#20 0x00000000067da4ef clang::Sema::ActOnEndOfTranslationUnitFragment(clang::Sema::TUFragmentKind) (.part.0) Sema.cpp:0:0
#21 0x00000000067dacea clang::Sema::ActOnEndOfTranslationUnit() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x67dacea)
#22 0x000000000664debb clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x664debb)
#23 0x00000000066402fa clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66402fa)
#24 0x00000000045029b8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x45029b8)
#25 0x00000000047bc2b9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47bc2b9)
#26 0x000000000473ae5e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x473ae5e)
#27 0x00000000048a1e2e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48a1e2e)
#28 0x0000000000cdb89f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcdb89f)
#29 0x0000000000cd35aa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#30 0x0000000004546689 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
#31 0x0000000003af5884 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3af5884)
#32 0x0000000004546c7f 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
#33 0x000000000450c5bd clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x450c5bd)
#34 0x000000000450d6ad 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+++0x450d6ad)
#35 0x0000000004514fd5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4514fd5)
#36 0x0000000000cd876f clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcd876f)
#37 0x0000000000ba7cc4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xba7cc4)
#38 0x0000706ddea29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#39 0x0000706ddea29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#40 0x0000000000cd305e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcd305e)
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/eJzkWk1z2zjS_jXwBUUVCX4ffJBlaybzZiZ-Y89W7UkFAqCMCQlwANCR8-u3AFISQcnZcdaaqq1NJbFMAN1PP93obkLAWvOtYOwapDcgvb3CvXmS6vqF_4FFUiTpVSXpyzVAS4CWj09cQ8O0IVgzyDXcMsEUNozC6gViWPffvjG1GCaD8BaE4_8r2Xa8YQre7bpGKqZAvIQgvXkyptMgXgK0Bmi9lbSSjVlItQVo_Q2g9T-f2Z9xUdIKpLcAFX99Oiqn6h3uZ9xwComkDH7lTQOJwvoJSgFXDRZbuNSaKcOlgI-qF18W8IOBmrFWQ_OEDTRWxFYyDStMvkAjIbHLgii1eAZdWTj8JV03PDGs7RpsGATxyrx0TOCWwUeAVpALAwEqAFquLVZUPNof8d2wzo7WvdiYtms2ipFeaWbnQANQCUF-M0yDUDHTKwHXABXGio2clHEY5LdHcZwyYQAq7OfdKGW_PATxDTzMfpacwlpKB8_TdgIpXnHh9L4-MuiN76A1DhXhWYAH5qZOezCWaNq33SnDw6-9YLuOERt-RIpnprR1n2J_9lwxa4OCQorAMg8PrsBq27cWkxPx-2-f75arn5c3H-8g2zHSW2HY-matpDQArZvmuQ06Jf9gxP7qvG4f8wqg9QNr8fjjcVSwsN6Pl3kalQBFg5b7j3fLhzuo-6rlBmJY9VuoWCeVsYE0i2punvpqQWQ7Kj_FwLXumQZoDbGgkAvS9JRB88TGmLYRahQmzDqgU6xTkjCtGYVa9mp4bFdirSXhbvuqXkBNFO_M4lX2wwUIy3sltwq3Bxq128loLTvHzrjPA7bf5yNjAd5vLx0Yu78AWldcHAm9AegGBlv6Fas6SGCwhYG0cnHXWem96Xqz0DB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