#7883 hang: CheckOther::checkFuncArgNamesDifferent() template code in .h. Activate language check for header files + Small refactoring

This commit is contained in:
Alexander Mai 2017-05-03 20:36:26 +02:00
parent 1ec9b8c5b4
commit f54a6f085b
2 changed files with 75 additions and 79 deletions

View File

@ -7289,8 +7289,7 @@ bool Tokenizer::duplicateDefinition(Token ** tokPtr)
return false;
}
namespace {
const std::set<std::string> stdFunctionsPresentInC = make_container< std::set<std::string> > () <<
static const std::set<std::string> stdFunctionsPresentInC = make_container< std::set<std::string> > () <<
"strcat" <<
"strcpy" <<
"strncat" <<
@ -7298,7 +7297,6 @@ namespace {
"free" <<
"malloc" <<
"strdup";
}
void Tokenizer::simplifyStd()
{
@ -8053,11 +8051,11 @@ void Tokenizer::checkConfiguration() const
void Tokenizer::validateC() const
{
if (!isC())
if (isCPP())
return;
for (const Token *tok = tokens(); tok; tok = tok->next()) {
// That might trigger false positives, but it's much faster to have this truncated pattern
if (Token::simpleMatch(tok, "const_cast|dynamic_cast|reinterpret_cast|static_cast <"))
if (Token::Match(tok, "const_cast|dynamic_cast|reinterpret_cast|static_cast <"))
syntaxErrorC(tok, "C++ cast <...");
// Template function..
if (Token::Match(tok, "%name% < %name% > (")) {
@ -8175,19 +8173,20 @@ const Token * Tokenizer::findGarbageCode() const
return nullptr;
}
static const std::set<std::string> controlFlowKeywords = make_container< std::set<std::string> > () <<
"goto" <<
"do" <<
"if" <<
"else" <<
"for" <<
"while" <<
"switch" <<
"break" <<
"continue" <<
"return";
bool Tokenizer::isGarbageExpr(const Token *start, const Token *end)
{
std::set<std::string> controlFlowKeywords;
controlFlowKeywords.insert("goto");
controlFlowKeywords.insert("do");
controlFlowKeywords.insert("if");
controlFlowKeywords.insert("else");
controlFlowKeywords.insert("for");
controlFlowKeywords.insert("while");
controlFlowKeywords.insert("switch");
controlFlowKeywords.insert("break");
controlFlowKeywords.insert("continue");
controlFlowKeywords.insert("return");
for (const Token *tok = start; tok != end; tok = tok->next()) {
if (controlFlowKeywords.find(tok->str()) != controlFlowKeywords.end())
return true;
@ -8647,8 +8646,7 @@ void Tokenizer::simplifyAttribute()
}
}
namespace {
const std::set<std::string> keywords = make_container< std::set<std::string> >()
static const std::set<std::string> keywords = make_container< std::set<std::string> >()
<< "volatile"
<< "inline"
<< "_inline"
@ -8657,7 +8655,6 @@ namespace {
<< "register"
<< "__restrict"
<< "__restrict__" ;
}
// Remove "volatile", "inline", "register", "restrict", "override", "final", "static" and "constexpr"
// "restrict" keyword
// - New to 1999 ANSI/ISO C standard
@ -9009,9 +9006,8 @@ void Tokenizer::simplifyBitfields()
}
namespace {
// Types and objects in std namespace that are neither functions nor templates
const std::set<std::string> stdTypes = make_container<std::set<std::string> >() <<
static const std::set<std::string> stdTypes = make_container<std::set<std::string> >() <<
"string"<< "wstring"<< "u16string"<< "u32string" <<
"iostream"<< "ostream"<< "ofstream"<< "ostringstream" <<
"istream"<< "ifstream"<< "istringstream"<< "fstream"<< "stringstream" <<
@ -9032,13 +9028,13 @@ namespace {
"internal"<< "left"<< "right" <<
"fpos"<< "streamoff"<< "streampos"<< "streamsize";
const std::set<std::string> stdTemplates = make_container<std::set<std::string> >() <<
static const std::set<std::string> stdTemplates = make_container<std::set<std::string> >() <<
"array"<< "basic_string"<< "bitset"<< "deque"<< "list"<< "map"<< "multimap" <<
"priority_queue"<< "queue"<< "set"<< "multiset"<< "stack"<< "vector"<< "pair" <<
"iterator"<< "iterator_traits" <<
"unordered_map"<< "unordered_multimap"<< "unordered_set"<< "unordered_multiset" <<
"tuple"<< "function";
const std::set<std::string> stdFunctions = make_container<std::set<std::string> >() <<
static const std::set<std::string> stdFunctions = make_container<std::set<std::string> >() <<
"getline" <<
"for_each"<< "find"<< "find_if"<< "find_end"<< "find_first_of" <<
"adjacent_find"<< "count"<< "count_if"<< "mismatch"<< "equal"<< "search"<< "search_n" <<
@ -9054,7 +9050,6 @@ namespace {
"min"<< "max"<< "min_element"<< "max_element"<< "lexicographical_compare"<< "next_permutation"<< "prev_permutation" <<
"advance"<< "back_inserter"<< "distance"<< "front_inserter"<< "inserter" <<
"make_pair"<< "make_shared"<< "make_tuple";
}
// Add std:: in front of std classes, when using namespace std; was given

View File

@ -825,6 +825,7 @@ private:
ASSERT_THROW(tokenizeAndStringify(";std::map<int,int> m;",false,false,Settings::Native,"test.c"), InternalError);
ASSERT_THROW(tokenizeAndStringify(";template<class T> class X { };",false,false,Settings::Native,"test.c"), InternalError);
ASSERT_THROW(tokenizeAndStringify("int X<Y>() {};",false,false,Settings::Native,"test.c"), InternalError);
ASSERT_THROW(tokenizeAndStringify("void foo(int i) { reinterpret_cast<char>(i) };",false,false,Settings::Native,"test.h"), InternalError);
}
void syntax_case_default() { // correct syntax