Skip to content

Linker error when using std::map default constructor from Swift on Linux #61412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
egorzhdan opened this issue Oct 3, 2022 · 0 comments · Fixed by #66557
Closed

Linker error when using std::map default constructor from Swift on Linux #61412

egorzhdan opened this issue Oct 3, 2022 · 0 comments · Fixed by #66557
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c++ interop Feature: Interoperability with C++

Comments

@egorzhdan
Copy link
Contributor

See swift/test/Interop/Cxx/stdlib/use-std-map.swift.

using Map = std::map<int, int>;
let m = Map()
******************** TEST 'Swift(linux-x86_64) :: Interop/Cxx/stdlib/use-std-map.swift' FAILED ********************
Script:
--
: 'RUN: at line 1';   rm -rf "/home/build-user/build/buildbot_linux/swift-linux-x86_64/test-linux-x86_64/Interop/Cxx/stdlib/Output/use-std-map.swift.tmp" && mkdir -p "/home/build-user/build/buildbot_linux/swift-linux-x86_64/test-linux-x86_64/Interop/Cxx/stdlib/Output/use-std-map.swift.tmp" && /home/build-user/build/buildbot_linux/swift-linux-x86_64/bin/swiftc -target x86_64-unknown-linux-gnu -toolchain-stdlib-rpath  -module-cache-path /home/build-user/build/buildbot_linux/swift-linux-x86_64/swift-test-results/x86_64-unknown-linux-gnu/clang-module-cache -swift-version 4  -Xfrontend -define-availability -Xfrontend 'SwiftStdlib 9999:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999' -Xfrontend -define-availability -Xfrontend 'SwiftStdlib 5.0:macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2' -Xfrontend -define-availability -Xfrontend 'SwiftStdlib 5.1:macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0' -Xfrontend -define-availability -Xfrontend 'SwiftStdlib 5.2:macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4' -Xfrontend -define-availability -Xfrontend 'SwiftStdlib 5.3:macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0' -Xfrontend -define-availability -Xfrontend 'SwiftStdlib 5.4:macOS 11.3, iOS 14.5, watchOS 7.4, tvOS 14.5' -Xfrontend -define-availability -Xfrontend 'SwiftStdlib 5.5:macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0' -Xfrontend -define-availability -Xfrontend 'SwiftStdlib 5.6:macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4' -Xfrontend -define-availability -Xfrontend 'SwiftStdlib 5.7:macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0' -Xfrontend -define-availability -Xfrontend 'SwiftStdlib 5.8:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999'  -module-cache-path /home/build-user/build/buildbot_linux/swift-linux-x86_64/swift-test-results/x86_64-unknown-linux-gnu/clang-module-cache /home/build-user/swift/test/Interop/Cxx/stdlib/use-std-map.swift -I /home/build-user/swift/test/Interop/Cxx/stdlib/Inputs -Xfrontend -enable-experimental-cxx-interop -o /home/build-user/build/buildbot_linux/swift-linux-x86_64/test-linux-x86_64/Interop/Cxx/stdlib/Output/use-std-map.swift.tmp/a.out -module-name main  && echo /home/build-user/build/buildbot_linux/swift-linux-x86_64/test-linux-x86_64/Interop/Cxx/stdlib/Output/use-std-map.swift.tmp/a.out && /usr/bin/env LD_LIBRARY_PATH='/home/build-user/build/buildbot_linux/swift-linux-x86_64/lib/swift/linux'  /home/build-user/build/buildbot_linux/swift-linux-x86_64/test-linux-x86_64/Interop/Cxx/stdlib/Output/use-std-map.swift.tmp/a.out
--
Exit Code: 1

Command Output (stderr):
--
/tmp/lit-tmp-3vjnhydr/use-std-map-2481b4.o:use-std-map-2481b4.o:function $s4mainyycfU_: error: undefined reference to 'std::map<int, int, std::less<int>, std::allocator<std::pair<int const, int> > >::map()'
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
@egorzhdan egorzhdan added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c++ interop Feature: Interoperability with C++ labels Oct 3, 2022
egorzhdan added a commit that referenced this issue Jun 12, 2023
When a default constructor is declared, but does not have a body because it is defaulted (`= default;`), Swift did not emit the IR for it. This was causing linker error for types such as `std::map` in libstdc++ when someone tried to initialize such types from Swift.

rdar://110638499 / resolves #61412
egorzhdan added a commit that referenced this issue Jun 12, 2023
When a default constructor is declared, but does not have a body because it is defaulted (`= default;`), Swift did not emit the IR for it. This was causing linker error for types such as `std::map` in libstdc++ when someone tried to initialize such types from Swift.

rdar://110638499 / resolves #61412
egorzhdan added a commit that referenced this issue Jun 13, 2023
When a default constructor is declared, but does not have a body because it is defaulted (`= default;`), Swift did not emit the IR for it. This was causing linker error for types such as `std::map` in libstdc++ when someone tried to initialize such types from Swift.

rdar://110638499 / resolves #61412
(cherry picked from commit b459fb5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c++ interop Feature: Interoperability with C++
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant