Skip to content

Commit 0cf7845

Browse files
authored
Merge pull request #3106 from JordanMaples/patch-18
Add description and example to C26461
2 parents 5d8ff2b + 1fa8173 commit 0cf7845

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

docs/code-quality/c26461.md

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

10-
The pointer argument '%argument%' for function '%function%' can be marked as a pointer to `const`. See [C++ Core Guidelines con.3](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rconst-ref).
11+
The pointer argument '%argument%' for function '%function%' can be marked as a pointer to `const` (con.3).
12+
13+
A function with a `T*` argument has the potential to modify the value of the object. If that is not the intent of the function, it is better to make the pointer a `const T*` instead.
14+
15+
## See also
16+
[C++ Core Guidelines con.3](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rconst-ref).
17+
18+
## Example
19+
```cpp
20+
struct MyStruct
21+
{
22+
void MemberFn1() const;
23+
void MemberFn2();
24+
};
25+
26+
void Function1_Helper(const MyStruct* myStruct);
27+
void Function1(MyStruct* myStruct) // C26461, neither of the operations on myStruct would modify the pointer's value.
28+
{
29+
if (!myStruct)
30+
return;
31+
32+
myStruct->MemberFn1(); // The member function is const
33+
Function1_Helper(myStruct); // Function1_Helper takes a const
34+
}
35+
36+
void Function2(MyStruct* myStruct)
37+
{
38+
if (!myStruct)
39+
return;
40+
41+
myStruct->MemberFn2(); // The member function is non-const, so no C26461 will be issued
42+
}
43+
```

0 commit comments

Comments
 (0)