Skip to content

Commit 4913bbe

Browse files
Merge pull request MicrosoftDocs#4433 from MugBergerFries/patch-2
Updated C26495
2 parents 648e409 + 09cb423 commit 4913bbe

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

docs/code-quality/c26495.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
---
22
title: C26495
3-
ms.date: 05/23/2022
3+
ms.date: 08/18/2022
44
ms.topic: reference
5-
f1_keywords: ["C26495"]
5+
f1_keywords: ["C26495", "MEMBER_UNINIT", "__WARNING_MEMBER_UNINIT"]
66
helpviewer_keywords: ["C26495"]
77
description: CppCoreCheck rule that enforces C++ Core Guidelines Type.6
88
---
9-
# C26495 MEMBER_UNINIT
9+
# Warning C26495
1010

11-
> Variable '*identifier*' is uninitialized. Always initialize a member variable (type.6).
11+
> Variable '\**parameter-name*' is uninitialized. Always initialize a member variable (type.6).
1212
1313
## Remarks
1414

1515
A member variable isn't initialized by a constructor or by an initializer. Make sure all variables are initialized by the end of construction. For more information, see C++ Core Guidelines [Type.6](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#SS-type) and [C.48](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c48-prefer-in-class-initializers-to-member-initializers-in-constructors-for-constant-initializers).
1616

17+
Code analysis name: MEMBER_UNINIT
18+
1719
## Example
1820

21+
The following sample generates warning C26495 because the member variable `value` isn't initialized when a `MyStruct` object is created.
22+
1923
```cpp
2024
struct MyStruct
2125
{
@@ -24,12 +28,12 @@ struct MyStruct
2428
};
2529
```
2630

27-
To fix the warning, add in-class initialization to all of the member variables:
31+
To resolve the issue, you can add in-class initialization to all of the member variables.
2832

2933
```cpp
3034
struct MyStruct
3135
{
32-
int value{};
36+
int value{}; // empty brace initializer sets value to 0
3337
MyStruct() {} // no warning, MyStruct::value is set via default member initialization
3438
};
3539
```

0 commit comments

Comments
 (0)