Skip to content

Commit ad8463a

Browse files
authored
Add description and example to C26462
1 parent 82a0dad commit ad8463a

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

docs/code-quality/c26462.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,26 @@ ms.date: 03/22/2018
44
ms.topic: reference
55
f1_keywords: ["C26462"]
66
helpviewer_keywords: ["C26462"]
7+
description: CppCoreCheck rule that enforces C++ Core Guidelines Con.4
78
---
89
# C26462 USE_CONST_POINTER_FOR_VARIABLE
910

10-
The value pointed to by '%variable%' is assigned only once, mark it as a pointer to `const`. See [C++ Core Guidelines con.4](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#con4-use-const-to-define-objects-with-values-that-do-not-change-after-construction).
11+
The value pointed to by '%variable%' is assigned only once, mark it as a pointer to `const` (con.4).
12+
13+
Pointers to variables whose values remain unchanged should be marked as const.
14+
15+
## See also
16+
[C++ Core Guidelines con.4](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#con4-use-const-to-define-objects-with-values-that-do-not-change-after-construction).
17+
18+
## Example
19+
```cpp
20+
void useVal(int val);
21+
22+
void function1(int* ptr)
23+
{
24+
int* p = ptr; // C26462, the value pointed to by p is unmodified
25+
ptr = nullptr;
26+
27+
useVal(*p);
28+
}
29+
```

0 commit comments

Comments
 (0)