Skip to content

[cxx-interop] Members of private base classes should not be exposed #62831

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

Merged
merged 1 commit into from
Jan 18, 2023

Conversation

egorzhdan
Copy link
Contributor

@egorzhdan egorzhdan commented Jan 4, 2023

Trying to use members of C++ private base classes from Swift causes an assertion failure in ClangImporter:

<build dir>/swift/lib/swift/macosx/arm64/libcxxshim.h:2:66: error: cannot cast 'A' to its private base class 'B'
To __swift_interopStaticCast(From from) { return static_cast<To>(from); }
                                                                 ^

Assertion failed: (Val && "isa<> used on a null pointer"), function doit, file Casting.h, line 104.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
...
8  swift-frontend           llvm::isa_impl_cl<swift::FuncDecl, swift::Decl const*>::doit(swift::Decl const*) + 100
9  swift-frontend           llvm::isa_impl_wrap<swift::FuncDecl, swift::Decl const*, swift::Decl const*>::doit(swift::Decl const* const&) + 28
10 swift-frontend           llvm::isa_impl_wrap<swift::FuncDecl, swift::Decl* const, swift::Decl const*>::doit(swift::Decl* const&) + 40
11 swift-frontend           bool llvm::isa<swift::FuncDecl, swift::Decl*>(swift::Decl* const&) + 24
12 swift-frontend           llvm::cast_retty<swift::FuncDecl, swift::Decl*>::ret_type llvm::cast<swift::FuncDecl, swift::Decl>(swift::Decl*) + 28
13 swift-frontend           getInteropStaticCastDeclRefExpr(swift::ASTContext&, clang::Module const*, swift::Type, swift::Type) + 768
14 swift-frontend           synthesizeBaseClassMethodBody(swift::AbstractFunctionDecl*, void*)::$_30::operator()() const + 396
...

Such members should not be exposed.

rdar://103871000

Trying to use members of C++ private base classes from Swift causes an assertion failure in ClangImporter:

```
<build dir>/swift/lib/swift/macosx/arm64/libcxxshim.h:2:66: error: cannot cast 'A' to its private base class 'B'
To __swift_interopStaticCast(From from) { return static_cast<To>(from); }
                                                                 ^
```

Such members should not be exposed.

rdar://103871000
@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Jan 4, 2023
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test macOS

Copy link
Contributor

@zoecarver zoecarver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thanks, Egor!

@egorzhdan egorzhdan merged commit 054bae5 into main Jan 18, 2023
@egorzhdan egorzhdan deleted the egorzhdan/cxx-private-base-members branch January 18, 2023 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ interop Feature: Interoperability with C++
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants