Skip to content

Commit fbb4901

Browse files
committed
[cxx-interop] only ban strstr, sin, cos, and exit on darwin where the conflict with declarations in the Darwin module; improve the test.
1 parent 4a790ad commit fbb4901

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3197,15 +3197,18 @@ namespace {
31973197
// presence in the C++ standard library will cause overloading
31983198
// ambiguities or other type checking errors in Swift.
31993199
auto isAlternativeCStdlibFunctionFromTextualHeader =
3200-
[](const clang::FunctionDecl *d) -> bool {
3200+
[this](const clang::FunctionDecl *d) -> bool {
32013201
// stdlib.h might be a textual header in libc++'s module map.
32023202
// in this case, check for known ambiguous functions by their name
32033203
// instead of checking if they come from the `std` module.
32043204
if (!d->getDeclName().isIdentifier())
32053205
return false;
3206-
return d->getName() == "abs" || d->getName() == "div" ||
3207-
d->getName() == "strstr" || d->getName() == "sin" ||
3208-
d->getName() == "cos" || d->getName() == "exit";
3206+
if (d->getName() == "abs" || d->getName() == "div")
3207+
return true;
3208+
if (Impl.SwiftContext.LangOpts.Target.isOSDarwin())
3209+
return d->getName() == "strstr" || d->getName() == "sin" ||
3210+
d->getName() == "cos" || d->getName() == "exit";
3211+
return false;
32093212
};
32103213
if (decl->getOwningModule() &&
32113214
(decl->getOwningModule()

test/Interop/Cxx/stdlib/avoid-import-cxx-math.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
import CxxStdlib
66

77
func test() {
8-
let x: Float = 1.0
9-
let y: Float = 2.0
8+
let x: Double = 1.0
9+
let y: Double = 2.0
1010

1111
let _ = pow(x, y)
1212

1313
let _ = abs(x)
1414
let _ = div(42, 2)
15+
let _ = sin(x)
16+
let _ = cos(x)
1517
let _ = strstr("a", "aaa")
1618

1719
exit(0)

0 commit comments

Comments
 (0)