-
Notifications
You must be signed in to change notification settings - Fork 10.5k
C++ Interop: support mutating attribute for C++ methods #39999
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 |
struct HasConstMethodAnnotatedAsMutating { | ||
int a; | ||
|
||
int annotatedMutating() const __attribute__((__swift_attr__("mutating"))) { |
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 test where there are multiple swift_attr
attributes. Also, you can spell it like this: struct __attribute__((swift_attr("mutating"))) X { };
.
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 test where there are multiple
swift_attr
attributes
Good idea, I added a test.
Also, you can spell it like this:
struct __attribute__((swift_attr("mutating"))) X { };
.
Hmm, that currently produces mutating struct X
which doesn't look right, but it also worked this way before this change :)
Do you think mutating
on a struct should apply it to all members methods?
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.
Do you think mutating on a struct should apply it to all members methods?
Hmm, I don't know. But the test looks good how it is now. I think that's the correct way to write it.
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.
This is a great improvement. As always, thanks for all your work on interop, Egor!
Feel free to merge this whenever you feel it's ready.
fc884b1
to
1cac51f
Compare
@swift-ci please smoke test |
1 similar comment
@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.
Still looks good. 🚢 it
This change teaches ClangImporter to import C++ methods marked with `__attribute__((__swift_attr__("mutating")))` as mutating in Swift. This is useful, for example, when a method mutates `this` despite being `const` in C++ (e.g. via `const_cast`).
1cac51f
to
0661293
Compare
@swift-ci please smoke test |
This change teaches ClangImporter to import C++ methods marked with
__attribute__((__swift_attr__("mutating")))
as mutating in Swift. This is useful, for example, when a method mutatesthis
despite beingconst
in C++ (e.g. viaconst_cast
).This is a follow-up after #38618.