Reviewed C handling in CheckOther::clarifyCondition, never treat x<..> as a template in C files.
This commit is contained in:
parent
d2dbaca24b
commit
3db58bb57f
|
@ -147,6 +147,8 @@ void CheckOther::clarifyCondition()
|
||||||
if (!_settings->isEnabled("style"))
|
if (!_settings->isEnabled("style"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
const bool isC = _tokenizer->isC();
|
||||||
|
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
||||||
if (Token::Match(tok, "( %var% [=&|^]")) {
|
if (Token::Match(tok, "( %var% [=&|^]")) {
|
||||||
for (const Token *tok2 = tok->tokAt(3); tok2; tok2 = tok2->next()) {
|
for (const Token *tok2 = tok->tokAt(3); tok2; tok2 = tok2->next()) {
|
||||||
|
@ -154,7 +156,7 @@ void CheckOther::clarifyCondition()
|
||||||
tok2 = tok2->link();
|
tok2 = tok2->link();
|
||||||
else if (tok2->type() == Token::eComparisonOp) {
|
else if (tok2->type() == Token::eComparisonOp) {
|
||||||
// This might be a template
|
// This might be a template
|
||||||
if (!_tokenizer->isC() && Token::Match(tok2->previous(), "%var% <"))
|
if (!isC && Token::Match(tok2->previous(), "%var% <"))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
clarifyConditionError(tok, tok->strAt(2) == "=", false);
|
clarifyConditionError(tok, tok->strAt(2) == "=", false);
|
||||||
|
@ -189,7 +191,7 @@ void CheckOther::clarifyCondition()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// #3609 - CWinTraits<WS_CHILD|WS_VISIBLE>::..
|
// #3609 - CWinTraits<WS_CHILD|WS_VISIBLE>::..
|
||||||
if (Token::Match(tok->previous(), "%var% <")) {
|
if (!isC && Token::Match(tok->previous(), "%var% <")) {
|
||||||
const Token *tok3 = tok2;
|
const Token *tok3 = tok2;
|
||||||
while (Token::Match(tok3, "[&|^] %var%"))
|
while (Token::Match(tok3, "[&|^] %var%"))
|
||||||
tok3 = tok3->tokAt(2);
|
tok3 = tok3->tokAt(2);
|
||||||
|
|
|
@ -3548,6 +3548,9 @@ private:
|
||||||
check("void f() { A<x &> a; }");
|
check("void f() { A<x &> a; }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void f() { a(x<y|z,0); }", "test.c"); // filename is c => there are never templates
|
||||||
|
ASSERT_EQUALS("[test.c:1]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses\n", errout.str());
|
||||||
|
|
||||||
check("class A<B&,C>;", "test.C");
|
check("class A<B&,C>;", "test.C");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue