More robust template detection in clarifyCondition check based on Token::link. (#3818)
Create links between < and > only on non-C code. AStyle fix
This commit is contained in:
parent
3b5dabdb14
commit
452f95cea0
|
@ -156,7 +156,7 @@ void CheckOther::clarifyCondition()
|
|||
tok2 = tok2->link();
|
||||
else if (tok2->type() == Token::eComparisonOp) {
|
||||
// This might be a template
|
||||
if (!isC && Token::Match(tok2->previous(), "%var% <"))
|
||||
if (!isC && tok2->link())
|
||||
break;
|
||||
|
||||
clarifyConditionError(tok, tok->strAt(2) == "=", false);
|
||||
|
@ -170,6 +170,9 @@ void CheckOther::clarifyCondition()
|
|||
// using boolean result in bitwise operation ! x [&|^]
|
||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
||||
if (Token::Match(tok, "!|<|<=|==|!=|>|>=")) {
|
||||
if (tok->link()) // don't write false positives when templates are used
|
||||
continue;
|
||||
|
||||
const Token *tok2 = tok->next();
|
||||
|
||||
// Todo: There are false positives if '(' if encountered. It
|
||||
|
@ -186,8 +189,7 @@ void CheckOther::clarifyCondition()
|
|||
|
||||
if (Token::Match(tok2, "[&|^]")) {
|
||||
// don't write false positives when templates are used
|
||||
if (Token::Match(tok, "<|>") && (Token::Match(tok2, "& ,|>") ||
|
||||
Token::simpleMatch(tok2->previous(), "const &")))
|
||||
if (Token::Match(tok2, "&|* ,|>") || Token::simpleMatch(tok2->previous(), "const &"))
|
||||
continue;
|
||||
|
||||
// #3609 - CWinTraits<WS_CHILD|WS_VISIBLE>::..
|
||||
|
|
|
@ -2935,6 +2935,9 @@ bool Tokenizer::createLinks()
|
|||
|
||||
void Tokenizer::createLinks2()
|
||||
{
|
||||
if (isC())
|
||||
return;
|
||||
|
||||
std::stack<const Token*> type;
|
||||
std::stack<Token*> links;
|
||||
for (Token *token = list.front(); token; token = token->next()) {
|
||||
|
@ -7836,7 +7839,7 @@ void Tokenizer::simplifyComma()
|
|||
|
||||
void Tokenizer::removeExceptionSpecifications()
|
||||
{
|
||||
for(Token* tok = list.front(); tok; tok = tok->next()) {
|
||||
for (Token* tok = list.front(); tok; tok = tok->next()) {
|
||||
if (Token::Match(tok, ") const| throw (")) {
|
||||
if (tok->next()->str() == "const") {
|
||||
Token::eraseTokens(tok->next(), tok->linkAt(3));
|
||||
|
|
|
@ -124,6 +124,7 @@ private:
|
|||
TEST_CASE(clarifyCondition3); // if (! a & b)
|
||||
TEST_CASE(clarifyCondition4); // ticket #3110
|
||||
TEST_CASE(clarifyCondition5); // #3609 CWinTraits<WS_CHILD|WS_VISIBLE>..
|
||||
TEST_CASE(clarifyCondition6); // #3818
|
||||
TEST_CASE(bitwiseOnBoolean); // if (bool & bool)
|
||||
|
||||
TEST_CASE(comparisonOfBoolExpressionWithInt1);
|
||||
|
@ -3657,6 +3658,15 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void clarifyCondition6() {
|
||||
check("template<class Y>\n"
|
||||
"SharedPtr& operator=( SharedPtr<Y> const & r ) {\n"
|
||||
" px = r.px;\n"
|
||||
" return *this;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void bitwiseOnBoolean() { // 3062
|
||||
check("void f(_Bool a, _Bool b) {\n"
|
||||
" if(a & b) {}\n"
|
||||
|
|
Loading…
Reference in New Issue