Skip to content

Commit

Permalink
Make it more explicit which oparators can be preeded by their operands
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Feb 26, 2024
1 parent 47173be commit 61f9489
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ static void compileUnaryOp(Token *&tok, AST_state& state, void (*f)(Token *&tok,
state.depth--;
}

if (!state.op.empty() && !(unaryop->str() == "&" && precedes(state.op.top(), unaryop))) {
if (!state.op.empty() && (!precedes(state.op.top(), unaryop) || unaryop->isIncDecOp() || Token::Match(unaryop, "[({[]"))) { // nullary functions, empty lists/arrays
unaryop->astOperand1(state.op.top());
state.op.pop();
}
Expand Down
6 changes: 3 additions & 3 deletions test/teststl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3946,17 +3946,17 @@ class TestStl : public TestFixture {
void size4() { // #2652 - don't warn about vector/deque
check("void f(std::vector<int> &v) {\n"
" if (v.size() > 0U) {}\n"
"}");
"}", false, Standards::CPP03);
ASSERT_EQUALS("", errout.str());

check("void f(std::deque<int> &v) {\n"
" if (v.size() > 0U) {}\n"
"}");
"}", false, Standards::CPP03);
ASSERT_EQUALS("", errout.str());

check("void f(std::array<int,3> &a) {\n"
" if (a.size() > 0U) {}\n"
"}");
"}", false, Standards::CPP03);
ASSERT_EQUALS("", errout.str());
}

Expand Down

0 comments on commit 61f9489

Please sign in to comment.