#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,16 +7289,14 @@ bool Tokenizer::duplicateDefinition(Token ** tokPtr)
return false; return false;
} }
namespace { static const std::set<std::string> stdFunctionsPresentInC = make_container< std::set<std::string> > () <<
const std::set<std::string> stdFunctionsPresentInC = make_container< std::set<std::string> > () << "strcat" <<
"strcat" << "strcpy" <<
"strcpy" << "strncat" <<
"strncat" << "strncpy" <<
"strncpy" << "free" <<
"free" << "malloc" <<
"malloc" << "strdup";
"strdup";
}
void Tokenizer::simplifyStd() void Tokenizer::simplifyStd()
{ {
@ -8053,11 +8051,11 @@ void Tokenizer::checkConfiguration() const
void Tokenizer::validateC() const void Tokenizer::validateC() const
{ {
if (!isC()) if (isCPP())
return; return;
for (const Token *tok = tokens(); tok; tok = tok->next()) { for (const Token *tok = tokens(); tok; tok = tok->next()) {
// That might trigger false positives, but it's much faster to have this truncated pattern // 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 <..."); syntaxErrorC(tok, "C++ cast <...");
// Template function.. // Template function..
if (Token::Match(tok, "%name% < %name% > (")) { if (Token::Match(tok, "%name% < %name% > (")) {
@ -8175,19 +8173,20 @@ const Token * Tokenizer::findGarbageCode() const
return nullptr; 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) 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()) { for (const Token *tok = start; tok != end; tok = tok->next()) {
if (controlFlowKeywords.find(tok->str()) != controlFlowKeywords.end()) if (controlFlowKeywords.find(tok->str()) != controlFlowKeywords.end())
return true; return true;
@ -8647,17 +8646,15 @@ void Tokenizer::simplifyAttribute()
} }
} }
namespace { static const std::set<std::string> keywords = make_container< std::set<std::string> >()
const std::set<std::string> keywords = make_container< std::set<std::string> >() << "volatile"
<< "volatile" << "inline"
<< "inline" << "_inline"
<< "_inline" << "__inline"
<< "__inline" << "__forceinline"
<< "__forceinline" << "register"
<< "register" << "__restrict"
<< "__restrict" << "__restrict__" ;
<< "__restrict__" ;
}
// Remove "volatile", "inline", "register", "restrict", "override", "final", "static" and "constexpr" // Remove "volatile", "inline", "register", "restrict", "override", "final", "static" and "constexpr"
// "restrict" keyword // "restrict" keyword
// - New to 1999 ANSI/ISO C standard // - New to 1999 ANSI/ISO C standard
@ -9009,52 +9006,50 @@ void Tokenizer::simplifyBitfields()
} }
namespace { // Types and objects in std namespace that are neither functions nor templates
// Types and objects in std namespace that are neither functions nor templates static const std::set<std::string> stdTypes = make_container<std::set<std::string> >() <<
const std::set<std::string> stdTypes = make_container<std::set<std::string> >() << "string"<< "wstring"<< "u16string"<< "u32string" <<
"string"<< "wstring"<< "u16string"<< "u32string" << "iostream"<< "ostream"<< "ofstream"<< "ostringstream" <<
"iostream"<< "ostream"<< "ofstream"<< "ostringstream" << "istream"<< "ifstream"<< "istringstream"<< "fstream"<< "stringstream" <<
"istream"<< "ifstream"<< "istringstream"<< "fstream"<< "stringstream" << "wstringstream"<< "wistringstream"<< "wostringstream"<< "wstringbuf" <<
"wstringstream"<< "wistringstream"<< "wostringstream"<< "wstringbuf" << "stringbuf"<< "streambuf"<< "ios"<< "filebuf"<< "ios_base" <<
"stringbuf"<< "streambuf"<< "ios"<< "filebuf"<< "ios_base" << "exception"<< "bad_exception"<< "bad_alloc" <<
"exception"<< "bad_exception"<< "bad_alloc" << "logic_error"<< "domain_error"<< "invalid_argument_"<< "length_error" <<
"logic_error"<< "domain_error"<< "invalid_argument_"<< "length_error" << "out_of_range"<< "runtime_error"<< "range_error"<< "overflow_error"<< "underflow_error" <<
"out_of_range"<< "runtime_error"<< "range_error"<< "overflow_error"<< "underflow_error" << "locale" <<
"locale" << "cout"<< "cerr"<< "clog"<< "cin" <<
"cout"<< "cerr"<< "clog"<< "cin" << "wcerr"<< "wcin"<< "wclog"<< "wcout" <<
"wcerr"<< "wcin"<< "wclog"<< "wcout" << "endl"<< "ends"<< "flush" <<
"endl"<< "ends"<< "flush" << "boolalpha"<< "noboolalpha"<< "showbase"<< "noshowbase" <<
"boolalpha"<< "noboolalpha"<< "showbase"<< "noshowbase" << "showpoint"<< "noshowpoint"<< "showpos"<< "noshowpos" <<
"showpoint"<< "noshowpoint"<< "showpos"<< "noshowpos" << "skipws"<< "noskipws"<< "unitbuf"<< "nounitbuf"<< "uppercase"<< "nouppercase" <<
"skipws"<< "noskipws"<< "unitbuf"<< "nounitbuf"<< "uppercase"<< "nouppercase" << "dec"<< "hex"<< "oct" <<
"dec"<< "hex"<< "oct" << "fixed"<< "scientific" <<
"fixed"<< "scientific" << "internal"<< "left"<< "right" <<
"internal"<< "left"<< "right" << "fpos"<< "streamoff"<< "streampos"<< "streamsize";
"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" << "array"<< "basic_string"<< "bitset"<< "deque"<< "list"<< "map"<< "multimap" <<
"priority_queue"<< "queue"<< "set"<< "multiset"<< "stack"<< "vector"<< "pair" << "priority_queue"<< "queue"<< "set"<< "multiset"<< "stack"<< "vector"<< "pair" <<
"iterator"<< "iterator_traits" << "iterator"<< "iterator_traits" <<
"unordered_map"<< "unordered_multimap"<< "unordered_set"<< "unordered_multiset" << "unordered_map"<< "unordered_multimap"<< "unordered_set"<< "unordered_multiset" <<
"tuple"<< "function"; "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" << "getline" <<
"for_each"<< "find"<< "find_if"<< "find_end"<< "find_first_of" << "for_each"<< "find"<< "find_if"<< "find_end"<< "find_first_of" <<
"adjacent_find"<< "count"<< "count_if"<< "mismatch"<< "equal"<< "search"<< "search_n" << "adjacent_find"<< "count"<< "count_if"<< "mismatch"<< "equal"<< "search"<< "search_n" <<
"copy"<< "copy_backward"<< "swap"<< "swap_ranges"<< "iter_swap"<< "transform"<< "replace" << "copy"<< "copy_backward"<< "swap"<< "swap_ranges"<< "iter_swap"<< "transform"<< "replace" <<
"replace_if"<< "replace_copy"<< "replace_copy_if"<< "fill"<< "fill_n"<< "generate"<< "generate_n"<< "remove" << "replace_if"<< "replace_copy"<< "replace_copy_if"<< "fill"<< "fill_n"<< "generate"<< "generate_n"<< "remove" <<
"remove_if"<< "remove_copy"<< "remove_copy_if" << "remove_if"<< "remove_copy"<< "remove_copy_if" <<
"unique"<< "unique_copy"<< "reverse"<< "reverse_copy" << "unique"<< "unique_copy"<< "reverse"<< "reverse_copy" <<
"rotate"<< "rotate_copy"<< "random_shuffle"<< "partition"<< "stable_partition" << "rotate"<< "rotate_copy"<< "random_shuffle"<< "partition"<< "stable_partition" <<
"sort"<< "stable_sort"<< "partial_sort"<< "partial_sort_copy"<< "nth_element" << "sort"<< "stable_sort"<< "partial_sort"<< "partial_sort_copy"<< "nth_element" <<
"lower_bound"<< "upper_bound"<< "equal_range"<< "binary_search"<< "merge"<< "inplace_merge"<< "includes" << "lower_bound"<< "upper_bound"<< "equal_range"<< "binary_search"<< "merge"<< "inplace_merge"<< "includes" <<
"set_union"<< "set_intersection"<< "set_difference" << "set_union"<< "set_intersection"<< "set_difference" <<
"set_symmetric_difference"<< "push_heap"<< "pop_heap"<< "make_heap"<< "sort_heap" << "set_symmetric_difference"<< "push_heap"<< "pop_heap"<< "make_heap"<< "sort_heap" <<
"min"<< "max"<< "min_element"<< "max_element"<< "lexicographical_compare"<< "next_permutation"<< "prev_permutation" << "min"<< "max"<< "min_element"<< "max_element"<< "lexicographical_compare"<< "next_permutation"<< "prev_permutation" <<
"advance"<< "back_inserter"<< "distance"<< "front_inserter"<< "inserter" << "advance"<< "back_inserter"<< "distance"<< "front_inserter"<< "inserter" <<
"make_pair"<< "make_shared"<< "make_tuple"; "make_pair"<< "make_shared"<< "make_tuple";
}
// Add std:: in front of std classes, when using namespace std; was given // 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(";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(";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("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 void syntax_case_default() { // correct syntax