Fixed #4042 (False Positive : Same expression on both sides of '&')
This commit is contained in:
parent
8f332af849
commit
cfd697d6d4
|
@ -1703,9 +1703,6 @@ bool Tokenizer::tokenize(std::istream &code,
|
|||
// remove unnecessary member qualification..
|
||||
removeUnnecessaryQualification();
|
||||
|
||||
// Add std:: in front of std classes, when using namespace std; was given
|
||||
simplifyNamespaceStd();
|
||||
|
||||
// remove Microsoft MFC..
|
||||
simplifyMicrosoftMFC();
|
||||
|
||||
|
@ -1990,6 +1987,9 @@ bool Tokenizer::tokenize(std::istream &code,
|
|||
setVarId();
|
||||
}
|
||||
|
||||
// Add std:: in front of std classes, when using namespace std; was given
|
||||
simplifyNamespaceStd();
|
||||
|
||||
createLinks2();
|
||||
|
||||
// Change initialisation of variable to assignment
|
||||
|
@ -8991,7 +8991,7 @@ void Tokenizer::simplifyNamespaceStd()
|
|||
"exception", "bad_exception",
|
||||
"logic_error", "domain_error", "invalid_argument_", "length_error", "out_of_rage", "runtime_error", "range_error", "overflow_error", "underflow_error",
|
||||
"locale",
|
||||
"cout", "cerr", "clog", "cin",
|
||||
"cout", "cerr", "clog", "cin", "endl",
|
||||
"fpos", "streamoff", "streampos", "streamsize"
|
||||
};
|
||||
static const std::set<std::string> stdTypes(stdTypes_, stdTypes_+sizeof(stdTypes_)/sizeof(*stdTypes_));
|
||||
|
@ -9019,7 +9019,7 @@ void Tokenizer::simplifyNamespaceStd()
|
|||
insert = true;
|
||||
else if (Token::Match(tok, "%var% <") && !Token::Match(tok->previous(), ".|::") && stdTemplates.find(tok->str()) != stdTemplates.end())
|
||||
insert = true;
|
||||
else if (tok->isName() && !Token::Match(tok->next(), "(|<") && !Token::Match(tok->previous(), ".|::") && stdTypes.find(tok->str()) != stdTypes.end())
|
||||
else if (tok->isName() && !tok->varId() && !Token::Match(tok->next(), "(|<") && !Token::Match(tok->previous(), ".|::") && stdTypes.find(tok->str()) != stdTypes.end())
|
||||
insert = true;
|
||||
|
||||
if (insert) {
|
||||
|
|
|
@ -7123,6 +7123,29 @@ private:
|
|||
static const char code10[] = "std::tr1::function <void(int)> f;";
|
||||
ASSERT_EQUALS("std :: tr1 :: function < void ( int ) > f ;", tokenizeAndStringify(code10, false, true, Settings::Unspecified, "test.cpp", false));
|
||||
ASSERT_EQUALS("std :: function < void ( int ) > f ;", tokenizeAndStringify(code10, false, true, Settings::Unspecified, "test.cpp", true));
|
||||
|
||||
// #4042 (Do not add 'std ::' to variables)
|
||||
static const char code11[] = "using namespace std;\n"
|
||||
"const char * string = \"Hi\";";
|
||||
ASSERT_EQUALS("const char * string ; string = \"Hi\" ;", tokenizeAndStringify(code11, false));
|
||||
|
||||
static const char code12[] = "using namespace std;\n"
|
||||
"string f(const char * string) {\n"
|
||||
" cout << string << endl;\n"
|
||||
" return string;\n"
|
||||
"}";
|
||||
static const char expected12[] = "std :: string f ( const char * string ) {\n"
|
||||
"std :: cout << string << std :: endl ;\n"
|
||||
"return string ;\n"
|
||||
"}";
|
||||
ASSERT_EQUALS(expected12, tokenizeAndStringify(code12, false));
|
||||
|
||||
static const char code13[] = "using namespace std;\n"
|
||||
"try { }\n"
|
||||
"catch(std::exception &exception) { }";
|
||||
static const char expected13[] = "try { }\n"
|
||||
"catch ( std :: exception & exception ) { }";
|
||||
ASSERT_EQUALS(expected13, tokenizeAndStringify(code13, false));
|
||||
}
|
||||
|
||||
void microsoftMFC() {
|
||||
|
|
Loading…
Reference in New Issue