Skip to content

Commit 2a64d42

Browse files
committed
Revert "Fixed a typo. local var name (#2284)"
This reverts commit 2722375. That typo was intentional as noted in the prose after the example (addmittedly hard to see)
1 parent d40a490 commit 2a64d42

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

CppCoreGuidelines.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ We can of course pass the number of elements along with the pointer:
767767

768768
void g2(int n)
769769
{
770-
f2(new int[n], n); // bad: a wrong number of elements can be passed to f()
770+
f2(new int[n], m); // bad: a wrong number of elements can be passed to f()
771771
}
772772

773773
Passing the number of elements as an argument is better (and far more common) than just passing the pointer and relying on some (unstated) convention for knowing or discovering the number of elements. However (as shown), a simple typo can introduce a serious error. The connection between the two arguments of `f2()` is conventional, rather than explicit.
@@ -785,7 +785,7 @@ The standard library resource management pointers fail to pass the size when the
785785

786786
void g3(int n)
787787
{
788-
f3(make_unique<int[]>(n), n); // bad: pass ownership and size separately
788+
f3(make_unique<int[]>(n), m); // bad: pass ownership and size separately
789789
}
790790

791791
##### Example

0 commit comments

Comments
 (0)