Skip to content

Commit 06c8363

Browse files
Fix #11469 FP mismatchingContainerExpression warning (#5912)
1 parent 485df98 commit 06c8363

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

lib/astutils.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,15 @@ bool isTemporary(bool cpp, const Token* tok, const Library* library, bool unknow
439439
if (Token::simpleMatch(tok->astOperand1(), "typeid"))
440440
return false;
441441
if (tok->valueType()) {
442-
return tok->valueType()->reference == Reference::None;
442+
if (tok->valueType()->pointer > 0) {
443+
const Token* const parent = tok->astParent();
444+
if (Token::simpleMatch(parent, "&"))
445+
return true;
446+
if (Token::simpleMatch(parent, "return") && parent->valueType()->reference != Reference::None &&
447+
parent->valueType()->container && parent->valueType()->container->stdStringLike)
448+
return true;
449+
}
450+
return tok->valueType()->reference == Reference::None && tok->valueType()->pointer == 0;
443451
}
444452
const Token* ftok = nullptr;
445453
if (Token::simpleMatch(tok->previous(), ">") && tok->previous()->link())

test/teststl.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,17 +2031,14 @@ class TestStl : public TestFixture {
20312031
"}\n");
20322032
ASSERT_EQUALS("", errout.str());
20332033

2034-
check("struct S {\n"
2034+
check("struct S {\n" // #11469
20352035
" const std::vector<int>* vec() const { return &v; }\n"
20362036
" const std::vector<int> v;\n"
20372037
"};\n"
20382038
"void f(const S& a, const S& b) {\n"
20392039
" if (a.vec()->begin() - a.vec()->end() != b.vec()->begin() - b.vec()->end()) {}\n"
20402040
"}\n");
2041-
TODO_ASSERT_EQUALS("",
2042-
"[test.cpp:6]: (warning) Iterators to containers from different expressions 'a.vec()' and 'a.vec()' are used together.\n"
2043-
"[test.cpp:6]: (warning) Iterators to containers from different expressions 'b.vec()' and 'b.vec()' are used together.\n",
2044-
errout.str());
2041+
ASSERT_EQUALS("", errout.str());
20452042
}
20462043

20472044
void iteratorSameExpression() {

0 commit comments

Comments
 (0)