Skip to content

Use in-class initializers for constant member values (C.48)#20449

Merged
DHowett merged 1 commit into
microsoft:mainfrom
nsfxdyj:dev/c48-in-class-initializers
Jul 20, 2026
Merged

Use in-class initializers for constant member values (C.48)#20449
DHowett merged 1 commit into
microsoft:mainfrom
nsfxdyj:dev/c48-in-class-initializers

Conversation

@nsfxdyj

@nsfxdyj nsfxdyj commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Part of #962. Moves constant member initializers out of constructor initializer lists and into in-class member initializers, per C++ Core Guidelines C.48.

This is a first, focused batch covering six classes whose constructors initialized members with only constant values:

  • ConsoleObjectHeader (server): 5 counter members; ctor now = default
  • ConsoleHandleData (server): _pvClientPointer, _pClientInput
  • ConsoleProcessHandle (server): pInputHandle, pOutputHandle, fRootProcess, _ulTerminateCount
  • OutputCellRect (buffer/out): _rows, _cols; default ctor now = default
  • Icon (interactivity/win32): 5 handle/state members
  • Window (interactivity/win32): 6 pointer/flag/dpi members

Validation

  • Full solution build (OpenConsole.slnx, x64 Debug): 0 errors
  • Conhost.Unit.Tests (ObjectTests covers ConsoleObjectHeader): passed
  • TextBuffer.Unit.Tests: 13/13 passed

Initialization values and ordering are unchanged; no behavioral difference. Follow-up PRs can cover the remaining candidates (e.g. Settings, OutputCellIterator, GdiEngine) once this approach is agreed on.

Move constant member initializers out of constructor initializer
lists and into in-class member initializers, per C++ Core Guidelines
C.48 and the coding standards discussion in microsoft#962.

This first batch covers six classes whose constructors initialized
members with only constant values:

- ConsoleObjectHeader (server): 5 counter members; ctor now defaulted
- ConsoleHandleData (server): _pvClientPointer, _pClientInput
- ConsoleProcessHandle (server): pInputHandle, pOutputHandle,
  fRootProcess, _ulTerminateCount
- OutputCellRect (buffer/out): _rows, _cols; default ctor defaulted
- Icon (interactivity/win32): 5 handle/state members
- Window (interactivity/win32): 6 pointer/flag/dpi members

Initialization values and ordering are unchanged; no behavioral
difference. Validated with a full solution build (0 errors) and the
Conhost unit tests covering these classes (ObjectTests, TextBuffer).

Part of microsoft#962
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@nsfxdyj

nsfxdyj commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@lhecker

lhecker commented Jul 20, 2026

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.

@DHowett
DHowett merged commit 840f548 into microsoft:main Jul 20, 2026
16 checks passed
nsfxdyj added a commit to nsfxdyj/terminal that referenced this pull request Jul 20, 2026
Second batch for microsoft#962, following the same approach as microsoft#20449.

Moves 24 scalar constant member initializers for the Settings class
out of the constructor initializer list and into in-class member
initializers. Initializers that depend on file-local constexpr
values (DEFAULT_NUMBER_OF_COMMANDS, DEFAULT_NUMBER_OF_BUFFERS),
Windows macros composed in the .cpp (FOREGROUND_*, SW_SHOWNORMAL,
BYTE_MAX, Cursor::CURSOR_SMALL_SIZE), or runtime state
(ServiceLocator::LocateGlobals().uiOEMCP) intentionally remain in
the constructor, since moving them to the header would break the
build or is not a constant initializer.

No behavioral change. Validated with an incremental solution build
(0 errors).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants