Issue |
126435
|
Summary |
Lambda with by-copy capture returned from function in module has copy constructor deleted
|
Labels |
|
Assignees |
|
Reporter |
es1024
|
Reproducer (https://godbolt.org/z/79q6Gsdas):
```
// module.cppm
export module mod;
export auto make_lambda(int x) {
return [x] { return x; };
}
// test.cc
import mod;
void test() {
auto f = make_lambda(0);
auto g = f;
}
```
yields
```
test.cc:4:8: error: no matching constructor for initialization of '(lambda at /app/module.cppm:3:10)'
4 | auto g = f;
| ^ ~
1 error generated.
```
A similar example where we instead create a std::function triggers an assertion (https://godbolt.org/z/bhjqr45bE):
```
// module.cppm
export module mod;
export auto make_lambda(int x) {
return [x] { return x; };
}
// test.cc
#include <functional>
import mod;
void test() {
std::function<int(void)> f = make_lambda(0);
}
```
```
/opt/compiler-explorer/clang-assertions-trunk/bin/clang++ --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -stdlib=libc++ -g -std=gnu++20 -MD -MT CMakeFiles/test_modules.dir/test.cc.o -MF CMakeFiles/test_modules.dir/test.cc.o.d @CMakeFiles/test_modules.dir/test.cc.o.modmap -o CMakeFiles/test_modules.dir/test.cc.o -c /app/test.cc
clang++: /root/llvm-project/clang/include/clang/AST/DeclCXX.h:871: void clang::CXXRecordDecl::setImplicitCopyConstructorIsDeleted(): Assertion `(data().DefaultedCopyConstructorIsDeleted || needsOverloadResolutionForCopyConstructor()) && "Copy constructor should not be deleted"' 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++ --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -stdlib=libc++ -g -std=gnu++20 -MD -MT CMakeFiles/test_modules.dir/test.cc.o -MF CMakeFiles/test_modules.dir/test.cc.o.d @CMakeFiles/test_modules.dir/test.cc.o.modmap -o CMakeFiles/test_modules.dir/test.cc.o -c /app/test.cc
1. <eof> parser at end of file
2. /opt/compiler-explorer/clang-assertions-trunk-20250209/bin/../include/c++/v1/__functional/function.h:952:30: instantiating function definition 'std::function<int ()>::function<(lambda at /app/module.cppm:3:10), void>'
3. /opt/compiler-explorer/clang-assertions-trunk-20250209/bin/../include/c++/v1/__functional/function.h:378:34: instantiating function definition 'std::__function::__value_func<int ()>::__value_func<(lambda at /app/module.cppm:3:10), 0>'
4. /opt/compiler-explorer/clang-assertions-trunk-20250209/bin/../include/c++/v1/__functional/function.h:358:25: instantiating function definition 'std::__function::__value_func<int ()>::__value_func<(lambda at /app/module.cppm:3:10), std::allocator<(lambda at /app/module.cppm:3:10)>>'
5. /opt/compiler-explorer/clang-assertions-trunk-20250209/bin/../include/c++/v1/__functional/function.h:274:34: instantiating function definition 'std::__function::__func<(lambda at /app/module.cppm:3:10), std::allocator<(lambda at /app/module.cppm:3:10)>, int ()>::__func'
#0 0x0000000003e72268 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3e72268)
#1 0x0000000003e6ff24 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3e6ff24)
#2 0x0000000003dbc3f8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x000076b807842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x000076b8078969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x000076b807842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x000076b8078287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x000076b80782871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x000076b807839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x00000000068bdbd5 clang::Sema::DeclareImplicitCopyConstructor(clang::CXXRecordDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x68bdbd5)
#10 0x0000000006b5a40f void llvm::function_ref<void ()>::callback_fn<clang::Sema::LookupConstructors(clang::CXXRecordDecl*)::'lambda'()>(long) SemaLookup.cpp:0:0
#11 0x0000000007cc5691 clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7cc5691)
#12 0x0000000006b5a743 clang::Sema::LookupConstructors(clang::CXXRecordDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b5a743)
#13 0x0000000006b2b082 TryConstructorInitialization(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>, clang::QualType, clang::QualType, clang::InitializationSequence&, bool, bool) SemaInit.cpp:0:0
#14 0x0000000006b33fad clang::InitializationSequence::InitializeFrom(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b33fad)
#15 0x00000000068696ec clang::Sema::BuildMemberInitializer(clang::ValueDecl*, clang::Expr*, clang::SourceLocation) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x68696ec)
#16 0x000000000707a618 clang::Sema::InstantiateMemInitializers(clang::CXXConstructorDecl*, clang::CXXConstructorDecl const*, clang::MultiLevelTemplateArgumentList const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x707a618)
#17 0x00000000070806c2 clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x70806c2)
#18 0x000000000707e65e clang::Sema::PerformPendingInstantiations(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x707e65e)
#19 0x00000000070809a6 clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x70809a6)
#20 0x000000000707e65e clang::Sema::PerformPendingInstantiations(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x707e65e)
#21 0x00000000070809a6 clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x70809a6)
#22 0x000000000707e65e clang::Sema::PerformPendingInstantiations(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x707e65e)
#23 0x00000000070809a6 clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x70809a6)
#24 0x000000000707e65e clang::Sema::PerformPendingInstantiations(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x707e65e)
#25 0x00000000065f1fed clang::Sema::ActOnEndOfTranslationUnitFragment(clang::Sema::TUFragmentKind) (.part.0) Sema.cpp:0:0
#26 0x00000000065f27e2 clang::Sema::ActOnEndOfTranslationUnit() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x65f27e2)
#27 0x000000000645d0eb clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x645d0eb)
#28 0x000000000644f4aa clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x644f4aa)
#29 0x0000000004807ea8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4807ea8)
#30 0x0000000004ace8f5 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ace8f5)
#31 0x0000000004a522be clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4a522be)
#32 0x0000000004bbd20e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4bbd20e)
#33 0x0000000000d4c6cf cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd4c6cf)
#34 0x0000000000d4414a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#35 0x000000000484e489 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
#36 0x0000000003dbc8a4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3dbc8a4)
#37 0x000000000484ea7f 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
#38 0x0000000004811bfd clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4811bfd)
#39 0x0000000004812c7e 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+++0x4812c7e)
#40 0x000000000481ac35 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x481ac35)
#41 0x0000000000d494c3 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd494c3)
#42 0x0000000000c11f74 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc11f74)
#43 0x000076b807829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#44 0x000076b807829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#45 0x0000000000d43bf5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd43bf5)
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs