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

    <tr>
        <th>Summary</th>
        <td>
            Clang segfaults with Non-Type Template Parameters and -Weverything 
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    The following code causes a Segmentation Fault when `-Weverything` is specified, starting from around Clang version 12.0.0 and up:
```
template <int num>
class TemplateClass {};

template <TemplateClass nttp>
void func() {}
```

I tested this on various versions of Clang using Compiler Explorer: https://godbolt.org/z/8G11GE8eq
(As an aside, MSVC and GCC are able to compile the example just fine, and Clang compiles it successfully without `-Weverything`)

Here is the output from `x86-64 clang (trunk)` for reference:
```
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++2b -Weverything <source>
1.      <source>:4:29: current parser token '>'
 #0 0x00005594cd929d34 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x00005594cd927b9c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3945b9c)
 #2 0x00005594cd865828 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007fd53134e420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00005594d0aabf1d ConvertTypeToDiagnosticString(clang::ASTContext&, clang::QualType, llvm::ArrayRef<std::pair<clang::DiagnosticsEngine::ArgumentKind, long>>, llvm::ArrayRef<long>) ASTDiagnostic.cpp:0:0
 #5 0x00005594d0aacf0c 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-trunk/bin/clang+++0x6acaf0c)
 #6 0x00005594cdc76bd7 clang::Diagnostic::FormatDiagnostic(char const*, char const*, llvm::SmallVectorImpl<char>&) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3c94bd7)
 #7 0x00005594ce4eff84 clang::TextDiagnosticPrinter::HandleDiagnostic(clang::DiagnosticsEngine::Level, clang::Diagnostic const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x450df84)
 #8 0x00005594cdc7cc71 clang::DiagnosticIDs::ProcessDiag(clang::DiagnosticsEngine&) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3c9ac71)
 #9 0x00005594cdc7131b clang::DiagnosticsEngine::EmitCurrentDiagnostic(bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3c8f31b)
#10 0x00005594cfec707b clang::Sema::EmitCurrentDiagnostic(unsigned int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5ee507b)
#11 0x00005594cfec79ff clang::Sema::ImmediateDiagBuilder::~ImmediateDiagBuilder() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5ee59ff)
#12 0x00005594cfec822b clang::Sema::SemaDiagnosticBuilder::~SemaDiagnosticBuilder() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5ee622b)
#13 0x00005594d0683150 clang::Sema::ActOnNonTypeTemplateParameter(clang::Scope*, clang::Declarator&, unsigned int, unsigned int, clang::SourceLocation, clang::Expr*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x66a1150)
#14 0x00005594cfe6cc6d clang::Parser::ParseNonTypeTemplateParameter(unsigned int, unsigned int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5e8ac6d)
#15 0x00005594cfe75a19 clang::Parser::ParseTemplateParameter(unsigned int, unsigned int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5e93a19)
#16 0x00005594cfe76769 clang::Parser::ParseTemplateParameterList(unsigned int, llvm::SmallVectorImpl<clang::NamedDecl*>&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5e94769)
#17 0x00005594cfe76c06 clang::Parser::ParseTemplateParameters(clang::Parser::MultiParseScope&, unsigned int, llvm::SmallVectorImpl<clang::NamedDecl*>&, clang::SourceLocation&, clang::SourceLocation&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5e94c06)
#18 0x00005594cfe796a6 clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5e976a6)
#19 0x00005594cfe79ad3 clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5e97ad3)
#20 0x00005594cfdaa5b5 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5dc85b5)
#21 0x00005594cfd7bb36 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5d99b36)
#22 0x00005594cfd7d8fa clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5d9b8fa)
#23 0x00005594cfd6d27a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5d8b27a)
#24 0x00005594ceb89f95 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4ba7f95)
#25 0x00005594ce494441 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x44b2441)
#26 0x00005594ce41b0e3 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x44390e3)
#27 0x00005594ce57296b clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x459096b)
#28 0x00005594cb244ca4 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x1262ca4)
#29 0x00005594cb23e29b ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#30 0x00005594ce285659 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
#31 0x00005594cd865f97 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3883f97)
#32 0x00005594ce285c4c 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
#33 0x00005594ce24f769 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x426d769)
#34 0x00005594ce25015d 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+++0x426e15d)
#35 0x00005594ce25a86c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x427886c)
#36 0x00005594cb2429c9 clang_main(int, char**) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x12609c9)
#37 0x00007fd530dfc083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#38 0x00005594cb23deae _start (/opt/compiler-explorer/clang-trunk/bin/clang+++0x125beae)
clang-16: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Compiler returned: 139
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzlWtty2zgS_Rr5BSUV75cHPSjyZbLrJN7INfOoAgFQ4oQiOADoyPP12wApiaBlxZ7lZKt2XbIt4nr6dKPRaDDj9Hn-uGUo52XJvxfVBhFOGSK4kUwijFZss2OVwqrgFbrFTanQ9y2r0CRypr-xJyae1RZ6wSMqJJI1I0VeMDrxlkgqLJQeMRd8h7DgTUXRssRQAv2kHtD1Zs7MQRgqmnriLybO9cRZwGDdxzwqtqtLrBia-MuiUqhqdhP_pq0jJZYSPXYtluZpEn-YxNcT_0M32otB7OaVUvVxvCdeUJQ3FZl4ycRLD2Odg9X-_YgUk4pRBDRIBCI9YVHwRh5EhLK8E7qRmowl39VFyQS62dclF0yA2GgLGKSW37uFz4bTjJdqxsUGnv6E3-TOde9uEvZHN7WXLEA5FcKyoExz_Wn169LQeLeE_4IhnJUMKQ7aNNMBPIbYHoPgDP3eSIXyojI98VEpXVOJCoVkQwiTMm_K8hl9L9SWN-qMzoGiPhm_MJgZaNCTQYca-hjdQ8t9Ek2jABEzE-BXoqm-6e5gODkXSLAcOleEvWYFD_c3i9UNAMt2gA-jrNlAp5oLpcUcEAiAm2wGAsFDWT4d_k1rwX9nRMFjIWXDJHwxBBQVKRvaskQElluUYfJNCUwMRzVMJLgmBBQteSPIkTqwIE4KrC0AJEKSiKJWsxbySsEgiDa7k2k7UJU-CL4RWC-JTaMXlwYOnNzyWiPr1CCm7GA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