Merge pull request #2700 from pfultz2/afterConditionFunction

Extend scope of afterCondition until end of function
This commit is contained in:
Daniel Marjamäki 2020-06-30 08:28:08 +02:00 committed by GitHub
commit 1567ccf97b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 11 deletions

View File

@ -37,6 +37,15 @@
# define NOEXCEPT
#endif
// C++11 noreturn
#if (defined(__GNUC__) && (__GNUC__ >= 5)) \
|| (defined(__clang__) && (defined (__cplusplus)) && (__cplusplus >= 201103L)) \
|| defined(__CPPCHECK__)
# define NORETURN [[noreturn]]
#else
# define NORETURN
#endif
#define REQUIRES(msg, ...) class=typename std::enable_if<__VA_ARGS__::value>::type
#include <string>

View File

@ -3560,7 +3560,6 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s
typeTok = typeTok->next();
if (Token::Match(typeTok, ",|)")) { // #8333
symbolDatabase->mTokenizer->syntaxError(typeTok);
return;
}
// skip over qualification
while (Token::Match(typeTok, "%type% ::"))

View File

@ -1352,7 +1352,7 @@ bool TemplateSimplifier::getTemplateNamePositionTemplateFunction(const Token *to
// skip decltype(...)
else if (Token::simpleMatch(tok->next(), "decltype (")) {
const Token * end = tok->linkAt(2)->previous();
while (tok && tok->next() && tok != end) {
while (tok->next() && tok != end) {
tok = tok->next();
namepos++;
}
@ -1361,7 +1361,7 @@ bool TemplateSimplifier::getTemplateNamePositionTemplateFunction(const Token *to
if (closing) {
if (closing->strAt(1) == "(" && Tokenizer::isFunctionHead(closing->next(), ";|{|:", true))
return true;
while (tok && tok->next() && tok->next() != closing) {
while (tok->next() && tok->next() != closing) {
tok = tok->next();
namepos++;
}
@ -1384,7 +1384,7 @@ bool TemplateSimplifier::getTemplateNamePositionTemplateVariable(const Token *to
// skip decltype(...)
else if (Token::simpleMatch(tok->next(), "decltype (")) {
const Token * end = tok->linkAt(2);
while (tok && tok->next() && tok != end) {
while (tok->next() && tok != end) {
tok = tok->next();
namepos++;
}
@ -1393,7 +1393,7 @@ bool TemplateSimplifier::getTemplateNamePositionTemplateVariable(const Token *to
if (closing) {
if (Token::Match(closing->next(), "=|;"))
return true;
while (tok && tok->next() && tok->next() != closing) {
while (tok->next() && tok->next() != closing) {
tok = tok->next();
namepos++;
}

View File

@ -607,16 +607,16 @@ private:
public:
/** Syntax error */
void syntaxError(const Token *tok, const std::string &code = "") const;
NORETURN void syntaxError(const Token *tok, const std::string &code = "") const;
/** Syntax error. Unmatched character. */
void unmatchedToken(const Token *tok) const;
NORETURN void unmatchedToken(const Token *tok) const;
/** Syntax error. C++ code in C file. */
void syntaxErrorC(const Token *tok, const std::string &what) const;
NORETURN void syntaxErrorC(const Token *tok, const std::string &what) const;
/** Warn about unknown macro(s), configuration is recommended */
void unknownMacroError(const Token *tok1) const;
NORETURN void unknownMacroError(const Token *tok1) const;
private:

View File

@ -4232,7 +4232,7 @@ struct ValueFlowConditionHandler {
// TODO: constValue could be true if there are no assignments in the conditional blocks and
// perhaps if there are no && and no || in the condition
bool constValue = false;
forward(after, top->scope()->bodyEnd, cond.vartok, values, constValue);
forward(after, scope->bodyEnd, cond.vartok, values, constValue);
}
}
}

View File

@ -262,7 +262,7 @@ private:
" }\n"
" tok->str();\n"
"}\n");
TODO_ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (warning, inconclusive) Possible null pointer dereference: tok - otherwise it is redundant to check it against null.\n", "", errout.str());
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (warning) Either the condition 'tok' is redundant or there is possible null pointer dereference: tok.\n", errout.str());
check("int foo(const Token *tok)\n"
"{\n"