mirror of
https://github.com/apple/swift.git
synced 2026-10-14 15:51:20 +02:00
The overloading rules in Swift and C++ are quite different. We were very conservative, and did not emit functions in an overload set that have the same arity. This PR relaxes this restriction by checking if the emitted C++ types would differ. rdar://157673175
26 lines
1.0 KiB
Swift
26 lines
1.0 KiB
Swift
// RUN: %empty-directory(%t)
|
|
// RUN: %target-swift-frontend %s -module-name Functions -clang-header-expose-decls=all-public -typecheck -verify -emit-clang-header-path %t/functions.h
|
|
// RUN: %FileCheck %s < %t/functions.h
|
|
|
|
// RUN: %check-interop-cxx-header-in-clang(%t/functions.h -DSWIFT_CXX_INTEROP_HIDE_STL_OVERLAY)
|
|
|
|
// Different arity should always work.
|
|
public func arityOverload() { }
|
|
public func arityOverload(_ x: Int) { }
|
|
|
|
// CHECK: void arityOverload() noexcept
|
|
// CHECK: void arityOverload(swift::Int x) noexcept
|
|
|
|
// Same-arity overloads with different C++ types should both be emitted.
|
|
public func overloadedFunc(_ x: Int) { }
|
|
public func overloadedFunc(_ y: Float) { }
|
|
|
|
public func overloadedFuncArgLabel(x _: Int) { }
|
|
public func overloadedFuncArgLabel(y _: Int) { }
|
|
|
|
// CHECK: void overloadedFunc(swift::Int x) noexcept
|
|
// CHECK: void overloadedFunc(float y) noexcept
|
|
|
|
// CHECK: // Unavailable in C++: Swift global function 'overloadedFuncArgLabel(y:)'. An overload with the same C++ parameter types already exists.
|
|
|