[llvm-bugs] [Bug 47804] New: Undeclared identifier causes DeclContext confusion during template instantiation "declaration not instantiated in this scope".

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Oct 12 08:41:17 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=47804

            Bug ID: 47804
           Summary: Undeclared identifier causes DeclContext confusion
                    during template instantiation "declaration not
                    instantiated in this scope".
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: erich.keane at intel.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

The below example, all of it is necessary as far as I can tell:

 template<class InputIt, class Pred>
   bool all_of(InputIt first, Pred p);

   template <typename T> void load_test() {
     //int output;
     all_of(output, [](T x){ return x; });
   }

   int main() {
     load_test<int>();
     return 0;
   }



See output/assert below.  The most interesting thing to me here is that the
error :
repro.cpp:6:34: error: variable 'x' cannot be implicitly captured in a lambda
with no capture-default specified

This happens before template instantiation, and to me is likely the cause of
the problem here. I've been trying to figure out the error a bit, but I don't
see how we end up in the wrong declaration context here. For some reason, we
don't seem to KNOW we're in the lambda?  I can't seem to figure out how we got
lost here.

See https://godbolt.org/z/aYWa1M for a minimal example that doesn't actually
assert (since I've removed the template stuff).







bash-4.2$ ./bin/clang -cc1 repro.cpp
repro.cpp:6:10: error: use of undeclared identifier 'output'
  all_of(output, [](T x){ return x; });
         ^
repro.cpp:6:34: error: variable 'x' cannot be implicitly captured in a lambda
with no capture-default specified
  all_of(output, [](T x){ return x; });
                                 ^
repro.cpp:6:23: note: 'x' declared here
  all_of(output, [](T x){ return x; });
                      ^
repro.cpp:6:18: note: lambda expression begins here
  all_of(output, [](T x){ return x; });
                 ^
clang:
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Sema/SemaTemplateInstantiate.cpp:3621:
llvm::PointerUnion<clang::Decl*, llvm::SmallVector<clang::VarDecl*, 4>*>*
clang::LocalInstantiationScope::findInstantiationOf(const clang::Decl*):
Assertion `isa<LabelDecl>(D) && "declaration not instantiated in this scope"'
failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash
backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: ./bin/clang -cc1 repro.cpp
1.      <eof> parser at end of file
2.      repro.cpp:4:28: instantiating function definition 'load_test<int>'
 #0 0x0000000004d14921 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
/iusers/ekeane1/workspaces/llvm-project/llvm/lib/Support/Unix/Signals.inc:563:22
 #1 0x0000000004d149c5 PrintStackTraceSignalHandler(void*)
/iusers/ekeane1/workspaces/llvm-project/llvm/lib/Support/Unix/Signals.inc:627:1
 #2 0x0000000004d129bb llvm::sys::RunSignalHandlers()
/iusers/ekeane1/workspaces/llvm-project/llvm/lib/Support/Signals.cpp:71:20
 #3 0x0000000004d14369 SignalHandler(int)
/iusers/ekeane1/workspaces/llvm-project/llvm/lib/Support/Unix/Signals.inc:405:1
 #4 0x00007ff59e2ff5e0 __restore_rt (/lib64/libpthread.so.0+0xf5e0)
 #5 0x00007ff59ce781f7 raise (/lib64/libc.so.6+0x351f7)
 #6 0x00007ff59ce798e8 abort (/lib64/libc.so.6+0x368e8)
 #7 0x00007ff59ce71266 __assert_fail_base (/lib64/libc.so.6+0x2e266)
 #8 0x00007ff59ce71312 (/lib64/libc.so.6+0x2e312)
 #9 0x000000000875fd6b
clang::LocalInstantiationScope::findInstantiationOf(clang::Decl const*)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Sema/SemaTemplateInstantiate.cpp:3621:3
#10 0x00000000087c1ff3 clang::Sema::FindInstantiatedDecl(clang::SourceLocation,
clang::NamedDecl*, clang::MultiLevelTemplateArgumentList const&, bool)
(.localalias.0)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:5802:70
#11 0x00000000087572a3 (anonymous
namespace)::TemplateInstantiator::TransformDecl(clang::SourceLocation,
clang::Decl*)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Sema/SemaTemplateInstantiate.cpp:1242:76
#12 0x0000000008763ff2 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformDeclRefExpr(clang::DeclRefExpr*)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Sema/TreeTransform.h:9958:30
#13 0x0000000008759275 (anonymous
namespace)::TemplateInstantiator::TransformDeclRefExpr(clang::DeclRefExpr*)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Sema/SemaTemplateInstantiate.cpp:1739:1
#14 0x0000000008763311 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*)
/iusers/ekeane1/workspaces/llvm-project/build/tools/clang/include/clang/AST/StmtNodes.inc:979:1
#15 0x00000000087694f6 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformInitializer(clang::Expr*, bool)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Sema/TreeTransform.h:3753:43
#16 0x0000000008789440 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformReturnStmt(clang::ReturnStmt*)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Sema/TreeTransform.h:7474:14
#17 0x00000000087688c2 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*,
clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::StmtDiscardKind)
/iusers/ekeane1/workspaces/llvm-project/build/tools/clang/include/clang/AST/StmtNodes.inc:527:1
#18 0x000000000878fc6c clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*,
bool)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Sema/TreeTransform.h:7099:16
#19 0x0000000008784169 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Sema/TreeTransform.h:7086:1
#20 0x0000000008767c7f clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*,
clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::StmtDiscardKind)
/iusers/ekeane1/workspaces/llvm-project/build/tools/clang/include/clang/AST/StmtNodes.inc:73:1
#21 0x000000000876bab6 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformLambdaBody(clang::LambdaExpr*,
clang::Stmt*)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Sema/TreeTransform.h:12694:1
#22 0x0000000008761adc clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformLambdaExpr(clang::LambdaExpr*)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Sema/TreeTransform.h:12666:15
#23 0x0000000008756bcc (anonymous
namespace)::TemplateInstantiator::TransformLambdaExpr(clang::LambdaExpr*)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Sema/SemaTemplateInstantiate.cpp:1127:72
#24 0x0000000008763617 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*)
/iusers/ekeane1/workspaces/llvm-project/build/tools/clang/include/clang/AST/StmtNodes.inc:1095:1
#25 0x00000000087694f6 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformInitializer(clang::Expr*, bool)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Sema/TreeTransform.h:3753:43
#26 0x000000000876a01a clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformExprs(clang::Expr* const*, unsigned
int, bool, llvm::SmallVectorImpl<clang::Expr*>&, bool*)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Sema/TreeTransform.h:3905:14
#27 0x00000000087712a7 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformCallExpr(clang::CallExpr*)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Sema/TreeTransform.h:10481:3
#28 0x0000000008762f5f clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*)
/iusers/ekeane1/workspaces/llvm-project/build/tools/clang/include/clang/AST/StmtNodes.inc:813:1
#29 0x0000000008768aab clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*,
clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::StmtDiscardKind)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Sema/TreeTransform.h:3675:18
#30 0x000000000878fc6c clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*,
bool)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Sema/TreeTransform.h:7099:16
#31 0x0000000008784169 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Sema/TreeTransform.h:7086:1
#32 0x0000000008767c7f clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*,
clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::StmtDiscardKind)
/iusers/ekeane1/workspaces/llvm-project/build/tools/clang/include/clang/AST/StmtNodes.inc:73:1
#33 0x000000000875f42b clang::Sema::SubstStmt(clang::Stmt*,
clang::MultiLevelTemplateArgumentList const&)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Sema/SemaTemplateInstantiate.cpp:3465:38
#34 0x00000000087bedb3
clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation,
clang::FunctionDecl*, bool, bool, bool)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:4830:45
#35 0x00000000087c3250 clang::Sema::PerformPendingInstantiations(bool)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:6083:32
#36 0x0000000007c0cfdb
clang::Sema::ActOnEndOfTranslationUnitFragment(clang::Sema::TUFragmentKind)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Sema/Sema.cpp:959:66
#37 0x0000000007c0d237 clang::Sema::ActOnEndOfTranslationUnit()
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Sema/Sema.cpp:1002:9
#38 0x0000000007ae0750
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Parse/Parser.cpp:692:12
#39 0x0000000007adc081 clang::ParseAST(clang::Sema&, bool, bool)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Parse/ParseAST.cpp:158:37
#40 0x000000000587be93 clang::ASTFrontendAction::ExecuteAction()
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1057:11
#41 0x000000000587b7fb clang::FrontendAction::Execute()
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Frontend/FrontendAction.cpp:954:38
#42 0x00000000058166ee
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:984:42
#43 0x00000000059f3154
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
/iusers/ekeane1/workspaces/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:278:38
#44 0x000000000222dd26 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*)
/iusers/ekeane1/workspaces/llvm-project/clang/tools/driver/cc1_main.cpp:240:40
#45 0x0000000002223c37 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&)
/iusers/ekeane1/workspaces/llvm-project/clang/tools/driver/driver.cpp:330:20
#46 0x0000000002224338 main
/iusers/ekeane1/workspaces/llvm-project/clang/tools/driver/driver.cpp:407:26
#47 0x00007ff59ce64c05 __libc_start_main (/lib64/libc.so.6+0x21c05)
#48 0x00000000022224d9 _start (./bin/clang+0x22224d9)
Aborted (core dumped)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201012/6369dad7/attachment-0001.html>


More information about the llvm-bugs mailing list