Removed rest of variableHidingTypedef and variableHidingEnum checking
This commit is contained in:
parent
42278dd133
commit
f8bf2b5776
|
@ -205,7 +205,7 @@ Token *Tokenizer::copyTokens(Token *dest, const Token *first, const Token *last,
|
|||
//---------------------------------------------------------------------------
|
||||
|
||||
// check if this statement is a duplicate definition
|
||||
bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name, const Token *typeDef, const std::set<std::string>& structs) const
|
||||
bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name, const Token *typeDef) const
|
||||
{
|
||||
// check for an end of definition
|
||||
const Token * tok = *tokPtr;
|
||||
|
@ -295,7 +295,6 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name, const Token
|
|||
// declaration after forward declaration
|
||||
return true;
|
||||
} else if (tok->next()->str() == "{") {
|
||||
if (structs.find(name->strAt(-1)) == structs.end())
|
||||
return true;
|
||||
} else if (Token::Match(tok->next(), ")|*")) {
|
||||
return true;
|
||||
|
@ -323,9 +322,8 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name, const Token
|
|||
tok = tok->previous();
|
||||
}
|
||||
|
||||
if ((*tokPtr)->strAt(1) != "(" || !Token::Match((*tokPtr)->linkAt(1), ") .|(|[")) {
|
||||
if ((*tokPtr)->strAt(1) != "(" || !Token::Match((*tokPtr)->linkAt(1), ") .|(|["))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -535,13 +533,6 @@ Token *Tokenizer::processFunc(Token *tok2, bool inOperator) const
|
|||
|
||||
void Tokenizer::simplifyTypedef()
|
||||
{
|
||||
// Collect all structs for later detection of undefined structs
|
||||
std::set<std::string> structs;
|
||||
for (const Token* tok = list.front(); tok; tok = tok->next()) {
|
||||
if (Token::Match(tok, "struct %type% {|:"))
|
||||
structs.insert(tok->strAt(1));
|
||||
}
|
||||
|
||||
std::vector<Space> spaceInfo;
|
||||
bool isNamespace = false;
|
||||
std::string className;
|
||||
|
@ -1163,7 +1154,7 @@ void Tokenizer::simplifyTypedef()
|
|||
}
|
||||
} else if (Token::Match(tok2->previous(), "case|;|{|} %type% :")) {
|
||||
tok2 = tok2->next();
|
||||
} else if (duplicateTypedef(&tok2, typeName, typeDef, structs)) {
|
||||
} else if (duplicateTypedef(&tok2, typeName, typeDef)) {
|
||||
// skip to end of scope if not already there
|
||||
if (tok2->str() != "}") {
|
||||
while (tok2->next()) {
|
||||
|
@ -7264,16 +7255,15 @@ bool Tokenizer::duplicateDefinition(Token ** tokPtr) const
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if (Token::Match(tok->previous(), "enum|,")) {
|
||||
if (Token::Match(tok->previous(), "enum|,"))
|
||||
return true;
|
||||
} else if (Token::Match(tok->previous(), "%type%")) {
|
||||
else if (Token::Match(tok->previous(), "%type%")) {
|
||||
// look backwards
|
||||
const Token *back = tok;
|
||||
while (back && back->isName())
|
||||
back = back->previous();
|
||||
if (!back || (Token::Match(back, "[(,;{}]") && !Token::Match(back->next(),"return|throw"))) {
|
||||
if (!back || (Token::Match(back, "[(,;{}]") && !Token::Match(back->next(),"return|throw")))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7330,8 +7320,8 @@ public:
|
|||
}
|
||||
|
||||
// Simplify calculations..
|
||||
while (start && start->previous() && TemplateSimplifier::simplifyNumericCalculations(start->previous()))
|
||||
{ }
|
||||
while (start && start->previous() && TemplateSimplifier::simplifyNumericCalculations(start->previous())) {
|
||||
}
|
||||
|
||||
if (Token::Match(start, "%num% [,}]")) {
|
||||
value = start;
|
||||
|
@ -7351,7 +7341,6 @@ void Tokenizer::simplifyEnum()
|
|||
int classLevel = 0;
|
||||
bool goback = false;
|
||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||
|
||||
if (goback) {
|
||||
//jump back once, see the comment at the end of the function
|
||||
goback = false;
|
||||
|
|
|
@ -704,7 +704,7 @@ private:
|
|||
void reportError(const Token* tok, const Severity::SeverityType severity, const std::string& id, const std::string& msg, bool inconclusive = false) const;
|
||||
void reportError(const std::list<const Token*>& callstack, Severity::SeverityType severity, const std::string& id, const std::string& msg, bool inconclusive = false) const;
|
||||
|
||||
bool duplicateTypedef(Token **tokPtr, const Token *name, const Token *typeDef, const std::set<std::string>& structs) const;
|
||||
bool duplicateTypedef(Token **tokPtr, const Token *name, const Token *typeDef) const;
|
||||
|
||||
void unsupportedTypedef(const Token *tok) const;
|
||||
|
||||
|
|
|
@ -168,8 +168,6 @@ private:
|
|||
TEST_CASE(enum5);
|
||||
TEST_CASE(enum6);
|
||||
TEST_CASE(enum7);
|
||||
TEST_CASE(enum8);
|
||||
TEST_CASE(enum9); // ticket 1404
|
||||
TEST_CASE(enum10); // ticket 1445
|
||||
TEST_CASE(enum11);
|
||||
TEST_CASE(enum12);
|
||||
|
@ -182,7 +180,6 @@ private:
|
|||
TEST_CASE(enum19); // ticket #2536
|
||||
TEST_CASE(enum20); // ticket #2600
|
||||
TEST_CASE(enum21); // ticket #2720
|
||||
TEST_CASE(enum22); // ticket #2745
|
||||
TEST_CASE(enum23); // ticket #2804
|
||||
TEST_CASE(enum24); // ticket #2828
|
||||
TEST_CASE(enum25); // ticket #2966
|
||||
|
@ -198,8 +195,6 @@ private:
|
|||
TEST_CASE(enum35); // ticket #3953 (avoid simplification of type)
|
||||
TEST_CASE(enum36); // ticket #4378
|
||||
TEST_CASE(enum37); // ticket #4280 (shadow variable)
|
||||
TEST_CASE(enum38); // ticket #4463 (when throwing enum id, don't warn about shadow variable)
|
||||
TEST_CASE(enum39); // ticket #5145 (fp variable hides enum)
|
||||
TEST_CASE(enum40);
|
||||
TEST_CASE(enum41); // ticket #5212 (valgrind errors during enum simplification)
|
||||
TEST_CASE(enum42); // ticket #5182 (template function call in enum value)
|
||||
|
@ -2995,59 +2990,6 @@ private:
|
|||
return tokenizer.tokens()->stringifyList(0, true);
|
||||
}
|
||||
|
||||
void enum8() {
|
||||
// ticket 1388
|
||||
checkSimplifyEnum("enum Direction {N=100,E,S,W,ALL};\n"
|
||||
"template<class T,int S> class EF_Vector{\n"
|
||||
" T v_v[S];\n"
|
||||
"\n"
|
||||
"public:\n"
|
||||
" EF_Vector();\n"
|
||||
" explicit EF_Vector(const T &);\n"
|
||||
" explicit EF_Vector(const T arr[S]);\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"template<class T,int S>\n"
|
||||
"EF_Vector<T,S>::EF_Vector()\n"
|
||||
"{\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"template<class T,int S>\n"
|
||||
"EF_Vector<T,S>::EF_Vector(const T &t)\n"
|
||||
"{\n"
|
||||
" for(int i=0;i<S;i++)\n"
|
||||
" v_v[i]=t;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"template<class T,int S>\n"
|
||||
"EF_Vector<T,S>::EF_Vector(const T arr[S])\n"
|
||||
"{\n"
|
||||
" for(int i=0;i<S;i++)\n"
|
||||
" v_v[i]=arr[i];\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"void initialize()\n"
|
||||
"{\n"
|
||||
" EF_Vector<float,6> d;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void enum9() {
|
||||
// ticket 1404
|
||||
checkSimplifyEnum("class XX {\n"
|
||||
"public:\n"
|
||||
"static void Set(const int &p){m_p=p;}\n"
|
||||
"static int m_p;\n"
|
||||
"};\n"
|
||||
"int XX::m_p=0;\n"
|
||||
"int main() {\n"
|
||||
" enum { XX };\n"
|
||||
" XX::Set(std::numeric_limits<X>::digits());\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void enum10() {
|
||||
// ticket 1445
|
||||
const char code[] = "enum {\n"
|
||||
|
@ -3204,42 +3146,6 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void enum22() { // ticket #2745
|
||||
const char code[] = "enum en { x = 0 };\n"
|
||||
"void f() {\n"
|
||||
" int x = 0;\n"
|
||||
" g(x);\n"
|
||||
"}\n"
|
||||
"void f2(int &x) {\n"
|
||||
" x+=1;\n"
|
||||
"}\n";
|
||||
checkSimplifyEnum(code);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// avoid false positive: in other scope
|
||||
const char code2[] = "class C1 { enum en { x = 0 }; };\n"
|
||||
"class C2 { bool x; };\n";
|
||||
checkSimplifyEnum(code2);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// avoid false positive: inner if-scope
|
||||
const char code3[] = "enum en { x = 0 };\n"
|
||||
"void f() { if (aa) ; else if (bb==x) df; }\n";
|
||||
checkSimplifyEnum(code3);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// avoid false positive: Initializer list
|
||||
const char code4[] = "struct S {\n"
|
||||
" enum { E = 1 };\n"
|
||||
" explicit S(float f)\n"
|
||||
" : f_(f * E)\n"
|
||||
" {}\n"
|
||||
" float f_;\n"
|
||||
"};";
|
||||
checkSimplifyEnum(code4);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void enum23() { // ticket #2804
|
||||
const char code[] = "enum Enumerator : std::uint8_t { ITEM1, ITEM2, ITEM3 };\n"
|
||||
"Enumerator e = ITEM3;\n";
|
||||
|
@ -3350,22 +3256,6 @@ private:
|
|||
|
||||
const char code4[] = "enum { a, b }; void f() { int &a=x; }";
|
||||
ASSERT_EQUALS("void f ( ) { int & a = x ; }", checkSimplifyEnum(code4));
|
||||
|
||||
// #4857 - not shadow variable
|
||||
checkSimplifyEnum("enum { a,b }; void f() { if (x) { } else if ( x & a ) {} }");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void enum38() { // #4463
|
||||
const char code[] = "enum { a,b }; void f() { throw a; }";
|
||||
checkSimplifyEnum(code);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void enum39() { // #5145 - fp variable hides enum
|
||||
const char code[] = "enum { A }; void f() { int a = 1 * A; }";
|
||||
checkSimplifyEnum(code);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void enum40() {
|
||||
|
|
|
@ -77,7 +77,6 @@ private:
|
|||
TEST_CASE(simplifyTypedef38);
|
||||
TEST_CASE(simplifyTypedef39);
|
||||
TEST_CASE(simplifyTypedef40);
|
||||
TEST_CASE(simplifyTypedef41); // ticket #1488
|
||||
TEST_CASE(simplifyTypedef43); // ticket #1588
|
||||
TEST_CASE(simplifyTypedef44);
|
||||
TEST_CASE(simplifyTypedef45); // ticket #1613
|
||||
|
@ -88,7 +87,6 @@ private:
|
|||
TEST_CASE(simplifyTypedef50);
|
||||
TEST_CASE(simplifyTypedef51);
|
||||
TEST_CASE(simplifyTypedef52); // ticket #1782
|
||||
TEST_CASE(simplifyTypedef53); // ticket #1801
|
||||
TEST_CASE(simplifyTypedef54); // ticket #1814
|
||||
TEST_CASE(simplifyTypedef55);
|
||||
TEST_CASE(simplifyTypedef56); // ticket #1829
|
||||
|
@ -1097,30 +1095,16 @@ private:
|
|||
}
|
||||
|
||||
void simplifyTypedef37() {
|
||||
{
|
||||
// ticket #1449
|
||||
const char code[] = "template <class T> class V {};\n"
|
||||
"typedef V<int> A;\n"
|
||||
"typedef int B;\n"
|
||||
"typedef V<int> A;\n"
|
||||
"typedef int B;";
|
||||
|
||||
checkSimplifyTypedef(code);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
{
|
||||
const char code[] = "typedef int INT;\n"
|
||||
"void f()\n"
|
||||
"{\n"
|
||||
" INT i; { }\n"
|
||||
const char code[] = "typedef int INT;\n"
|
||||
"void f()\n"
|
||||
"{\n"
|
||||
" INT i; { }\n"
|
||||
"}";
|
||||
const char expected[] = "void f ( ) "
|
||||
"{ "
|
||||
"int i ; { } "
|
||||
"}";
|
||||
const char expected[] = "void f ( ) "
|
||||
"{ "
|
||||
"int i ; { } "
|
||||
"}";
|
||||
ASSERT_EQUALS(expected, tok(code, false));
|
||||
}
|
||||
ASSERT_EQUALS(expected, tok(code, false));
|
||||
}
|
||||
|
||||
void simplifyTypedef38() {
|
||||
|
@ -1146,60 +1130,6 @@ private:
|
|||
const char expected[] = "template < class A , class B > class C { } ;";
|
||||
ASSERT_EQUALS(expected, tok(code, false));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkSimplifyTypedef("typedef tuple<double&, const double&, const double, double*, const double*> t2;\n"
|
||||
"void ordering_test()\n"
|
||||
"{\n"
|
||||
" tuple<short, float> t2(5, 3.3f);\n"
|
||||
" BOOST_CHECK(t3 > t2);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkSimplifyTypedef("class MyOverflowingUnsigned\n"
|
||||
"{\n"
|
||||
"public:\n"
|
||||
" typedef unsigned self_type::* bool_type;\n"
|
||||
" operator bool_type() const { return this->v_ ? &self_type::v_ : 0; }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkSimplifyTypedef("typedef int (*fptr_type)(int, int);\n"
|
||||
"struct which_one {\n"
|
||||
" typedef fptr_type (*result_type)(bool x);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkSimplifyTypedef("class my_configuration\n"
|
||||
"{\n"
|
||||
"public:\n"
|
||||
" template < typename T >\n"
|
||||
" class hook\n"
|
||||
" {\n"
|
||||
" public:\n"
|
||||
" typedef ::boost::rational<T> rational_type;\n"
|
||||
" public:\n"
|
||||
" rational_type ( &r_ )[ 9 ];\n"
|
||||
" };\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkSimplifyTypedef("class A\n"
|
||||
"{\n"
|
||||
" typedef B b;\n"
|
||||
" friend b;\n"
|
||||
"};");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void simplifyTypedef41() {
|
||||
// ticket #1488
|
||||
checkSimplifyTypedef("class Y;\n"
|
||||
"class X\n"
|
||||
"{\n"
|
||||
" typedef Y type;\n"
|
||||
" friend class type;\n"
|
||||
"};");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void simplifyTypedef43() {
|
||||
|
@ -1452,31 +1382,6 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
void simplifyTypedef53() { // ticket #1801
|
||||
{
|
||||
const char code[] = "typedef int ( * int ( * ) ( ) ) ( ) ;";
|
||||
|
||||
// this is invalid C so just make sure it doesn't crash
|
||||
checkSimplifyTypedef(code);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (debug) Failed to parse 'typedef int ( * int ( * ) ( ) ) ( ) ;'. The checking continues anyway.\n", errout.str());
|
||||
}
|
||||
|
||||
{
|
||||
const char code[] = "typedef int (*PPDMarkOption)(ppd_file_t *ppd, const char *keyword, const char *option);\n"
|
||||
"typedef int (*PPDMarkOption)(ppd_file_t *ppd, const char *keyword, const char *option);";
|
||||
|
||||
checkSimplifyTypedef(code);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
{
|
||||
const char code[] = "typedef int * A;\n"
|
||||
"typedef int * A;";
|
||||
checkSimplifyTypedef(code);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
}
|
||||
|
||||
void simplifyTypedef54() { // ticket #1814
|
||||
const char code[] = "void foo()\n"
|
||||
"{\n"
|
||||
|
@ -2927,7 +2832,7 @@ private:
|
|||
void simplifyTypedefFunction8() {
|
||||
// #2376 - internal error
|
||||
const char code[] = "typedef int f_expand(const nrv_byte *);\n"
|
||||
"void f(f_expand *(*get_fexp(int))){}";
|
||||
"void f(f_expand *(*get_fexp(int))){}";
|
||||
checkSimplifyTypedef(code);
|
||||
TODO_ASSERT_EQUALS("", "[test.cpp:2]: (debug) Function::addArguments found argument 'int' with varid 0.\n", errout.str()); // make sure that there is no internal error
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue