-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] Add tests for operator++()
that returns void
#59663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@swift-ci please smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had a Q on the mapping going on when return type is void
// CHECK: } | ||
|
||
// CHECK: struct HasPreIncrementOperatorWithVoidReturnType { | ||
// CHECK: func successor() -> HasPreIncrementOperatorWithVoidReturnType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this function be mutating and just update the value in lhs.value
or something? Feels odd that a void function in Cxx is being mapped into a function that returns a type (a copy I assume)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to map them differently for a couple reasons:
- We're importing
operator++
mainly to make it possible to increment C++ iterators from Swift. If the signature offunc successor() -> Self
changes depending on the return type ofoperator++
, we can't conform iterators to a single protocol (UnsafeCxxInputIterator
), and that defeats the purpose of importingoperator++
in the first place. - In most C++ use cases, there is no difference between
void operator++()
andT& operator++()
. I think it would be a bit confusing to introduce it in Swift.
let anotherReturnTypeResult: HasPreIncrementOperatorWithAnotherReturnType = anotherReturnType.successor() | ||
|
||
let voidReturnType = HasPreIncrementOperatorWithVoidReturnType() | ||
let voidReturnTypeResult: HasPreIncrementOperatorWithVoidReturnType = voidReturnType.successor() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a check that the successors .value is indeed 1 more than the predecessor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, we should have an execution test for this.
This pattern was discovered on `llvm::detail::SafeIntIterator` (`llvm/ADT/Sequence.h:153`): ```cpp // Pre Increment/Decrement void operator++() { offset(1); } void operator--() { offset(-1); } ``` rdar://95684692
90513c8
to
0f1ef6d
Compare
@swift-ci please smoke test |
This pattern was discovered on
llvm::detail::SafeIntIterator
(llvm/ADT/Sequence.h:153
):Previous patch: #59643.
rdar://95684692