mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
If a non-member operator is declared in a C++ namespace, we previously imported it as a static member of the enum that represents the C++ namespace.
This is not always correct under Swift rules for operators. In pure Swift, this code is valid:
```
public protocol UnsafeCxxRandomAccessIterator {
static func +=(lhs: inout Self, rhs: Int)
}
enum std {
public struct A : UnsafeCxxRandomAccessIterator {
public static func += (lhs: inout A, rhs: Int) {
}
}
}
```
but this is not valid:
```
public protocol UnsafeCxxRandomAccessIterator {
static func +=(lhs: inout Self, rhs: Int)
}
enum std {
public struct A : UnsafeCxxRandomAccessIterator {}
public static func += (lhs: inout A, rhs: Int) {}
}
// error: Member operator '+=' must have at least one argument of type 'std'
```
This caused assertion failures in SILGen when conforming C++ iterator types to `UnsafeCxxRandomAccessIterator`.
1.9 KiB
1.9 KiB