User/benkuhn/struct ordering#1052
Merged
kennykerr merged 4 commits intomastermicrosoft/cppwinrt:masterfrom Oct 28, 2021
user/benkuhn/struct-orderingmicrosoft/cppwinrt:user/benkuhn/struct-orderingCopy head branch name to clipboard
Merged
User/benkuhn/struct ordering#1052kennykerr merged 4 commits intomastermicrosoft/cppwinrt:masterfrom user/benkuhn/struct-orderingmicrosoft/cppwinrt:user/benkuhn/struct-orderingCopy head branch name to clipboard
kennykerr merged 4 commits intomastermicrosoft/cppwinrt:masterfrom
user/benkuhn/struct-orderingmicrosoft/cppwinrt:user/benkuhn/struct-orderingCopy head branch name to clipboard
Conversation
kennykerr
approved these changes
Oct 28, 2021
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.
Fixes #1049. Partly.
cppwinrt separates the headers by namespace, and within each namespace into 'passes' where each pass has specific responsibilities. Structs for a given namespace all appear in the same header. There are limits to what C++ /WinRT can resolve in terms of struct dependencies across headers, but within a header, it sorts definitions so that structs consumed by other structs appear first. In the absence of dependencies, it follows metadata order, which is alphabetical.
There's an overlooked corner case in the dependency sorting. structs generally only contain plain data, with two exceptions: strings and nullable types (instances of IReference). The dependency checking code only looked at the exact type name when evaluating dependencies. If a struct contains an IReference<> to another struct, the dependency checking code would not detect the template parameter inside the IReference type.
Since this is a very constrained special case, I've chosen to code a fix that looks specifically for IReference. MidlRT and other tooling enforce this constraint. It could be generalized to parse template parameters out of the type name, but given there's only one exact type that can appear, this is complete and sufficient as written.