Skip to content

Commit 5d8ff2b

Browse files
authored
Merge pull request #3105 from JordanMaples/patch-16
Add description and example to C26460
2 parents 8b795a6 + f40edeb commit 5d8ff2b

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

docs/code-quality/c26460.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,34 @@ ms.date: 03/22/2018
44
ms.topic: reference
55
f1_keywords: ["C26460"]
66
helpviewer_keywords: ["C26460"]
7+
description: CppCoreCheck rule that enforces C++ Core Guidelines Con.3
78
---
89
# C26460 USE_CONST_REFERENCE_ARGUMENTS
10+
The reference argument '%argument%' for function '%function%' can be marked as `const` (con.3).
911

10-
The reference argument '%argument%' for function '%function%' can be marked as `const`. See [C++ Core Guidelines con.3](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rconst-ref).
12+
Passing an object by reference indicates that the function has the potential modify the object. If that is not the intent of the function, it is better to mark the argument as a const reference.
13+
14+
## See also
15+
[C++ Core Guidelines con.3](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rconst-ref).
16+
17+
## Example
18+
```cpp
19+
struct MyStruct
20+
{
21+
void MemberFn1() const;
22+
void MemberFn2();
23+
};
24+
25+
26+
void Function1_Helper(const MyStruct&);
27+
void Function1(MyStruct& myStruct) // C26460, see comments below.
28+
{
29+
myStruct.MemberFn1(); // The member function is marked as const
30+
Function1_Helper(myStruct); // Function1_Helper takes a const reference
31+
}
32+
33+
void Function2(MyStruct& myStruct)
34+
{
35+
myStruct.MemberFn2(); // MemberFn2 is non-const and has the potential to modify data
36+
}
37+
```

0 commit comments

Comments
 (0)