[clang] Assertion `getDepthAndIndex(NewParam).first == 0 && "Unexpected template parameter depth"' failed.
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Reproducer:
https://godbolt.org/z/bExzasorq
```cpp
template struct S {
static constexpr bool value = false;
};
template struct S {
static constexpr float value = Foo::Bar()
};
template struct SS {
template SS(U &&) {}
};
template SS(A) -> SS;
```
Backtrace:
```console
clang++: /root/llvm-project/llvm/tools/clang/lib/Sema/SemaTemplateDeductionGuide.cpp:595: clang::NamedDecl* {anonymous}::ConvertConstructorToDeductionGuideTransform::transformConstructor(clang::FunctionTemplateDecl*, clang::CXXConstructorDecl*): Assertion `getDepthAndIndex(NewParam).first == 0 && "Unexpected template parameter depth"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -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
1. :13:37: current parser token ';'
2. :5:23: parsing struct/union/class body 'S'
#0 0x00000000043b02f8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43b02f8)
#1 0x00000000043ad1b4 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43ad1b4)
#2 0x00000000043ad7dc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43ad7dc)
#3 0x00000000042ec828 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x0000703ac9845330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x0000703ac989eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
#6 0x0000703ac984527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x0000703ac98288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x0000703ac982881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x0000703ac983b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x00000000077f0581 (anonymous namespace)::ConvertConstructorToDeductionGuideTransform::transformConstructor(clang::FunctionTemplateDecl*, clang::CXXConstructorDecl*) SemaTemplateDeductionGuide.cpp:0:0
#11 0x00000000077f1afa clang::Sema::DeclareImplicitDeductionGuides(clang::TemplateDecl*, clang::SourceLocation) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x77f1afa)
#12 0x00000000073d7aff LookupDirect(clang::Sema&, clang::LookupResult&, clang::DeclContext const*) SemaLookup.cpp:0:0
#13 0x00000000073d7db2 clang::Sema::LookupQualifiedName(clang::LookupResult&, clang::DeclContext*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x73d7db2)
#14 0x00000000073c55c5 clang::Sema::CppLookupName(clang::LookupResult&, clang::Scope*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x73c55c5)
#15 0x00000000073c62c5 clang::Sema::LookupName(clang::LookupResult&, clang::Scope*, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x73c62c5)
#16 0x00000000070ad7c9 clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x70ad7c9)
#17 0x0000000007154b67 clang::Sema::ActOnCXXMemberDeclarator(clang::Scope*, clang::AccessSpecifier, clang::Declarator&, llvm::MutableArrayRef, clang::Expr*, clang::VirtSpecifiers const&, clang::InClassInitStyle) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7154b67)
#18 0x0000000006d108ee clang::Parser::ParseCXXClassMemberDeclaration(clang::AccessSpecifier, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::ParsingDeclRAIIObject*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d108ee)
#19 0x0000000006dbaff3 clang::Parser::ParseDeclarationAfterTemplate(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6dbaff3)
#20 0x0000000006dc72d3 clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (.part.0) ParseTemplate.cpp:0:0
#21 0x0000000006d0ff3d clang::Parser::ParseCXXClassMemberDeclaration(clang::AccessSpecifier, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::ParsingDeclRAIIObject*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d0ff3d)
#22 0x0000000006d11fef clang::Parser::ParseCXXClassMemberDeclarationWithPragmas(clang::AccessSpecifier&, clang::ParsedAttributes&, clang::TypeSpecifierType, clang::Decl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d11fef)
#23 0x0000000006d1256f clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, clang::SourceLocation, clang::ParsedAttributes&, unsigned int, clang::Decl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d1256f)
#24 0x0000000006d150eb clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d150eb)
#25 0x0000000006ce4a01 clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::LateParsedAttrList*, clang::ImplicitTypenameContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ce4a01)
#26 0x0000000006dbac09 clang::Parser::ParseDeclarationAfterTemplate(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6dbac09)
#27 0x0000000006dc72d3 clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (.part.0) ParseTemplate.cpp:0:0
#28 0x0000000006dc76ca clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6dc76ca)
#29 0x0000000006cf8080 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6cf8080)
#30 0x0000000006caebf6 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6caebf6)
#31 0x0000000006cafae5 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6cafae5)
#32 0x0000000006c8c9fa clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c8c9fa)
#33 0x0000000004eac4a8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4eac4a8)
#34 0x00000000051d7918 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x51d7918)
#35 0x0000000005164ead clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5164ead)
#36 0x00000000052b004d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x52b004d)
#37 0x0000000000db88ac cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdb88ac)
#38 0x0000000000daf4ba ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#39 0x0000000000daf63d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#40 0x0000000004f23759 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#41 0x00000000042ecc64 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42ecc64)
#42 0x0000000004f242c5 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#43 0x0000000004edccb2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4edccb2)
#44 0x0000000004ee14e7 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ee14e7)
#45 0x0000000004eeba45 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4eeba45)
#46 0x0000000000db4d9a clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdb4d9a)
#47 0x0000000000cd0efa main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcd0efa)
#48 0x0000703ac982a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#49 0x0000703ac982a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#50 0x0000000000daee65 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdaee65)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134
```
Contributor guide
Research direction
Start by running the C++ reproducer from the issue, then inspect ConvertConstructorToDeductionGuideTransform::transformConstructor in llvm/tools/clang/lib/Sema/SemaTemplateDeductionGuide.cpp and the DeclareImplicitDeductionGuides call path. Done means the reproducer no longer triggers the template-parameter-depth assertion or aborts clang.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100