<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/114758>114758</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang-20 Crash: TemplateArgument kind is not expected for NTTP UNREACHABLE executed at /root/llvm-project/clang/lib/AST/ASTDiagnostic.cpp:1245!
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
iamanonymouscs
</td>
</tr>
</table>
<pre>
### Description
I encountered a crash in Clang-20 when compiling the following code snippet:
```cpp
template<int N> struct A
{
void foo() throw(int[N]);
};
A<0> a;
template<typename T> struct A
{
void foo() throw(typename T::X);
};
A<void> a;
```
The compilation command used was:
```sh
clang++ -O3 -ffast-math -fno-ident -std=c++23 -fno-rtlib-add-rpath -Wall -Wextra -fno-strict-aliasing -fwrapv -g -fsanitize=address test.cpp
```
Following the error messages, the compiler crashed with an assertion failure:
```sh
TemplateArgument kind is not expected for NTTP UNREACHABLE executed at /root/llvm-project/clang/lib/AST/ASTDiagnostic.cpp:1245!
```
### Error Message
```sh
<source>:3:16: error: ISO C++17 does not allow dynamic exception specifications [-Wdynamic-exception-spec]
3 | void foo() throw(int[N]);
| ^~~~~~~~~~~~~
<source>:3:16: note: use 'noexcept(false)' instead
3 | void foo() throw(int[N]);
| ^~~~~~~~~~~~~
| noexcept(false)
<source>:8:19: error: template parameter has a different kind in template redeclaration
8 | template<typename T> struct A
| ^
<source>:1:14: note: previous template declaration is here
1 | template<int N> struct A
| ^
TemplateArgument kind is not expected for NTTP
UNREACHABLE executed at /root/llvm-project/clang/lib/AST/ASTDiagnostic.cpp:1245!
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 -O3 -ffast-math -fno-ident -std=c++23 -fno-rtlib-add-rpath -Wall -Wextra -fno-strict-aliasing -fwrapv -g -fsanitize=address <source>
1. <source>:13:10: current parser token ';'
#0 0x0000000003be87b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3be87b8)
#1 0x0000000003be64bc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3be64bc)
#2 0x0000000003b33df8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007b7ccba42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007b7ccba969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x00007b7ccba42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x00007b7ccba287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x0000000003b3f71a (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3b3f71a)
#8 0x000000000793b6ce (anonymous namespace)::TemplateDiff::InitializeNonTypeDiffVariables(clang::ASTContext&, (anonymous namespace)::TemplateDiff::TSTiterator const&, clang::NonTypeTemplateParmDecl*, llvm::APSInt&, bool&, clang::QualType&, bool&, clang::Expr*&, clang::ValueDecl*&, bool&) (.isra.0) ASTDiagnostic.cpp:0:0
#9 0x000000000793bd4e (anonymous namespace)::TemplateDiff::DiffTemplate(clang::TemplateSpecializationType const*, clang::TemplateSpecializationType const*) ASTDiagnostic.cpp:0:0
#10 0x0000000007942cec FormatTemplateTypeDiff(clang::ASTContext&, clang::QualType, clang::QualType, bool, bool, bool, bool, llvm::raw_ostream&) ASTDiagnostic.cpp:0:0
#11 0x000000000794343c clang::FormatASTNodeDiagnosticArgument(clang::DiagnosticsEngine::ArgumentKind, long, llvm::StringRef, llvm::StringRef, llvm::ArrayRef<std::pair<clang::DiagnosticsEngine::ArgumentKind, long>>, llvm::SmallVectorImpl<char>&, void*, llvm::ArrayRef<long>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x794343c)
#12 0x0000000003e12915 clang::Diagnostic::FormatDiagnostic(char const*, char const*, llvm::SmallVectorImpl<char>&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3e12915)
#13 0x000000000487557a clang::TextDiagnosticPrinter::HandleDiagnostic(clang::DiagnosticsEngine::Level, clang::Diagnostic const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x487557a)
#14 0x0000000003e1e1fb clang::DiagnosticIDs::EmitDiag(clang::DiagnosticsEngine&, clang::DiagnosticBuilder const&, clang::DiagnosticIDs::Level) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3e1e1fb)
#15 0x0000000003e1e7f3 clang::DiagnosticIDs::ProcessDiag(clang::DiagnosticsEngine&, clang::DiagnosticBuilder const&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3e1e7f3)
#16 0x0000000003e11edf clang::DiagnosticsEngine::EmitDiagnostic(clang::DiagnosticBuilder const&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3e11edf)
#17 0x0000000006869cc4 clang::Sema::EmitDiagnostic(unsigned int, clang::DiagnosticBuilder const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6869cc4)
#18 0x00000000068e1a88 clang::SemaBase::ImmediateDiagBuilder::~ImmediateDiagBuilder() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x68e1a88)
#19 0x0000000006858a73 clang::SemaBase::SemaDiagnosticBuilder::~SemaDiagnosticBuilder() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6858a73)
#20 0x0000000006a80a43 diagnoseVarDeclTypeMismatch(clang::Sema&, clang::VarDecl*, clang::VarDecl*) SemaDecl.cpp:0:0
#21 0x0000000006aa40df clang::Sema::MergeVarDecl(clang::VarDecl*, clang::LookupResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6aa40df)
#22 0x0000000006aa550a clang::Sema::CheckVariableDeclaration(clang::VarDecl*, clang::LookupResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6aa550a)
#23 0x0000000006aa7a9d clang::Sema::ActOnVariableDeclarator(clang::Scope*, clang::Declarator&, clang::DeclContext*, clang::TypeSourceInfo*, clang::LookupResult&, llvm::MutableArrayRef<clang::TemplateParameterList*>, bool&, llvm::ArrayRef<clang::BindingDecl*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6aa7a9d)
#24 0x0000000006abcac4 clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6abcac4)
#25 0x0000000006abd530 clang::Sema::ActOnDeclarator(clang::Scope*, clang::Declarator&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6abd530)
#26 0x00000000067174be clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x67174be)
#27 0x0000000006726f89 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6726f89)
#28 0x00000000066e6fae clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66e6fae)
#29 0x00000000066e776e clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66e776e)
#30 0x00000000066eef03 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66eef03)
#31 0x00000000066efded clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66efded)
#32 0x00000000066e230a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66e230a)
#33 0x0000000004560df8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4560df8)
#34 0x000000000481b949 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x481b949)
#35 0x000000000479abbe clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x479abbe)
#36 0x00000000049016de clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x49016de)
#37 0x0000000000ce5b8f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xce5b8f)
#38 0x0000000000cdd84a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#39 0x00000000045a3f79 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 0x0000000003b342a4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3b342a4)
#41 0x00000000045a456f 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 0x000000000456a8dd clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x456a8dd)
#43 0x000000000456b9cd 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+++0x456b9cd)
#44 0x0000000004572d85 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4572d85)
#45 0x0000000000ce2a29 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xce2a29)
#46 0x0000000000bafbc4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbafbc4)
#47 0x00007b7ccba29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#48 0x00007b7ccba29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#49 0x0000000000cdd2fe _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcdd2fe)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
The issue can also be reproduced on Compiler Explorer:https://godbolt.org/z/e77c91afb
Please let me know if you need any more details.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkW9tT47ia_2vMi8qUb4mdBx5CAucw29PNdtiZfaNk-XOixZa8kkyHeTh_-5YkO7FMEqAP6ZqqpaYZY91-3--76NPFWEq6ZgBX3uTamywvcKs2XFxRX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