Skip to content

Commit 828b3f0

Browse files
committed
suppress cppcheck mismatchingContainerExpression instead of rewriting
Keep the terse erase-remove one-liners from the ranges migration (#244) and silence cppcheck's mismatchingContainerExpression false positive instead. The warning fires because a range algorithm returns a subrange, so the first iterator's source expression (ranges::unique(x)) differs syntactically from the second (end(x)) even though end(subrange) is end(x) by construction. Reverts the earlier local-variable rewrite and adds line-anchored suppressions for the six affected call sites.
1 parent c87595d commit 828b3f0

7 files changed

Lines changed: 17 additions & 13 deletions

File tree

library/trees/extra_members/virtual_tree.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ array<vi, 2> compress_tree(vi subset) {
1616
rep(i, 1, len)
1717
subset.push_back(lca(subset[i - 1], subset[i]));
1818
ranges::sort(subset, {}, proj);
19-
auto dup = ranges::unique(subset);
20-
subset.erase(begin(dup), end(dup));
19+
subset.erase(begin(ranges::unique(subset)), end(subset));
2120
return {
2221
mono_st(subset,
2322
[&](int u, int v) { return in_subtree(u, v); }),

tests/.config/.cppcheck_suppression_list

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,9 @@ unusedFunction:../kactl/stress-tests/utilities/genTree.h:49
6262
containerOutOfBounds:../library/data_structures_[l,r)/uncommon/permutation_tree.hpp:85
6363
ctuOneDefinitionRuleViolation:../library/data_structures_[l,r)/bit.hpp:12
6464
ctuOneDefinitionRuleViolation:../library/data_structures_[l,r)/lazy_seg_tree.hpp:4
65+
mismatchingContainerExpression:../library/trees/extra_members/virtual_tree.hpp:19
66+
mismatchingContainerExpression:library_checker_aizu_tests/data_structures/bit_ordered_set.test.cpp:20
67+
mismatchingContainerExpression:library_checker_aizu_tests/data_structures/kth_smallest_pst.test.cpp:13
68+
mismatchingContainerExpression:library_checker_aizu_tests/data_structures/mode_query.test.cpp:13
69+
mismatchingContainerExpression:library_checker_aizu_tests/strings/sa_sort_pairs.test.cpp:13
70+
mismatchingContainerExpression:library_checker_aizu_tests/strings/single_matching_bs.test.cpp:73

tests/library_checker_aizu_tests/data_structures/bit_ordered_set.test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ int main() {
1717
compress.push_back(x);
1818
}
1919
ranges::sort(compress);
20-
auto dup = ranges::unique(compress);
21-
compress.erase(begin(dup), end(dup));
20+
compress.erase(begin(ranges::unique(compress)),
21+
end(compress));
2222
BIT bit(sz(compress));
2323
auto get_compressed_idx = [&](int val) -> int {
2424
int l = 0, r = sz(compress);

tests/library_checker_aizu_tests/data_structures/kth_smallest_pst.test.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ int main() {
1010
rep(i, 0, n) cin >> arr[i];
1111
vi sorted(arr);
1212
ranges::sort(sorted);
13-
auto dup = ranges::unique(sorted);
14-
sorted.erase(begin(dup), end(dup));
13+
sorted.erase(begin(ranges::unique(sorted)), end(sorted));
1514
for (int& val : arr) {
1615
int start = 0, end = sz(sorted);
1716
while (start + 1 < end) {

tests/library_checker_aizu_tests/data_structures/mode_query.test.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ int main() {
1010
rep(i, 0, n) cin >> a[i];
1111
vi comp(a);
1212
ranges::sort(comp);
13-
auto dup = ranges::unique(comp);
14-
comp.erase(begin(dup), end(dup));
13+
comp.erase(begin(ranges::unique(comp)), end(comp));
1514
for (int& val : a) {
1615
int start = 0, end = sz(comp);
1716
while (start + 1 < end) {

tests/library_checker_aizu_tests/strings/sa_sort_pairs.test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ int main() {
1010
for (int& x : arr) cin >> x;
1111
vi compress(arr);
1212
ranges::sort(compress);
13-
auto dup = ranges::unique(compress);
14-
compress.erase(begin(dup), end(dup));
13+
compress.erase(begin(ranges::unique(compress)),
14+
end(compress));
1515
for (int& x : arr) {
1616
int l = -1, r = int(sz(compress));
1717
while (r - l > 1) {

tests/library_checker_aizu_tests/strings/single_matching_bs.test.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ int main() {
6969
assert(sa_ri2 - sa_le2 == 1 + sa_ri - sa_le);
7070
vi matches_other(begin(lq_both.sa) + sa_le2,
7171
begin(lq_both.sa) + sa_ri2);
72-
auto rem = ranges::remove_if(matches_other,
73-
[&](int val) { return val >= sz(s) + 1; });
74-
matches_other.erase(begin(rem), end(rem));
72+
matches_other.erase(
73+
begin(ranges::remove_if(matches_other,
74+
[&](int val) { return val >= sz(s) + 1; })),
75+
end(matches_other));
7576
ranges::sort(matches_other);
7677
assert(matches == matches_other);
7778
}

0 commit comments

Comments
 (0)