This commit is contained in:
chrchr-github 2023-06-26 13:37:33 +02:00 committed by GitHub
parent f4030c4b1a
commit a0c4e20e2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 0 deletions

View File

@ -1933,6 +1933,31 @@ private:
" 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() {