microsoft / microsoft/microsoft-ui-xaml

Wrong member initialization order in `XamlUserType`+`XamlMember`

Open
#11,097 0 comments 0 reactions 0 assignees View on GitHub
area-XamlCompiler bug team-Markup
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

### Describe the bug

I am using MSVC compiler option `/we` to treat warning `C5038` - out-of-order initialization of members - as an error.

The C++ code generator of a WinUI 3 project generates constructors for `XamlUserType` and `XamlMember` with members initialized out-of-order, so my project fails to compile.

Irrespective of my specific compiler settings the generator should emit correct code.

```
1> XamlTypeInfo.Impl.g.cpp
1>\Generated Files\XamlTypeInfo.Impl.g.cpp(308,15): error C5038: data member 'winrt::Lozenge::implementation::XamlUserType::_fullName' will be initialized after data member 'winrt::Lozenge::implementation::XamlUserType::_baseType'
1> (compiling source file '/Generated%20Files/XamlTypeInfo.Impl.g.cpp')
1>\Generated Files\XamlTypeInfo.Impl.g.cpp(575,15): error C5038: data member 'winrt::Lozenge::implementation::XamlMember::_provider' will be initialized after data member 'winrt::Lozenge::implementation::XamlMember::_name'
1> (compiling source file '/Generated%20Files/XamlTypeInfo.Impl.g.cpp')
```

### Steps to reproduce the bug

1. Create a new C++ project from template "WinUI Blank App (Packaged)"
2. Edit project properties -> Configuration Properties -> C/C++ -> Advanced -> Treat Specific Warnings As Error -> 5038 (also see screenshot);
Alternatively set the warning level for this error as an Additional Option: `/w1"5038"`.
4. Build
5. Observe the reported error (or warning).

### Expected behavior

`XamlTypeInfo.Impl.g.cpp` should compile without warnings or errors.
Irrespective of my specific compiler settings the generator should emit correct code.

### Screenshots

Image

### NuGet package version

1.8.251003001, 2.0.1

### Packaging type

Unpackaged, Packaged (MSIX)

### Windows version

Windows 11 version 24H2 (26100, June 2025 Update)

### IDE

Visual Studio 2022, Other

### Additional context

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by tracing the generator output for XamlTypeInfo.Impl.g.cpp, focusing on the constructors for XamlUserType and XamlMember and the member order shown by warning C5038. Verify the generated initialization order against the declarations, then reproduce with MSVC warning 5038 enabled and confirm the generated file builds without warnings or errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
desktop, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.