<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/95778>95778</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang assertion "dependent lookup context that isn't the current instantiation?"
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:frontend
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
OCHyams
</td>
</tr>
</table>
<pre>
The following code which includes an error (undeclared function used in the lambda) causes an assertion in Clang ([SemaExprMember.cpp#L1016](https://github.com/llvm/llvm-project/blob/3cead572e91d3de5f8cb458f09ab39302e289d22/clang/lib/Sema/SemaExprMember.cpp#L1016)):
[Godbolt example here](https://godbolt.org/z/q7ojehW5b).
---
`$ cat test.cpp`
```
class X {
public:
template <typename Fn>
X(Fn&& F);
void m();
};
template <class T>
struct Y {
void operator()() const {
T a;
X x = X([&]() {
undeclared_function(&a);
});
x.m();
}
};
void fun() {
Y<char>()();
}
```
`$ clang test.cpp`
```
<source>:14:9: error: use of undeclared identifier 'undeclared_function'
14 | undeclared_function(&a);
| ^
<source>:13:21: note: while substituting into a lambda expression here
13 | X x = X([&]() {
| ^
<source>:21:12: note: in instantiation of member function 'Y<char>::operator()' requested here
21 | Y<char>()();
| ^
clang++: /root/llvm-project/clang/lib/Sema/SemaExprMember.cpp:1013: clang::ExprResult clang::Sema::BuildMemberReferenceExpr(clang::Expr*, clang::QualType, clang::SourceLocation, bool, const clang::CXXScopeSpec&, clang::SourceLocation, clang::NamedDecl*, clang::LookupResult&, const clang::TemplateArgumentListInfo*, const clang::Scope*, bool, clang::Sema::ActOnMemberAccessExtraArgs*): Assertion `(SS.isEmpty() ? !BaseType->isDependentType() || computeDeclContext(BaseType) : !isDependentScopeSpecifier(SS) || computeDeclContext(SS)) && "dependent lookup context that isn't the current instantiation?"' 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. <eof> parser at end of file
2. <source>:11:8: instantiating function definition 'Y<char>::operator()'
#0 0x0000000003a18218 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a18218)
#1 0x0000000003a15efc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a15efc)
#2 0x000000000395dfd8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x0000709933242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007099332969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x0000709933242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x00007099332287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x000070993322871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x0000709933239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x0000000006aeecd7 clang::Sema::BuildMemberReferenceExpr(clang::Expr*, clang::QualType, clang::SourceLocation, bool, clang::CXXScopeSpec const&, clang::SourceLocation, clang::NamedDecl*, clang::LookupResult&, clang::TemplateArgumentListInfo const*, clang::Scope const*, bool, clang::Sema::ActOnMemberAccessExtraArgs*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6aeecd7)
#10 0x0000000007007ef8 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformMemberExpr(clang::MemberExpr*) SemaTemplateInstantiate.cpp:0:0
#11 0x0000000006fd39e2 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#12 0x0000000006fdf771 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCallExpr(clang::CallExpr*) SemaTemplateInstantiate.cpp:0:0
#13 0x0000000006fd3623 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#14 0x000000000701019f clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*, clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::StmtDiscardKind) SemaTemplateInstantiate.cpp:0:0
#15 0x0000000007010f94 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*, bool) SemaTemplateInstantiate.cpp:0:0
#16 0x000000000701877a clang::Sema::SubstStmt(clang::Stmt*, clang::MultiLevelTemplateArgumentList const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x701877a)
#17 0x0000000007070a78 clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7070a78)
#18 0x000000000706ecdf clang::Sema::PerformPendingInstantiations(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x706ecdf)
#19 0x00000000065049cf clang::Sema::ActOnEndOfTranslationUnitFragment(clang::Sema::TUFragmentKind) (.part.0) Sema.cpp:0:0
#20 0x00000000065051ca clang::Sema::ActOnEndOfTranslationUnit() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x65051ca)
#21 0x000000000637e0fa clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x637e0fa)
#22 0x000000000637181a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x637181a)
#23 0x00000000042f8148 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42f8148)
#24 0x000000000457c619 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x457c619)
#25 0x000000000450355e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x450355e)
#26 0x0000000004663c8e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4663c8e)
#27 0x0000000000c6bc3c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc6bc3c)
#28 0x0000000000c64f9a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#29 0x000000000433b429 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
#30 0x000000000395e484 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x395e484)
#31 0x000000000433ba1f 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
#32 0x00000000043018c5 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43018c5)
#33 0x000000000430232d 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+++0x430232d)
#34 0x000000000430a025 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x430a025)
#35 0x0000000000c69145 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc69145)
#36 0x0000000000b430c4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xb430c4)
#37 0x0000709933229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#38 0x0000709933229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#39 0x0000000000c64a4e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc64a4e)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWt9z2zhw_mvgF4w0JPj7wQ-ybN3lmmvSyNfmnjQguJR4IQEeACZy__oOQFIiaDmJW-umnXocSyGBxbcfFt8uQFKlqj0HuEXRHYrub2inD0Leflj_-kQbdZOL4un28QC4FHUtvlV8j5koAH87VOyAK87qrgCFKccgpZAYkbTjBbCaSihw2XGmK8Fxp6DAFcf6ALimTV5QRDLMaKf6zlQpkLZlxfG6pnxvLKHobgsNfTi28ndocpBL1raIBO99z49RdI9IetC6VShYIbJBZLOv9KHLl0w0iGzq-uv4sWil-AuYRmST1yJHZBMwoEWUEMj8IiggKlOWh1FaehnNgyzwCJA0KwhBZMMMHGOoMh0NoOHjBVwkM7_BCnn3yBv_Rne_iCIXtcZwpE1bAz6AhIs-9O2WQppB_xORzd-J-AsO_xHliGTLqdXFYuEMEnuIhJhRjTUobUHF3vle_2v_y2qqFP6MUXLXX2i7vK7YCTXGGGto2ppqwChY66cWOG0AbzgKHoY2nxFJNxyRGJEYb6zTd1M8xshXURW4MXM5vZ3cz5pOx-qxPZ7GUVp2TOM_z2AHs6IFSbWQg3X7FzPBlZ42NT-PmJ4G7K98xkeMgnvrg4l8MsSTMXHufA7l3RjKtk1Mp-70Fo1Tzy4el3PfbbsXWLBelR1_hgP_a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