You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/code-quality/c26820.md
+7-5Lines changed: 7 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ helpviewer_keywords: ["C26820"]
7
7
---
8
8
# C26820
9
9
10
-
> Assigning by value when a const-reference would suffice, use const T& instead (p.9).
10
+
> Assigning by value when a const-reference would suffice, use const auto& instead (p.9).
11
11
12
12
For more information, see [P.9: Don't waste time or space](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#p9-dont-waste-time-or-space) in the C++ Core Guidelines.
13
13
@@ -31,13 +31,15 @@ This check covers non-obvious and easy-to-miss behavior when assigning a referen
31
31
This sample shows a variable definition that makes a potentially expensive copy when assigned a reference:
32
32
33
33
```cpp
34
-
MyClass& ref = ...;
35
-
auto var = ref; // C26820 (`var` takes a copy of the object referred to by `ref`)
34
+
const Object& MyClass::getRef() { ... }
35
+
...
36
+
auto ref = myclass.getRef(); // C26820 (`ref` takes a copy of the returned object)
36
37
```
37
38
38
39
To resolve this issue, declare the variable by using `const auto&` instead:
0 commit comments