Improve C++ compound-assignment operator and C compound literal support#824
Merged
tannergooding merged 3 commits intoJul 18, 2026
Merged
Conversation
Projects operator+=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>= to op_AdditionAssignment and friends, consistent with the existing operator= to op_Assign mapping. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
A C compound literal (T){ ... } has no distinct C# spelling, so it projects as the object initializer emitted by its inner initializer list.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…argeting latest When generating latest code, a C++ compound-assignment operator that returns a pointer/reference to its declaring type and just returns \ his\/\*this\ is projected onto a C# 14 user-defined \operator +=\ with a void return, dropping the trailing return, rather than the \op_*Assignment\ metadata-name projection. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Maps C++ compound-assignment operators to their .NET metadata names so they project into C# instead of being skipped.
operator+=becomesop_AdditionAssignment,operator<<=becomesop_LeftShiftAssignment, and so on -- consistent with howoperator=is already emitted asop_Assign.Fixes #821
When generating
latestcode (.NET 10 / C# 14 currently), a compound-assignment operator is instead projected onto the new C# 14 user-defined compound-assignment operator feature. This is only safe for an instance member that returns a pointer/reference to its declaring type and whose body just returnsthis/*this, so the transform is gated on exactly that: the return type is dropped tovoid, the trailing return is elided, and the result ispublic void operator +=(MyStruct rhs) { ... }.An operator that returns something other than
this(e.g. a parameter) does not qualify and continues to emit under itsop_*Assignmentmetadata name -- covered by a regression case inCompoundAssignmentOperatorTest.Emits C compound literals (
(MyStruct){ .x = 1 }) as C# object initializers rather than dropping them.Fixes #819