Skip to content

Commit

Permalink
Add tests for #10587, #11539
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Jun 26, 2023
1 parent 9dc38f8 commit 90f2a46
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/testunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1933,6 +1933,31 @@ class TestUnusedVar : public TestFixture {
" return v.begin()->b;\n"
"}\n");
ASSERT_EQUALS("", errout.str());

checkStructMemberUsage("int f(int s) {\n" // #10587
" const struct S { int a, b; } Map[] = { { 0, 1 }, { 2, 3 } };\n"
" auto it = std::find_if(std::begin(Map), std::end(Map), [&](const auto& m) { return s == m.a; });\n"
" if (it != std::end(Map))\n"
" return it->b;\n"
" return 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());

checkStructMemberUsage("int f(int s) {\n"
" const struct S { int a, b; } Map[] = { { 0, 1 }, { 2, 3 } };\n"
" for (auto&& m : Map)\n"
" if (m.a == s)\n"
" return m.b;\n"
" return 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());

checkStructMemberUsage("struct R { bool b{ false }; };\n" // #11539
"void f(std::optional<R> r) {\n"
" if (r.has_value())\n"
" std::cout << r->b;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}

void structmember_macro() {
Expand Down

0 comments on commit 90f2a46

Please sign in to comment.