Skip to content
Open
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
5 changes: 5 additions & 0 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3727,6 +3727,11 @@ namespace {
clang::OverloadedOperatorKind cxxOperatorKind) {
if (cxxOperatorKind == clang::OverloadedOperatorKind::OO_None)
return true;
// If this operator was renamed via swift_name attribute, the imported
// Swift function already has the specified name. Do not apply any special
// handling to it.
if (importedName.hasCustomName())
return true;

auto dc = func->getDeclContext();
auto typeDecl = dc->getSelfNominalTypeDecl();
Expand Down
5 changes: 5 additions & 0 deletions test/Interop/Cxx/operators/Inputs/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ module NonMemberOutOfLine {
header "non-member-out-of-line.h"
requires cplusplus
}

module RenamedOperators {
header "renamed-operators.h"
requires cplusplus
}
16 changes: 16 additions & 0 deletions test/Interop/Cxx/operators/Inputs/renamed-operators.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
struct HasRenamedOperatorStar {
int value;

const int &operator*() const __attribute__((swift_name("dereference()"))) {
return value;
}
};

struct HasRenamedOperatorPlusPlus {
int value;

HasRenamedOperatorPlusPlus &operator++() __attribute__((swift_name("plusPlus()"))) {
value++;
return *this;
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: %target-swift-ide-test -print-module -module-to-print=RenamedOperators -I %S/Inputs -source-filename=x -cxx-interoperability-mode=upcoming-swift | %FileCheck %s

// CHECK: struct HasRenamedOperatorStar {
// CHECK-NOT: prefix static func * (lhs: HasRenamedOperatorStar)
// CHECK: func dereference() -> UnsafePointer<Int32>
// CHECK: }

// CHECK: struct HasRenamedOperatorPlusPlus {
// CHECK-NOT: prefix static func ++ (lhs: HasRenamedOperatorPlusPlus)
// CHECK: mutating func plusPlus() -> UnsafeMutablePointer<HasRenamedOperatorPlusPlus>
// CHECK: }
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: %target-typecheck-verify-swift -I %S/Inputs -cxx-interoperability-mode=default

import RenamedOperators

let star = HasRenamedOperatorStar(value: 123)
_ = *star // expected-error {{'*' is not a prefix unary operator}}

let plusPlus = HasRenamedOperatorStar(value: 123)
plusPlus++ // expected-error {{cannot find operator '++' in scope; did you mean '+= 1'?}}