Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/Sema/TypeCheckAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "swift/Basic/Assertions.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/Type.h"

using namespace swift;

Expand Down Expand Up @@ -1862,6 +1863,15 @@ bool isFragileClangType(clang::QualType type) {
// Builtin clang types are compatible with library evolution.
if (underlyingTypePtr->isBuiltinType())
return false;
if (const auto *ft = dyn_cast<clang::FunctionType>(underlyingTypePtr)) {
if (const auto *fpt =
dyn_cast<clang::FunctionProtoType>(underlyingTypePtr)) {
for (auto paramTy : fpt->getParamTypes())
if (isFragileClangType(paramTy))
return true;
}
return isFragileClangType(ft->getReturnType());
}
// Pointers to non-fragile types are non-fragile.
if (underlyingTypePtr->isPointerType())
return isFragileClangType(underlyingTypePtr->getPointeeType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ struct CStruct {
}
#endif

typedef void (*my_sighandler_t)(int);
typedef void (*my_other_cb)(CxxStruct);

//--- test.swift

import CxxModule
Expand All @@ -55,3 +58,9 @@ public func useCxxEnum(_ x: CxxEnum) { // expected-error {{cannot use enum 'CxxE
// expected-error@+1 {{cannot use struct 'CxxStruct' here; C++ types from imported module 'CxxModule' do not support library evolution}}
public func usesCxxStruct(_ x: CxxStruct) {
}

public func usesTypeAliasToFuncPtr(_ x: my_sighandler_t) {
}

public func usesTypeAliasToFuncPtr2(_ x: my_other_cb) { // expected-error {{cannot use type alias 'my_other_cb' here; C++ types from imported module 'CxxModule' do not support library evolution}}
}