mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Exempt C++ namespaces from internal-import checking
C++ namespaces always get imported into the bridging header's module for Reasons. Exempt them from internal-import checking, since we get checking for the namespace members that are actually used.
This commit is contained in:
@@ -2694,6 +2694,11 @@ void swift::recordRequiredImportAccessLevelForDecl(
|
||||
if (definingModule == dc->getParentModule())
|
||||
return;
|
||||
|
||||
// Egregious hack: if the declaration is for a C++ namespace, assume it's
|
||||
// accessible.
|
||||
if (isa_and_nonnull<clang::NamespaceDecl>(decl->getClangDecl()))
|
||||
return;
|
||||
|
||||
sf->registerRequiredAccessLevelForModule(definingModule, accessLevel);
|
||||
|
||||
if (auto attributedImport = sf->getImportAccessLevel(definingModule)) {
|
||||
|
||||
9
test/ClangImporter/Inputs/cxx-bridging-header.h
Normal file
9
test/ClangImporter/Inputs/cxx-bridging-header.h
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
namespace OuterNS {
|
||||
class MyPoint {
|
||||
public:
|
||||
double x, y;
|
||||
};
|
||||
}
|
||||
|
||||
#include "cxx-outer-ns.h"
|
||||
7
test/ClangImporter/Inputs/cxx-outer-ns.h
Normal file
7
test/ClangImporter/Inputs/cxx-outer-ns.h
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace OuterNS {
|
||||
enum Color {
|
||||
red,
|
||||
green,
|
||||
blue
|
||||
};
|
||||
}
|
||||
3
test/ClangImporter/Inputs/module.modulemap
Normal file
3
test/ClangImporter/Inputs/module.modulemap
Normal file
@@ -0,0 +1,3 @@
|
||||
module CXXOuterNS {
|
||||
header "cxx-outer-ns.h"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// RUN: %target-typecheck-verify-swift -internal-import-bridging-header %S/../Inputs/cxx-bridging-header.h -sdk %clang-importer-sdk -cxx-interoperability-mode=default -I %S/../Inputs
|
||||
|
||||
public func getRed() -> OuterNS.Color { OuterNS.red }
|
||||
// expected-error@-1{{function cannot be declared public because its result uses an internal type}}
|
||||
// expected-note@-2{{enum 'OuterNS' is imported by this file as 'internal' from bridging header}}
|
||||
|
||||
public func getX(point: OuterNS.MyPoint) -> Double { point.x }
|
||||
// expected-error@-1{{function cannot be declared public because its parameter uses an internal type}}
|
||||
// expected-note@-2{{enum 'OuterNS' is imported by this file as 'internal' from bridging header}}
|
||||
Reference in New Issue
Block a user