Skip to content

Commit bddd2e1

Browse files
authored
Improved struct ordering (#1052)
1 parent eab5d4b commit bddd2e1

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

cppwinrt/code_writers.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2718,9 +2718,11 @@ struct __declspec(empty_bases) produce_dispatch_to_overridable<T, D, %>
27182718

27192719
auto depends = [](writer& w, complex_struct const& left, complex_struct const& right)
27202720
{
2721+
auto right_type = w.write_temp("%", right.type);
2722+
std::string right_as_ref = std::string("winrt::Windows::Foundation::IReference<") + right_type + ">";
27212723
for (auto&& field : left.fields)
27222724
{
2723-
if (w.write_temp("%", right.type) == field.second)
2725+
if (right_type == field.second || right_as_ref == field.second)
27242726
{
27252727
return true;
27262728
}

test/test_component/test_component.idl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,26 @@ namespace test_component
189189
Int32 OuterValue;
190190
};
191191
}
192+
193+
// structs can contain nullable types (IReference<>) as well as strings. These are the only non-POD types
194+
// Alphabetical sorting of names below is important to validate sort order in generated code. Metadata will
195+
// sort to alphabetical order. cppwinrt needs to re-establish dependencies in the IReference types to produce
196+
// correct output.
197+
struct NullableC
198+
{
199+
Single a1;
200+
Windows.Foundation.IReference<Single> a2;
201+
};
202+
203+
struct NullableB
204+
{
205+
Windows.Foundation.IReference<NullableC> a1;
206+
};
207+
208+
struct NullableA
209+
{
210+
Windows.Foundation.IReference<NullableB> a1;
211+
};
192212
}
193213

194214
namespace Parent

0 commit comments

Comments
 (0)