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:
Doug Gregor
2025-09-19 15:57:17 -07:00
parent b13c2aeccd
commit 903937a78f
5 changed files with 33 additions and 0 deletions

View File

@@ -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)) {

View File

@@ -0,0 +1,9 @@
namespace OuterNS {
class MyPoint {
public:
double x, y;
};
}
#include "cxx-outer-ns.h"

View File

@@ -0,0 +1,7 @@
namespace OuterNS {
enum Color {
red,
green,
blue
};
}

View File

@@ -0,0 +1,3 @@
module CXXOuterNS {
header "cxx-outer-ns.h"
}

View File

@@ -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}}