Quuxplusone / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
https://p1144.godbolt.org/z/jf67zx5hq
Other
1 stars 2 forks source link

ICE "Declaration context must already be complete!" in friend template #22

Open Quuxplusone opened 1 year ago

Quuxplusone commented 1 year ago

https://godbolt.org/z/6YE6PxMsq

template<class> struct Vector {
  template<class> class Node {};
};
template<class U>
struct S {
  template<class>
  friend class Vector<U>::Node;
};
S<int> s;

Clang fails an internal assertion.

clang++: /root/llvm-project/clang/lib/Sema/SemaLookup.cpp:2429: bool clang::Sema::LookupQualifiedName(clang::LookupResult&, clang::DeclContext*, bool): Assertion `(!isa<TagDecl>(LookupCtx) || LookupCtx->isDependentContext() || cast<TagDecl>(LookupCtx)->isCompleteDefinition() || cast<TagDecl>(LookupCtx)->isBeingDefined()) && "Declaration context must already be complete!"' failed.
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 <source>
1.  <source>:9:9: current parser token ';'
2.  <source>:5:8: instantiating class definition 'S<int>'
[...]
 #7 0x00007f3ecf067fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x0000000006699711 clang::Sema::LookupQualifiedName(clang::LookupResult&, clang::DeclContext*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6699711)
 #9 0x0000000006abd059 clang::TemplateDeclInstantiator::VisitClassTemplateDecl(clang::ClassTemplateDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6abd059)
#10 0x0000000006ab9b8b clang::TemplateDeclInstantiator::VisitFriendDecl(clang::FriendDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ab9b8b)
#11 0x0000000006a41cc3 clang::Sema::InstantiateClass(clang::SourceLocation, clang::CXXRecordDecl*, clang::CXXRecordDecl*, clang::MultiLevelTemplateArgumentList const&, clang::TemplateSpecializationKind, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a41cc3)
#12 0x0000000006a5ff5b clang::Sema::InstantiateClassTemplateSpecialization(clang::SourceLocation, clang::ClassTemplateSpecializationDecl*, clang::TemplateSpecializationKind, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a5ff5b)
#13 0x0000000006ae920f void llvm::function_ref<void ()>::callback_fn<clang::Sema::RequireCompleteTypeImpl(clang::SourceLocation, clang::QualType, clang::Sema::CompleteTypeKind, clang::Sema::TypeDiagnoser*)::'lambda'()>(long) SemaType.cpp:0:0
#14 0x000000000605f301 clang::Sema::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x605f301)
#15 0x0000000006af2727 clang::Sema::RequireCompleteTypeImpl(clang::SourceLocation, clang::QualType, clang::Sema::CompleteTypeKind, clang::Sema::TypeDiagnoser*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6af2727)
[...]

This reproduces back to almost the beginning of time. Clang 2.6.0 debug build fails a different assertion: https://godbolt.org/z/4fsxs6zP6

clang: warning: argument unused during compilation: '-gdwarf-4'
<source>:7:27: error: 'Node' does not name a tag member in the specified scope
  friend class Vector<U>::Node;
               ~~~~~~~~~~~^
clang-cc: /home/tonik/llvm-project/llvm/tools/clang/lib/AST/DeclBase.cpp:386: void clang::Decl::CheckAccessDeclContext() const: Assertion `(Access != AS_none || isa<TranslationUnitDecl>(this) || !isa<CXXRecordDecl>(getDeclContext())) && "Access specifier is AS_none inside a record decl"' failed.
Stack dump: [...]

Clang 2.7.0 and 2.8.0 are clean. Clang 2.9.0 fails with the same "Declaration context must already be complete!" assertion as Clang trunk (the rising Clang 18).