Skip to content

Commit 173329e

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 744783a commit 173329e

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
@@ -3200,15 +3200,18 @@ namespace {
32003200
// presence in the C++ standard library will cause overloading
32013201
// ambiguities or other type checking errors in Swift.
32023202
auto isAlternativeCStdlibFunctionFromTextualHeader =
3203-
[](const clang::FunctionDecl *d) -> bool {
3203+
[this](const clang::FunctionDecl *d) -> bool {
32043204
// stdlib.h might be a textual header in libc++'s module map.
32053205
// in this case, check for known ambiguous functions by their name
32063206
// instead of checking if they come from the `std` module.
32073207
if (!d->getDeclName().isIdentifier())
32083208
return false;
3209-
return d->getName() == "abs" || d->getName() == "div" ||
3210-
d->getName() == "strstr" || d->getName() == "sin" ||
3211-
d->getName() == "cos" || d->getName() == "exit";
3209+
if (d->getName() == "abs" || d->getName() == "div")
3210+
return true;
3211+
if (Impl.SwiftContext.LangOpts.Target.isOSDarwin())
3212+
return d->getName() == "strstr" || d->getName() == "sin" ||
3213+
d->getName() == "cos" || d->getName() == "exit";
3214+
return false;
32123215
};
32133216
if (decl->getOwningModule() &&
32143217
(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)