ASSERT() on calls to Tokenizer::tokenize() in test code (#3501)
This commit is contained in:
parent
853a1f6d54
commit
ca311ebcdf
|
@ -42,7 +42,8 @@ private:
|
||||||
TEST_CASE(assignment);
|
TEST_CASE(assignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const char code[]) {
|
#define check(code) check_(code, __FILE__, __LINE__)
|
||||||
|
void check_(const char code[], const char* file, int line) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -50,7 +51,7 @@ private:
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
LOAD_LIB_2(settings.library, "std.cfg");
|
LOAD_LIB_2(settings.library, "std.cfg");
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check char variable usage..
|
// Check char variable usage..
|
||||||
Check64BitPortability check64BitPortability(&tokenizer, &settings, this);
|
Check64BitPortability check64BitPortability(&tokenizer, &settings, this);
|
||||||
|
|
|
@ -30,14 +30,15 @@ public:
|
||||||
private:
|
private:
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
|
||||||
void check(const char code[], const char *filename = "test.cpp") {
|
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
void check_(const char* file, int line, const char code[], const char *filename = "test.cpp") {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, filename);
|
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);
|
||||||
|
|
||||||
// Check..
|
// Check..
|
||||||
CheckAssert checkAssert;
|
CheckAssert checkAssert;
|
||||||
|
|
|
@ -33,29 +33,30 @@ public:
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void run() OVERRIDE {
|
void run() OVERRIDE {
|
||||||
TEST_CASE(findLambdaEndToken);
|
TEST_CASE(findLambdaEndTokenTest);
|
||||||
TEST_CASE(findLambdaStartToken);
|
TEST_CASE(findLambdaStartTokenTest);
|
||||||
TEST_CASE(isNullOperand);
|
TEST_CASE(isNullOperandTest);
|
||||||
TEST_CASE(isReturnScope);
|
TEST_CASE(isReturnScopeTest);
|
||||||
TEST_CASE(isSameExpression);
|
TEST_CASE(isSameExpressionTest);
|
||||||
TEST_CASE(isVariableChanged);
|
TEST_CASE(isVariableChangedTest);
|
||||||
TEST_CASE(isVariableChangedByFunctionCall);
|
TEST_CASE(isVariableChangedByFunctionCallTest);
|
||||||
TEST_CASE(nextAfterAstRightmostLeaf);
|
TEST_CASE(nextAfterAstRightmostLeafTest);
|
||||||
TEST_CASE(isUsedAsBool);
|
TEST_CASE(isUsedAsBool);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool findLambdaEndToken(const char code[]) {
|
#define findLambdaEndToken(code) findLambdaEndToken_(code, __FILE__, __LINE__)
|
||||||
|
bool findLambdaEndToken_(const char code[], const char* file, int line) {
|
||||||
Settings settings;
|
Settings settings;
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
const Token * const tokEnd = ::findLambdaEndToken(tokenizer.tokens());
|
const Token * const tokEnd = (::findLambdaEndToken)(tokenizer.tokens());
|
||||||
return tokEnd && tokEnd->next() == nullptr;
|
return tokEnd && tokEnd->next() == nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void findLambdaEndToken() {
|
void findLambdaEndTokenTest() {
|
||||||
const Token* nullTok = nullptr;
|
const Token* nullTok = nullptr;
|
||||||
ASSERT(nullptr == ::findLambdaEndToken(nullTok));
|
ASSERT(nullptr == (::findLambdaEndToken)(nullTok));
|
||||||
ASSERT_EQUALS(false, findLambdaEndToken("void f() { }"));
|
ASSERT_EQUALS(false, findLambdaEndToken("void f() { }"));
|
||||||
ASSERT_EQUALS(true, findLambdaEndToken("[]{ }"));
|
ASSERT_EQUALS(true, findLambdaEndToken("[]{ }"));
|
||||||
ASSERT_EQUALS(true, findLambdaEndToken("[]{ return 0; }"));
|
ASSERT_EQUALS(true, findLambdaEndToken("[]{ return 0; }"));
|
||||||
|
@ -77,17 +78,18 @@ private:
|
||||||
ASSERT_EQUALS(true, findLambdaEndToken("[](void) constexpr -> const * const* int { return x; }"));
|
ASSERT_EQUALS(true, findLambdaEndToken("[](void) constexpr -> const * const* int { return x; }"));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool findLambdaStartToken(const char code[]) {
|
#define findLambdaStartToken(code) findLambdaStartToken_(code, __FILE__, __LINE__)
|
||||||
|
bool findLambdaStartToken_(const char code[], const char* file, int line) {
|
||||||
Settings settings;
|
Settings settings;
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
const Token * const tokStart = ::findLambdaStartToken(tokenizer.list.back());
|
const Token * const tokStart = (::findLambdaStartToken)(tokenizer.list.back());
|
||||||
return tokStart && tokStart == tokenizer.list.front();
|
return tokStart && tokStart == tokenizer.list.front();
|
||||||
}
|
}
|
||||||
|
|
||||||
void findLambdaStartToken() {
|
void findLambdaStartTokenTest() {
|
||||||
ASSERT(nullptr == ::findLambdaStartToken(nullptr));
|
ASSERT(nullptr == (::findLambdaStartToken)(nullptr));
|
||||||
ASSERT_EQUALS(false, findLambdaStartToken("void f() { }"));
|
ASSERT_EQUALS(false, findLambdaStartToken("void f() { }"));
|
||||||
ASSERT_EQUALS(true, findLambdaStartToken("[]{ }"));
|
ASSERT_EQUALS(true, findLambdaStartToken("[]{ }"));
|
||||||
ASSERT_EQUALS(true, findLambdaStartToken("[]{ return 0; }"));
|
ASSERT_EQUALS(true, findLambdaStartToken("[]{ return 0; }"));
|
||||||
|
@ -109,15 +111,16 @@ private:
|
||||||
ASSERT_EQUALS(true, findLambdaStartToken("[](void) constexpr -> const * const* int { return x; }"));
|
ASSERT_EQUALS(true, findLambdaStartToken("[](void) constexpr -> const * const* int { return x; }"));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isNullOperand(const char code[]) {
|
#define isNullOperand(code) isNullOperand_(code, __FILE__, __LINE__)
|
||||||
|
bool isNullOperand_(const char code[], const char* file, int line) {
|
||||||
Settings settings;
|
Settings settings;
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
return ::isNullOperand(tokenizer.tokens());
|
return (::isNullOperand)(tokenizer.tokens());
|
||||||
}
|
}
|
||||||
|
|
||||||
void isNullOperand() {
|
void isNullOperandTest() {
|
||||||
ASSERT_EQUALS(true, isNullOperand("(void*)0;"));
|
ASSERT_EQUALS(true, isNullOperand("(void*)0;"));
|
||||||
ASSERT_EQUALS(true, isNullOperand("(void*)0U;"));
|
ASSERT_EQUALS(true, isNullOperand("(void*)0U;"));
|
||||||
ASSERT_EQUALS(true, isNullOperand("(void*)0x0LL;"));
|
ASSERT_EQUALS(true, isNullOperand("(void*)0x0LL;"));
|
||||||
|
@ -130,18 +133,19 @@ private:
|
||||||
ASSERT_EQUALS(false, isNullOperand("(void*)1;"));
|
ASSERT_EQUALS(false, isNullOperand("(void*)1;"));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isReturnScope(const char code[], int offset) {
|
#define isReturnScope(code, offset) isReturnScope_(code, offset, __FILE__, __LINE__)
|
||||||
|
bool isReturnScope_(const char code[], int offset, const char* file, int line) {
|
||||||
Settings settings;
|
Settings settings;
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
const Token * const tok = (offset < 0)
|
const Token * const tok = (offset < 0)
|
||||||
? tokenizer.list.back()->tokAt(1+offset)
|
? tokenizer.list.back()->tokAt(1+offset)
|
||||||
: tokenizer.tokens()->tokAt(offset);
|
: tokenizer.tokens()->tokAt(offset);
|
||||||
return ::isReturnScope(tok);
|
return (::isReturnScope)(tok);
|
||||||
}
|
}
|
||||||
|
|
||||||
void isReturnScope() {
|
void isReturnScopeTest() {
|
||||||
ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { return; } }", -2));
|
ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { return; } }", -2));
|
||||||
ASSERT_EQUALS(true, isReturnScope("int f() { if (a) { return {}; } }", -2)); // #8891
|
ASSERT_EQUALS(true, isReturnScope("int f() { if (a) { return {}; } }", -2)); // #8891
|
||||||
ASSERT_EQUALS(true, isReturnScope("std::string f() { if (a) { return std::string{}; } }", -2)); // #8891
|
ASSERT_EQUALS(true, isReturnScope("std::string f() { if (a) { return std::string{}; } }", -2)); // #8891
|
||||||
|
@ -160,19 +164,20 @@ private:
|
||||||
ASSERT_EQUALS(true, isReturnScope("void positiveTokenOffset() { return; }", 7));
|
ASSERT_EQUALS(true, isReturnScope("void positiveTokenOffset() { return; }", 7));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isSameExpression(const char code[], const char tokStr1[], const char tokStr2[]) {
|
#define isSameExpression(code, tokStr1, tokStr2) isSameExpression_(code, tokStr1, tokStr2, __FILE__, __LINE__)
|
||||||
|
bool isSameExpression_(const char code[], const char tokStr1[], const char tokStr2[], const char* file, int line) {
|
||||||
Settings settings;
|
Settings settings;
|
||||||
Library library;
|
Library library;
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
tokenizer.simplifyTokens1("");
|
tokenizer.simplifyTokens1("");
|
||||||
const Token * const tok1 = Token::findsimplematch(tokenizer.tokens(), tokStr1, strlen(tokStr1));
|
const Token * const tok1 = Token::findsimplematch(tokenizer.tokens(), tokStr1, strlen(tokStr1));
|
||||||
const Token * const tok2 = Token::findsimplematch(tok1->next(), tokStr2, strlen(tokStr2));
|
const Token * const tok2 = Token::findsimplematch(tok1->next(), tokStr2, strlen(tokStr2));
|
||||||
return ::isSameExpression(false, false, tok1, tok2, library, false, true, nullptr);
|
return (::isSameExpression)(false, false, tok1, tok2, library, false, true, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void isSameExpression() {
|
void isSameExpressionTest() {
|
||||||
ASSERT_EQUALS(true, isSameExpression("x = 1 + 1;", "1", "1"));
|
ASSERT_EQUALS(true, isSameExpression("x = 1 + 1;", "1", "1"));
|
||||||
ASSERT_EQUALS(false, isSameExpression("x = 1 + 1u;", "1", "1u"));
|
ASSERT_EQUALS(false, isSameExpression("x = 1 + 1u;", "1", "1u"));
|
||||||
ASSERT_EQUALS(true, isSameExpression("x = 1.0 + 1.0;", "1.0", "1.0"));
|
ASSERT_EQUALS(true, isSameExpression("x = 1.0 + 1.0;", "1.0", "1.0"));
|
||||||
|
@ -199,17 +204,18 @@ private:
|
||||||
ASSERT_EQUALS(true, true);
|
ASSERT_EQUALS(true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isVariableChanged(const char code[], const char startPattern[], const char endPattern[]) {
|
#define isVariableChanged(code, startPattern, endPattern) isVariableChanged_(code, startPattern, endPattern, __FILE__, __LINE__)
|
||||||
|
bool isVariableChanged_(const char code[], const char startPattern[], const char endPattern[], const char* file, int line) {
|
||||||
Settings settings;
|
Settings settings;
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
const Token * const tok1 = Token::findsimplematch(tokenizer.tokens(), startPattern, strlen(startPattern));
|
const Token * const tok1 = Token::findsimplematch(tokenizer.tokens(), startPattern, strlen(startPattern));
|
||||||
const Token * const tok2 = Token::findsimplematch(tokenizer.tokens(), endPattern, strlen(endPattern));
|
const Token * const tok2 = Token::findsimplematch(tokenizer.tokens(), endPattern, strlen(endPattern));
|
||||||
return ::isVariableChanged(tok1,tok2,1,false,&settings,true);
|
return (::isVariableChanged)(tok1, tok2, 1, false, &settings, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void isVariableChanged() {
|
void isVariableChangedTest() {
|
||||||
// #8211 - no lhs for >> , do not crash
|
// #8211 - no lhs for >> , do not crash
|
||||||
isVariableChanged("void f() {\n"
|
isVariableChanged("void f() {\n"
|
||||||
" int b;\n"
|
" int b;\n"
|
||||||
|
@ -221,16 +227,17 @@ private:
|
||||||
"}\n", "= a", "}"));
|
"}\n", "= a", "}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isVariableChangedByFunctionCall(const char code[], const char pattern[], bool *inconclusive) {
|
#define isVariableChangedByFunctionCall(code, pattern, inconclusive) isVariableChangedByFunctionCall_(code, pattern, inconclusive, __FILE__, __LINE__)
|
||||||
|
bool isVariableChangedByFunctionCall_(const char code[], const char pattern[], bool *inconclusive, const char* file, int line) {
|
||||||
Settings settings;
|
Settings settings;
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
const Token * const argtok = Token::findmatch(tokenizer.tokens(), pattern);
|
const Token * const argtok = Token::findmatch(tokenizer.tokens(), pattern);
|
||||||
return ::isVariableChangedByFunctionCall(argtok, 0, &settings, inconclusive);
|
return (::isVariableChangedByFunctionCall)(argtok, 0, &settings, inconclusive);
|
||||||
}
|
}
|
||||||
|
|
||||||
void isVariableChangedByFunctionCall() {
|
void isVariableChangedByFunctionCallTest() {
|
||||||
const char *code;
|
const char *code;
|
||||||
bool inconclusive;
|
bool inconclusive;
|
||||||
|
|
||||||
|
@ -249,16 +256,17 @@ private:
|
||||||
TODO_ASSERT_EQUALS(false, true, inconclusive);
|
TODO_ASSERT_EQUALS(false, true, inconclusive);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool nextAfterAstRightmostLeaf(const char code[], const char parentPattern[], const char rightPattern[]) {
|
#define nextAfterAstRightmostLeaf(code, parentPattern, rightPattern) nextAfterAstRightmostLeaf_(code, parentPattern, rightPattern, __FILE__, __LINE__)
|
||||||
|
bool nextAfterAstRightmostLeaf_(const char code[], const char parentPattern[], const char rightPattern[], const char* file, int line) {
|
||||||
Settings settings;
|
Settings settings;
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
const Token * tok = Token::findsimplematch(tokenizer.tokens(), parentPattern, strlen(parentPattern));
|
const Token * tok = Token::findsimplematch(tokenizer.tokens(), parentPattern, strlen(parentPattern));
|
||||||
return Token::simpleMatch(::nextAfterAstRightmostLeaf(tok), rightPattern, strlen(rightPattern));
|
return Token::simpleMatch((::nextAfterAstRightmostLeaf)(tok), rightPattern, strlen(rightPattern));
|
||||||
}
|
}
|
||||||
|
|
||||||
void nextAfterAstRightmostLeaf() {
|
void nextAfterAstRightmostLeafTest() {
|
||||||
ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("void f(int a, int b) { int x = a + b; }", "=", "; }"));
|
ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("void f(int a, int b) { int x = a + b; }", "=", "; }"));
|
||||||
ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("int * g(int); void f(int a, int b) { int x = g(a); }", "=", "; }"));
|
ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("int * g(int); void f(int a, int b) { int x = g(a); }", "=", "; }"));
|
||||||
ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("int * g(int); void f(int a, int b) { int x = g(a)[b]; }", "=", "; }"));
|
ASSERT_EQUALS(true, nextAfterAstRightmostLeaf("int * g(int); void f(int a, int b) { int x = g(a)[b]; }", "=", "; }"));
|
||||||
|
|
|
@ -30,7 +30,8 @@ public:
|
||||||
private:
|
private:
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
|
||||||
void check(const char code[], bool inconclusive = false, const char* filename = "test.cpp") {
|
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
void check_(const char* file, int line, const char code[], bool inconclusive = false, const char* filename = "test.cpp") {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -39,7 +40,7 @@ private:
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, filename);
|
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);
|
||||||
|
|
||||||
CheckAutoVariables checkAutoVariables;
|
CheckAutoVariables checkAutoVariables;
|
||||||
checkAutoVariables.runChecks(&tokenizer, &settings, this);
|
checkAutoVariables.runChecks(&tokenizer, &settings, this);
|
||||||
|
|
|
@ -75,7 +75,8 @@ private:
|
||||||
TEST_CASE(returnNonBoolClass);
|
TEST_CASE(returnNonBoolClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const char code[], bool experimental = false, const char filename[] = "test.cpp") {
|
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
void check_(const char* file, int line, const char code[], bool experimental = false, const char filename[] = "test.cpp") {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -84,7 +85,7 @@ private:
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, filename);
|
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);
|
||||||
|
|
||||||
// Check...
|
// Check...
|
||||||
CheckBool checkBool(&tokenizer, &settings, this);
|
CheckBool checkBool(&tokenizer, &settings, this);
|
||||||
|
|
|
@ -37,14 +37,15 @@ private:
|
||||||
TEST_CASE(BoostForeachContainerModification);
|
TEST_CASE(BoostForeachContainerModification);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const char code[]) {
|
#define check(code) check_(code, __FILE__, __LINE__)
|
||||||
|
void check_(const char code[], const char* file, int line) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check..
|
// Check..
|
||||||
CheckBoost checkBoost;
|
CheckBoost checkBoost;
|
||||||
|
|
|
@ -39,7 +39,8 @@ public:
|
||||||
private:
|
private:
|
||||||
Settings settings0;
|
Settings settings0;
|
||||||
|
|
||||||
void check(const char code[], const char filename[] = "test.cpp") {
|
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
void check_(const char* file, int line, const char code[], const char filename[] = "test.cpp") {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -48,17 +49,17 @@ private:
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, filename);
|
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);
|
||||||
|
|
||||||
// Check for buffer overruns..
|
// Check for buffer overruns..
|
||||||
CheckBufferOverrun checkBufferOverrun;
|
CheckBufferOverrun checkBufferOverrun;
|
||||||
checkBufferOverrun.runChecks(&tokenizer, &settings0, this);
|
checkBufferOverrun.runChecks(&tokenizer, &settings0, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const char code[], const Settings &settings, const char filename[] = "test.cpp") {
|
void check_(const char* file, int line, const char code[], const Settings &settings, const char filename[] = "test.cpp") {
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, filename);
|
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);
|
||||||
|
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
@ -4539,22 +4540,23 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 'arr+20' is out of bounds.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 'arr+20' is out of bounds.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ctu(const char code[]) {
|
#define ctu(code) ctu_(code, __FILE__, __LINE__)
|
||||||
|
void ctu_(const char code[], const char* file, int line) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
CTU::FileInfo *ctu = CTU::getFileInfo(&tokenizer);
|
CTU::FileInfo *ctu = CTU::getFileInfo(&tokenizer);
|
||||||
|
|
||||||
// Check code..
|
// Check code..
|
||||||
std::list<Check::FileInfo*> fileInfo;
|
std::list<Check::FileInfo*> fileInfo;
|
||||||
CheckBufferOverrun check(&tokenizer, &settings0, this);
|
CheckBufferOverrun checkBO(&tokenizer, &settings0, this);
|
||||||
fileInfo.push_back(check.getFileInfo(&tokenizer, &settings0));
|
fileInfo.push_back(checkBO.getFileInfo(&tokenizer, &settings0));
|
||||||
check.analyseWholeProgram(ctu, fileInfo, settings0, *this);
|
checkBO.analyseWholeProgram(ctu, fileInfo, settings0, *this);
|
||||||
while (!fileInfo.empty()) {
|
while (!fileInfo.empty()) {
|
||||||
delete fileInfo.back();
|
delete fileInfo.back();
|
||||||
fileInfo.pop_back();
|
fileInfo.pop_back();
|
||||||
|
|
|
@ -41,14 +41,15 @@ private:
|
||||||
TEST_CASE(bitop);
|
TEST_CASE(bitop);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const char code[]) {
|
#define check(code) check_(code, __FILE__, __LINE__)
|
||||||
|
void check_(const char code[], const char* file, int line) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check char variable usage..
|
// Check char variable usage..
|
||||||
CheckOther checkOther(&tokenizer, &settings, this);
|
CheckOther checkOther(&tokenizer, &settings, this);
|
||||||
|
|
|
@ -219,16 +219,17 @@ private:
|
||||||
TEST_CASE(override1);
|
TEST_CASE(override1);
|
||||||
TEST_CASE(overrideCVRefQualifiers);
|
TEST_CASE(overrideCVRefQualifiers);
|
||||||
|
|
||||||
TEST_CASE(checkThisUseAfterFree);
|
TEST_CASE(thisUseAfterFree);
|
||||||
|
|
||||||
TEST_CASE(unsafeClassRefMember);
|
TEST_CASE(unsafeClassRefMember);
|
||||||
|
|
||||||
TEST_CASE(ctuOneDefinitionRule);
|
TEST_CASE(ctuOneDefinitionRule);
|
||||||
|
|
||||||
TEST_CASE(getFileInfo);
|
TEST_CASE(testGetFileInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkCopyCtorAndEqOperator(const char code[]) {
|
#define checkCopyCtorAndEqOperator(code) checkCopyCtorAndEqOperator_(code, __FILE__, __LINE__)
|
||||||
|
void checkCopyCtorAndEqOperator_(const char code[], const char* file, int line) {
|
||||||
// Clear the error log
|
// Clear the error log
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
@ -237,11 +238,11 @@ private:
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check..
|
// Check..
|
||||||
CheckClass checkClass(&tokenizer, &settings, this);
|
CheckClass checkClass(&tokenizer, &settings, this);
|
||||||
checkClass.checkCopyCtorAndEqOperator();
|
(checkClass.checkCopyCtorAndEqOperator)();
|
||||||
}
|
}
|
||||||
|
|
||||||
void copyCtorAndEqOperator() {
|
void copyCtorAndEqOperator() {
|
||||||
|
@ -333,18 +334,19 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkExplicitConstructors(const char code[]) {
|
#define checkExplicitConstructors(code) checkExplicitConstructors_(code, __FILE__, __LINE__)
|
||||||
|
void checkExplicitConstructors_(const char code[], const char* file, int line) {
|
||||||
// Clear the error log
|
// Clear the error log
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check..
|
// Check..
|
||||||
CheckClass checkClass(&tokenizer, &settings0, this);
|
CheckClass checkClass(&tokenizer, &settings0, this);
|
||||||
checkClass.checkExplicitConstructors();
|
(checkClass.checkExplicitConstructors)();
|
||||||
}
|
}
|
||||||
|
|
||||||
void explicitConstructors() {
|
void explicitConstructors() {
|
||||||
|
@ -442,18 +444,19 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:1]: (style) Struct 'A' has a constructor with 1 argument that is not explicit.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:1]: (style) Struct 'A' has a constructor with 1 argument that is not explicit.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkDuplInheritedMembers(const char code[]) {
|
#define checkDuplInheritedMembers(code) checkDuplInheritedMembers_(code, __FILE__, __LINE__)
|
||||||
|
void checkDuplInheritedMembers_(const char code[], const char* file, int line) {
|
||||||
// Clear the error log
|
// Clear the error log
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings1, this);
|
Tokenizer tokenizer(&settings1, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check..
|
// Check..
|
||||||
CheckClass checkClass(&tokenizer, &settings1, this);
|
CheckClass checkClass(&tokenizer, &settings1, this);
|
||||||
checkClass.checkDuplInheritedMembers();
|
(checkClass.checkDuplInheritedMembers)();
|
||||||
}
|
}
|
||||||
|
|
||||||
void duplInheritedMembers() {
|
void duplInheritedMembers() {
|
||||||
|
@ -596,14 +599,15 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkCopyConstructor(const char code[]) {
|
#define checkCopyConstructor(code) checkCopyConstructor_(code, __FILE__, __LINE__)
|
||||||
|
void checkCopyConstructor_(const char code[], const char* file, int line) {
|
||||||
// Clear the error log
|
// Clear the error log
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check..
|
// Check..
|
||||||
CheckClass checkClass(&tokenizer, &settings0, this);
|
CheckClass checkClass(&tokenizer, &settings0, this);
|
||||||
|
@ -1027,14 +1031,15 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that operator Equal returns reference to this
|
// Check that operator Equal returns reference to this
|
||||||
void checkOpertorEqRetRefThis(const char code[]) {
|
#define checkOpertorEqRetRefThis(code) checkOpertorEqRetRefThis_(code, __FILE__, __LINE__)
|
||||||
|
void checkOpertorEqRetRefThis_(const char code[], const char* file, int line) {
|
||||||
// Clear the error log
|
// Clear the error log
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check..
|
// Check..
|
||||||
CheckClass checkClass(&tokenizer, &settings0, this);
|
CheckClass checkClass(&tokenizer, &settings0, this);
|
||||||
|
@ -1490,14 +1495,15 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that operator Equal checks for assignment to self
|
// Check that operator Equal checks for assignment to self
|
||||||
void checkOpertorEqToSelf(const char code[]) {
|
#define checkOpertorEqToSelf(code) checkOpertorEqToSelf_(code, __FILE__, __LINE__)
|
||||||
|
void checkOpertorEqToSelf_(const char code[], const char* file, int line) {
|
||||||
// Clear the error log
|
// Clear the error log
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings1, this);
|
Tokenizer tokenizer(&settings1, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check..
|
// Check..
|
||||||
CheckClass checkClass(&tokenizer, &settings1, this);
|
CheckClass checkClass(&tokenizer, &settings1, this);
|
||||||
|
@ -2448,7 +2454,8 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that base classes have virtual destructors
|
// Check that base classes have virtual destructors
|
||||||
void checkVirtualDestructor(const char code[], bool inconclusive = false) {
|
#define checkVirtualDestructor(...) checkVirtualDestructor_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
void checkVirtualDestructor_(const char* file, int line, const char code[], bool inconclusive = false) {
|
||||||
// Clear the error log
|
// Clear the error log
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -2458,7 +2465,7 @@ private:
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check..
|
// Check..
|
||||||
CheckClass checkClass(&tokenizer, &settings0, this);
|
CheckClass checkClass(&tokenizer, &settings0, this);
|
||||||
|
@ -2742,21 +2749,23 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkNoMemset(const char code[]) {
|
|
||||||
|
#define checkNoMemset(...) checkNoMemset_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
void checkNoMemset_(const char* file, int line, const char code[]) {
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.severity.enable(Severity::warning);
|
settings.severity.enable(Severity::warning);
|
||||||
settings.severity.enable(Severity::portability);
|
settings.severity.enable(Severity::portability);
|
||||||
checkNoMemset(code,settings);
|
checkNoMemset_(file, line, code, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkNoMemset(const char code[], const Settings &settings) {
|
void checkNoMemset_(const char* file, int line, const char code[], const Settings &settings) {
|
||||||
// Clear the error log
|
// Clear the error log
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check..
|
// Check..
|
||||||
CheckClass checkClass(&tokenizer, &settings, this);
|
CheckClass checkClass(&tokenizer, &settings, this);
|
||||||
|
@ -3338,15 +3347,15 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define checkThisSubtraction(code) checkThisSubtraction_(code, __FILE__, __LINE__)
|
||||||
void checkThisSubtraction(const char code[]) {
|
void checkThisSubtraction_(const char code[], const char* file, int line) {
|
||||||
// Clear the error log
|
// Clear the error log
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings1, this);
|
Tokenizer tokenizer(&settings1, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check..
|
// Check..
|
||||||
CheckClass checkClass(&tokenizer, &settings1, this);
|
CheckClass checkClass(&tokenizer, &settings1, this);
|
||||||
|
@ -3371,7 +3380,8 @@ private:
|
||||||
"[test.cpp:3]: (warning) Suspicious pointer subtraction. Did you intend to write '->'?\n", errout.str());
|
"[test.cpp:3]: (warning) Suspicious pointer subtraction. Did you intend to write '->'?\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkConst(const char code[], Settings *s = nullptr, bool inconclusive = true) {
|
#define checkConst(...) checkConst_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
void checkConst_(const char* file, int line, const char code[], Settings *s = nullptr, bool inconclusive = true) {
|
||||||
// Clear the error log
|
// Clear the error log
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -3383,10 +3393,10 @@ private:
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(s, this);
|
Tokenizer tokenizer(s, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
CheckClass checkClass(&tokenizer, s, this);
|
CheckClass checkClass(&tokenizer, s, this);
|
||||||
checkClass.checkConst();
|
(checkClass.checkConst)();
|
||||||
}
|
}
|
||||||
|
|
||||||
void const1() {
|
void const1() {
|
||||||
|
@ -6559,7 +6569,8 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkInitializerListOrder(const char code[]) {
|
#define checkInitializerListOrder(code) checkInitializerListOrder_(code, __FILE__, __LINE__)
|
||||||
|
void checkInitializerListOrder_(const char code[], const char* file, int line) {
|
||||||
// Clear the error log
|
// Clear the error log
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -6569,7 +6580,7 @@ private:
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
CheckClass checkClass(&tokenizer, &settings0, this);
|
CheckClass checkClass(&tokenizer, &settings0, this);
|
||||||
checkClass.initializerListOrder();
|
checkClass.initializerListOrder();
|
||||||
|
@ -6593,7 +6604,8 @@ private:
|
||||||
"[test.cpp:4] -> [test.cpp:2]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list.\n", errout.str());
|
"[test.cpp:4] -> [test.cpp:2]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkInitializationListUsage(const char code[]) {
|
#define checkInitializationListUsage(code) checkInitializationListUsage_(code, __FILE__, __LINE__)
|
||||||
|
void checkInitializationListUsage_(const char code[], const char* file, int line) {
|
||||||
// Clear the error log
|
// Clear the error log
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -6604,7 +6616,7 @@ private:
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
CheckClass checkClass(&tokenizer, &settings, this);
|
CheckClass checkClass(&tokenizer, &settings, this);
|
||||||
checkClass.initializationListUsage();
|
checkClass.initializationListUsage();
|
||||||
|
@ -6808,17 +6820,18 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void checkSelfInitialization(const char code[]) {
|
#define checkSelfInitialization(code) checkSelfInitialization_(code, __FILE__, __LINE__)
|
||||||
|
void checkSelfInitialization_(const char code[], const char* file, int line) {
|
||||||
// Clear the error log
|
// Clear the error log
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
CheckClass checkClass(&tokenizer, &settings0, this);
|
CheckClass checkClass(&tokenizer, &settings0, this);
|
||||||
checkClass.checkSelfInitialization();
|
(checkClass.checkSelfInitialization)();
|
||||||
}
|
}
|
||||||
|
|
||||||
void selfInitialization() {
|
void selfInitialization() {
|
||||||
|
@ -6901,7 +6914,9 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkVirtualFunctionCall(const char code[], Settings *s = nullptr, bool inconclusive = true) {
|
|
||||||
|
#define checkVirtualFunctionCall(...) checkVirtualFunctionCall_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
void checkVirtualFunctionCall_(const char* file, int line, const char code[], Settings *s = nullptr, bool inconclusive = true) {
|
||||||
// Clear the error log
|
// Clear the error log
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -6916,7 +6931,7 @@ private:
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(s, this);
|
Tokenizer tokenizer(s, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
CheckClass checkClass(&tokenizer, s, this);
|
CheckClass checkClass(&tokenizer, s, this);
|
||||||
checkClass.checkVirtualFunctionCallInConstructor();
|
checkClass.checkVirtualFunctionCallInConstructor();
|
||||||
|
@ -7175,7 +7190,9 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkOverride(const char code[]) {
|
|
||||||
|
#define checkOverride(code) checkOverride_(code, __FILE__, __LINE__)
|
||||||
|
void checkOverride_(const char code[], const char* file, int line) {
|
||||||
// Clear the error log
|
// Clear the error log
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
@ -7184,11 +7201,11 @@ private:
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check..
|
// Check..
|
||||||
CheckClass checkClass(&tokenizer, &settings, this);
|
CheckClass checkClass(&tokenizer, &settings, this);
|
||||||
checkClass.checkOverride();
|
(checkClass.checkOverride)();
|
||||||
}
|
}
|
||||||
|
|
||||||
void override1() {
|
void override1() {
|
||||||
|
@ -7257,7 +7274,9 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkUnsafeClassRefMember(const char code[]) {
|
|
||||||
|
#define checkUnsafeClassRefMember(code) checkUnsafeClassRefMember_(code, __FILE__, __LINE__)
|
||||||
|
void checkUnsafeClassRefMember_(const char code[], const char* file, int line) {
|
||||||
// Clear the error log
|
// Clear the error log
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
@ -7267,11 +7286,11 @@ private:
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check..
|
// Check..
|
||||||
CheckClass checkClass(&tokenizer, &settings, this);
|
CheckClass checkClass(&tokenizer, &settings, this);
|
||||||
checkClass.checkUnsafeClassRefMember();
|
(checkClass.checkUnsafeClassRefMember)();
|
||||||
}
|
}
|
||||||
|
|
||||||
void unsafeClassRefMember() {
|
void unsafeClassRefMember() {
|
||||||
|
@ -7279,21 +7298,23 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:1]: (warning) Unsafe class: The const reference member 'C::s' is initialized by a const reference constructor argument. You need to be careful about lifetime issues.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:1]: (warning) Unsafe class: The const reference member 'C::s' is initialized by a const reference constructor argument. You need to be careful about lifetime issues.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkThisUseAfterFree(const char code[]) {
|
|
||||||
|
#define checkThisUseAfterFree(code) checkThisUseAfterFree_(code, __FILE__, __LINE__)
|
||||||
|
void checkThisUseAfterFree_(const char code[], const char* file, int line) {
|
||||||
// Clear the error log
|
// Clear the error log
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings1, this);
|
Tokenizer tokenizer(&settings1, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check..
|
// Check..
|
||||||
CheckClass checkClass(&tokenizer, &settings1, this);
|
CheckClass checkClass(&tokenizer, &settings1, this);
|
||||||
checkClass.checkThisUseAfterFree();
|
(checkClass.checkThisUseAfterFree)();
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkThisUseAfterFree() {
|
void thisUseAfterFree() {
|
||||||
setMultiline();
|
setMultiline();
|
||||||
|
|
||||||
// Calling method..
|
// Calling method..
|
||||||
|
@ -7443,7 +7464,7 @@ private:
|
||||||
for (const std::string& c: code) {
|
for (const std::string& c: code) {
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(c);
|
std::istringstream istr(c);
|
||||||
tokenizer.tokenize(istr, (std::to_string(fileInfo.size()) + ".cpp").c_str());
|
ASSERT(tokenizer.tokenize(istr, (std::to_string(fileInfo.size()) + ".cpp").c_str()));
|
||||||
fileInfo.push_back(check.getFileInfo(&tokenizer, &settings));
|
fileInfo.push_back(check.getFileInfo(&tokenizer, &settings));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7474,24 +7495,26 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void getFileInfo(const char code[]) {
|
|
||||||
|
#define getFileInfo(code) getFileInfo_(code, __FILE__, __LINE__)
|
||||||
|
void getFileInfo_(const char code[], const char* file, int line) {
|
||||||
// Clear the error log
|
// Clear the error log
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings1, this);
|
Tokenizer tokenizer(&settings1, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check..
|
// Check..
|
||||||
CheckClass checkClass(&tokenizer, &settings1, this);
|
CheckClass checkClass(&tokenizer, &settings1, this);
|
||||||
|
|
||||||
Check::FileInfo * fileInfo = checkClass.getFileInfo(&tokenizer, &settings1);
|
Check::FileInfo * fileInfo = (checkClass.getFileInfo)(&tokenizer, &settings1);
|
||||||
|
|
||||||
delete fileInfo;
|
delete fileInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
void getFileInfo() {
|
void testGetFileInfo() {
|
||||||
getFileInfo("void foo() { union { struct { }; }; }"); // don't crash
|
getFileInfo("void foo() { union { struct { }; }; }"); // don't crash
|
||||||
getFileInfo("struct sometype { sometype(); }; sometype::sometype() = delete;"); // don't crash
|
getFileInfo("struct sometype { sometype(); }; sometype::sometype() = delete;"); // don't crash
|
||||||
}
|
}
|
||||||
|
|
|
@ -493,6 +493,7 @@ private:
|
||||||
ASSERT_EQUALS("",errout.str()); //correct for negative 'a'
|
ASSERT_EQUALS("",errout.str()); //correct for negative 'a'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define checkPureFunction(code) checkPureFunction_(code, __FILE__, __LINE__)
|
||||||
void multicompare() {
|
void multicompare() {
|
||||||
check("void foo(int x)\n"
|
check("void foo(int x)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -532,14 +533,14 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkPureFunction(const char code[]) {
|
void checkPureFunction_(const char code[], const char* file, int line) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings1, this);
|
Tokenizer tokenizer(&settings1, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
CheckCondition checkCondition;
|
CheckCondition checkCondition;
|
||||||
checkCondition.runChecks(&tokenizer, &settings1, this);
|
checkCondition.runChecks(&tokenizer, &settings1, this);
|
||||||
|
|
|
@ -30,7 +30,8 @@ public:
|
||||||
private:
|
private:
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
|
||||||
void check(const char code[], bool inconclusive = false) {
|
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
void check_(const char* file, int line, const char code[], bool inconclusive = false) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -39,21 +40,21 @@ private:
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check class constructors..
|
// Check class constructors..
|
||||||
CheckClass checkClass(&tokenizer, &settings, this);
|
CheckClass checkClass(&tokenizer, &settings, this);
|
||||||
checkClass.constructors();
|
checkClass.constructors();
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const char code[], const Settings &s) {
|
void check_(const char* file, int line, const char code[], const Settings &s) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&s, this);
|
Tokenizer tokenizer(&s, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check class constructors..
|
// Check class constructors..
|
||||||
CheckClass checkClass(&tokenizer, &s, this);
|
CheckClass checkClass(&tokenizer, &s, this);
|
||||||
|
|
|
@ -55,7 +55,8 @@ private:
|
||||||
TEST_CASE(rethrowNoCurrentException3);
|
TEST_CASE(rethrowNoCurrentException3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const char code[], bool inconclusive = false) {
|
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
void check_(const char* file, int line, const char code[], bool inconclusive = false) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -64,7 +65,7 @@ private:
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check char variable usage..
|
// Check char variable usage..
|
||||||
CheckExceptionSafety checkExceptionSafety(&tokenizer, &settings, this);
|
CheckExceptionSafety checkExceptionSafety(&tokenizer, &settings, this);
|
||||||
|
|
|
@ -175,12 +175,13 @@ private:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string expr(const char code[], const std::string &binop) {
|
#define expr(code, binop) expr_(code, binop, __FILE__, __LINE__)
|
||||||
|
std::string expr_(const char code[], const std::string &binop, const char* file, int line) {
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.platform(cppcheck::Platform::Unix64);
|
settings.platform(cppcheck::Platform::Unix64);
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
std::string ret;
|
std::string ret;
|
||||||
ExprEngine::Callback f = [&](const Token *tok, const ExprEngine::Value &value, ExprEngine::DataBase *dataBase) {
|
ExprEngine::Callback f = [&](const Token *tok, const ExprEngine::Value &value, ExprEngine::DataBase *dataBase) {
|
||||||
if (tok->str() != binop)
|
if (tok->str() != binop)
|
||||||
|
@ -197,7 +198,8 @@ private:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string functionCallContractExpr(const char code[], const Settings &s) {
|
#define functionCallContractExpr(...) functionCallContractExpr_(code, s, __FILE__, __LINE__)
|
||||||
|
std::string functionCallContractExpr_(const char code[], const Settings &s, const char* file, int line) {
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.bugHunting = true;
|
settings.bugHunting = true;
|
||||||
settings.debugBugHunting = true;
|
settings.debugBugHunting = true;
|
||||||
|
@ -205,7 +207,7 @@ private:
|
||||||
settings.platform(cppcheck::Platform::Unix64);
|
settings.platform(cppcheck::Platform::Unix64);
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
std::vector<ExprEngine::Callback> callbacks;
|
std::vector<ExprEngine::Callback> callbacks;
|
||||||
std::ostringstream trace;
|
std::ostringstream trace;
|
||||||
ExprEngine::executeAllFunctions(this, &tokenizer, &settings, callbacks, trace);
|
ExprEngine::executeAllFunctions(this, &tokenizer, &settings, callbacks, trace);
|
||||||
|
@ -217,20 +219,21 @@ private:
|
||||||
return TestExprEngine::cleanupExpr(ret.substr(pos1, pos2+1-pos1));
|
return TestExprEngine::cleanupExpr(ret.substr(pos1, pos2+1-pos1));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getRange(const char code[], const std::string &str, int linenr = 0) {
|
#define getRange(...) getRange_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
std::string getRange_(const char* file, int line, const char code[], const std::string &str, int linenr = 0) {
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.platform(cppcheck::Platform::Unix64);
|
settings.platform(cppcheck::Platform::Unix64);
|
||||||
settings.library.smartPointers["std::shared_ptr"];
|
settings.library.smartPointers["std::shared_ptr"];
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
std::string ret;
|
std::string ret;
|
||||||
ExprEngine::Callback f = [&](const Token *tok, const ExprEngine::Value &value, ExprEngine::DataBase *dataBase) {
|
ExprEngine::Callback f = [&](const Token *tok, const ExprEngine::Value &value, ExprEngine::DataBase *dataBase) {
|
||||||
(void)dataBase;
|
(void)dataBase;
|
||||||
if ((linenr == 0 || linenr == tok->linenr()) && tok->expressionString() == str) {
|
if ((linenr == 0 || linenr == tok->linenr()) && tok->expressionString() == str) {
|
||||||
if (!ret.empty())
|
if (!ret.empty())
|
||||||
ret += ",";
|
ret += ",";
|
||||||
ret += value.getRange();
|
ret += (value.getRange)();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
std::vector<ExprEngine::Callback> callbacks;
|
std::vector<ExprEngine::Callback> callbacks;
|
||||||
|
@ -240,7 +243,8 @@ private:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string trackExecution(const char code[], Settings *settings = nullptr) {
|
#define trackExecution(...) trackExecution_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
std::string trackExecution_(const char* file, int line, const char code[], Settings *settings = nullptr) {
|
||||||
Settings s;
|
Settings s;
|
||||||
if (!settings)
|
if (!settings)
|
||||||
settings = &s;
|
settings = &s;
|
||||||
|
@ -250,7 +254,7 @@ private:
|
||||||
settings->library.smartPointers["std::shared_ptr"];
|
settings->library.smartPointers["std::shared_ptr"];
|
||||||
Tokenizer tokenizer(settings, this);
|
Tokenizer tokenizer(settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
std::vector<ExprEngine::Callback> callbacks;
|
std::vector<ExprEngine::Callback> callbacks;
|
||||||
std::ostringstream ret;
|
std::ostringstream ret;
|
||||||
ExprEngine::executeAllFunctions(this, &tokenizer, settings, callbacks, ret);
|
ExprEngine::executeAllFunctions(this, &tokenizer, settings, callbacks, ret);
|
||||||
|
|
|
@ -95,7 +95,8 @@ private:
|
||||||
TEST_CASE(returnLocalStdMove5);
|
TEST_CASE(returnLocalStdMove5);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const char code[], const char filename[]="test.cpp", const Settings* settings_=nullptr) {
|
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
void check_(const char* file, int line, const char code[], const char filename[] = "test.cpp", const Settings* settings_ = nullptr) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -105,7 +106,7 @@ private:
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(settings_, this);
|
Tokenizer tokenizer(settings_, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, filename);
|
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);
|
||||||
|
|
||||||
CheckFunctions checkFunctions(&tokenizer, settings_, this);
|
CheckFunctions checkFunctions(&tokenizer, settings_, this);
|
||||||
checkFunctions.runChecks(&tokenizer, settings_, this);
|
checkFunctions.runChecks(&tokenizer, settings_, this);
|
||||||
|
|
|
@ -260,6 +260,7 @@ private:
|
||||||
TEST_CASE(nonGarbageCode1); // #8346
|
TEST_CASE(nonGarbageCode1); // #8346
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define checkCodeInternal(code, filename) checkCodeInternal_(code, filename, __FILE__, __LINE__)
|
||||||
std::string checkCode(const std::string &code, bool cpp = true) {
|
std::string checkCode(const std::string &code, bool cpp = true) {
|
||||||
// double the tests - run each example as C as well as C++
|
// double the tests - run each example as C as well as C++
|
||||||
const char* const filename = cpp ? "test.cpp" : "test.c";
|
const char* const filename = cpp ? "test.cpp" : "test.c";
|
||||||
|
@ -273,13 +274,13 @@ private:
|
||||||
return checkCodeInternal(code, filename);
|
return checkCodeInternal(code, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string checkCodeInternal(const std::string &code, const char* filename) {
|
std::string checkCodeInternal_(const std::string &code, const char* filename, const char* file, int line) {
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// tokenize..
|
// tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, filename);
|
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);
|
||||||
|
|
||||||
// call all "runChecks" in all registered Check classes
|
// call all "runChecks" in all registered Check classes
|
||||||
for (std::list<Check *>::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) {
|
for (std::list<Check *>::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) {
|
||||||
|
@ -289,11 +290,12 @@ private:
|
||||||
return tokenizer.tokens()->stringifyList(false, false, false, true, false, nullptr, nullptr);
|
return tokenizer.tokens()->stringifyList(false, false, false, true, false, nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getSyntaxError(const char code[]) {
|
#define getSyntaxError(code) getSyntaxError_(code, __FILE__, __LINE__)
|
||||||
|
std::string getSyntaxError_(const char code[], const char* file, int line) {
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
try {
|
try {
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
} catch (InternalError& e) {
|
} catch (InternalError& e) {
|
||||||
if (e.id != "syntaxError")
|
if (e.id != "syntaxError")
|
||||||
return "";
|
return "";
|
||||||
|
@ -310,7 +312,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -358,7 +360,7 @@ private:
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
try {
|
try {
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
assertThrowFail(__FILE__, __LINE__);
|
assertThrowFail(__FILE__, __LINE__);
|
||||||
} catch (InternalError& e) {
|
} catch (InternalError& e) {
|
||||||
ASSERT_EQUALS("syntax error", e.errorMessage);
|
ASSERT_EQUALS("syntax error", e.errorMessage);
|
||||||
|
@ -392,14 +394,14 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.c");
|
ASSERT(tokenizer.tokenize(istr, "test.c"));
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
ASSERT_EQUALS("[test.cpp:1]: (information) The code 'class x y {' is not handled. You can use -I or --include to add handling of this code.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:1]: (information) The code 'class x y {' is not handled. You can use -I or --include to add handling of this code.\n", errout.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,14 +46,15 @@ private:
|
||||||
TEST_CASE(checkRedundantTokCheck);
|
TEST_CASE(checkRedundantTokCheck);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const char code[]) {
|
#define check(code) check_(code, __FILE__, __LINE__)
|
||||||
|
void check_(const char code[], const char* file, int line) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check..
|
// Check..
|
||||||
CheckInternal checkInternal;
|
CheckInternal checkInternal;
|
||||||
|
|
|
@ -77,7 +77,8 @@ private:
|
||||||
TEST_CASE(testStdDistance); // #10304
|
TEST_CASE(testStdDistance); // #10304
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const char* code, bool inconclusive = false, bool portability = false, Settings::PlatformType platform = Settings::Unspecified, bool onlyFormatStr = false) {
|
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
void check_(const char* file, int line, const char* code, bool inconclusive = false, bool portability = false, Settings::PlatformType platform = Settings::Unspecified, bool onlyFormatStr = false) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -92,7 +93,7 @@ private:
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check..
|
// Check..
|
||||||
CheckIO checkIO(&tokenizer, &settings, this);
|
CheckIO checkIO(&tokenizer, &settings, this);
|
||||||
|
|
|
@ -201,14 +201,15 @@ private:
|
||||||
TEST_CASE(functionCallCastConfig); // #9652
|
TEST_CASE(functionCallCastConfig); // #9652
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const char code[], bool cpp = false) {
|
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
void check_(const char* file, int line, const char code[], bool cpp = false) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, cpp?"test.cpp":"test.c");
|
ASSERT_LOC(tokenizer.tokenize(istr, cpp ? "test.cpp" : "test.c"), file, line);
|
||||||
|
|
||||||
// Check for leaks..
|
// Check for leaks..
|
||||||
CheckLeakAutoVar c;
|
CheckLeakAutoVar c;
|
||||||
|
@ -217,14 +218,14 @@ private:
|
||||||
c.runChecks(&tokenizer, &settings, this);
|
c.runChecks(&tokenizer, &settings, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const char code[], Settings & settings_) {
|
void check_(const char* file, int line, const char code[], Settings & settings_) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings_, this);
|
Tokenizer tokenizer(&settings_, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check for leaks..
|
// Check for leaks..
|
||||||
CheckLeakAutoVar c;
|
CheckLeakAutoVar c;
|
||||||
|
@ -2307,14 +2308,14 @@ public:
|
||||||
private:
|
private:
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
|
||||||
void check(const char code[]) {
|
void check_(const char* file, int line, const char code[]) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check for leaks..
|
// Check for leaks..
|
||||||
CheckLeakAutoVar checkLeak;
|
CheckLeakAutoVar checkLeak;
|
||||||
|
@ -2357,14 +2358,14 @@ public:
|
||||||
private:
|
private:
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
|
||||||
void check(const char code[]) {
|
void check_(const char* file, int line, const char code[]) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.c");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.c"), file, line);
|
||||||
|
|
||||||
// Check for leaks..
|
// Check for leaks..
|
||||||
CheckLeakAutoVar checkLeak;
|
CheckLeakAutoVar checkLeak;
|
||||||
|
|
|
@ -554,14 +554,14 @@ private:
|
||||||
{
|
{
|
||||||
Tokenizer tokenizer(&settings, nullptr);
|
Tokenizer tokenizer(&settings, nullptr);
|
||||||
std::istringstream istr("CString str; str.Format();");
|
std::istringstream istr("CString str; str.Format();");
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
ASSERT(library.isnotnoreturn(Token::findsimplematch(tokenizer.tokens(), "Format")));
|
ASSERT(library.isnotnoreturn(Token::findsimplematch(tokenizer.tokens(), "Format")));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
Tokenizer tokenizer(&settings, nullptr);
|
Tokenizer tokenizer(&settings, nullptr);
|
||||||
std::istringstream istr("HardDrive hd; hd.Format();");
|
std::istringstream istr("HardDrive hd; hd.Format();");
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
ASSERT(!library.isnotnoreturn(Token::findsimplematch(tokenizer.tokens(), "Format")));
|
ASSERT(!library.isnotnoreturn(Token::findsimplematch(tokenizer.tokens(), "Format")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -580,14 +580,14 @@ private:
|
||||||
{
|
{
|
||||||
Tokenizer tokenizer(&settings, nullptr);
|
Tokenizer tokenizer(&settings, nullptr);
|
||||||
std::istringstream istr("struct X : public Base { void dostuff() { f(0); } };");
|
std::istringstream istr("struct X : public Base { void dostuff() { f(0); } };");
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
ASSERT(library.isnullargbad(Token::findsimplematch(tokenizer.tokens(), "f"),1));
|
ASSERT(library.isnullargbad(Token::findsimplematch(tokenizer.tokens(), "f"),1));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
Tokenizer tokenizer(&settings, nullptr);
|
Tokenizer tokenizer(&settings, nullptr);
|
||||||
std::istringstream istr("struct X : public Base { void dostuff() { f(1,2); } };");
|
std::istringstream istr("struct X : public Base { void dostuff() { f(1,2); } };");
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
ASSERT(!library.isnullargbad(Token::findsimplematch(tokenizer.tokens(), "f"),1));
|
ASSERT(!library.isnullargbad(Token::findsimplematch(tokenizer.tokens(), "f"),1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,18 +39,19 @@ private:
|
||||||
TEST_CASE(open);
|
TEST_CASE(open);
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckMemoryLeak::AllocType functionReturnType(const char code[]) {
|
#define functionReturnType(code) functionReturnType_(code, __FILE__, __LINE__)
|
||||||
|
CheckMemoryLeak::AllocType functionReturnType_(const char code[], const char* file, int line) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
const CheckMemoryLeak c(&tokenizer, this, &settings);
|
const CheckMemoryLeak c(&tokenizer, this, &settings);
|
||||||
|
|
||||||
return c.functionReturnType(&tokenizer.getSymbolDatabase()->scopeList.front().functionList.front());
|
return (c.functionReturnType)(&tokenizer.getSymbolDatabase()->scopeList.front().functionList.front());
|
||||||
}
|
}
|
||||||
|
|
||||||
void testFunctionReturnType() {
|
void testFunctionReturnType() {
|
||||||
|
@ -98,7 +99,7 @@ private:
|
||||||
|
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
|
|
||||||
// there is no allocation
|
// there is no allocation
|
||||||
const Token *tok = Token::findsimplematch(tokenizer.tokens(), "ret =");
|
const Token *tok = Token::findsimplematch(tokenizer.tokens(), "ret =");
|
||||||
|
@ -122,7 +123,8 @@ private:
|
||||||
Settings settings1;
|
Settings settings1;
|
||||||
Settings settings2;
|
Settings settings2;
|
||||||
|
|
||||||
void check(const char code[]) {
|
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
void check_(const char* file, int line, const char code[]) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -131,7 +133,7 @@ private:
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(settings, this);
|
Tokenizer tokenizer(settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check for memory leaks..
|
// Check for memory leaks..
|
||||||
CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, settings, this);
|
CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, settings, this);
|
||||||
|
@ -467,18 +469,18 @@ private:
|
||||||
* Tokenize and execute leak check for given code
|
* Tokenize and execute leak check for given code
|
||||||
* @param code Source code
|
* @param code Source code
|
||||||
*/
|
*/
|
||||||
void check(const char code[]) {
|
void check_(const char* file, int line, const char code[]) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check for memory leaks..
|
// Check for memory leaks..
|
||||||
CheckMemoryLeakInClass checkMemoryLeak(&tokenizer, &settings, this);
|
CheckMemoryLeakInClass checkMemoryLeak(&tokenizer, &settings, this);
|
||||||
checkMemoryLeak.check();
|
(checkMemoryLeak.check)();
|
||||||
}
|
}
|
||||||
|
|
||||||
void run() OVERRIDE {
|
void run() OVERRIDE {
|
||||||
|
@ -1643,18 +1645,18 @@ public:
|
||||||
private:
|
private:
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
|
||||||
void check(const char code[], bool isCPP = true) {
|
void check_(const char* file, int line, const char code[], bool isCPP = true) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, isCPP ? "test.cpp" : "test.c");
|
ASSERT_LOC(tokenizer.tokenize(istr, isCPP ? "test.cpp" : "test.c"), file, line);
|
||||||
|
|
||||||
// Check for memory leaks..
|
// Check for memory leaks..
|
||||||
CheckMemoryLeakStructMember checkMemoryLeakStructMember(&tokenizer, &settings, this);
|
CheckMemoryLeakStructMember checkMemoryLeakStructMember(&tokenizer, &settings, this);
|
||||||
checkMemoryLeakStructMember.check();
|
(checkMemoryLeakStructMember.check)();
|
||||||
}
|
}
|
||||||
|
|
||||||
void run() OVERRIDE {
|
void run() OVERRIDE {
|
||||||
|
@ -2124,18 +2126,18 @@ public:
|
||||||
private:
|
private:
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
|
||||||
void check(const char code[]) {
|
void check_(const char* file, int line, const char code[]) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check for memory leaks..
|
// Check for memory leaks..
|
||||||
CheckMemoryLeakNoVar checkMemoryLeakNoVar(&tokenizer, &settings, this);
|
CheckMemoryLeakNoVar checkMemoryLeakNoVar(&tokenizer, &settings, this);
|
||||||
checkMemoryLeakNoVar.check();
|
(checkMemoryLeakNoVar.check)();
|
||||||
}
|
}
|
||||||
|
|
||||||
void run() OVERRIDE {
|
void run() OVERRIDE {
|
||||||
|
|
|
@ -156,10 +156,11 @@ private:
|
||||||
TEST_CASE(addNull);
|
TEST_CASE(addNull);
|
||||||
TEST_CASE(isPointerDeRefFunctionDecl);
|
TEST_CASE(isPointerDeRefFunctionDecl);
|
||||||
|
|
||||||
TEST_CASE(ctu);
|
TEST_CASE(ctuTest);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const char code[], bool inconclusive = false, const char filename[] = "test.cpp") {
|
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
void check_(const char* file, int line, const char code[], bool inconclusive = false, const char filename[] = "test.cpp") {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -168,8 +169,7 @@ private:
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
if (!tokenizer.tokenize(istr, filename))
|
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);
|
||||||
return;
|
|
||||||
|
|
||||||
// Check for null pointer dereferences..
|
// Check for null pointer dereferences..
|
||||||
CheckNullPointer checkNullPointer;
|
CheckNullPointer checkNullPointer;
|
||||||
|
@ -3688,7 +3688,7 @@ private:
|
||||||
Settings settings1;
|
Settings settings1;
|
||||||
Tokenizer tokenizer(&settings1,this);
|
Tokenizer tokenizer(&settings1,this);
|
||||||
std::istringstream code("void f() { int a,b,c; x(a,b,c); }");
|
std::istringstream code("void f() { int a,b,c; x(a,b,c); }");
|
||||||
tokenizer.tokenize(code,"test.c");
|
ASSERT_EQUALS(true, tokenizer.tokenize(code, "test.c"));
|
||||||
const Token *xtok = Token::findsimplematch(tokenizer.tokens(), "x");
|
const Token *xtok = Token::findsimplematch(tokenizer.tokens(), "x");
|
||||||
|
|
||||||
// nothing bad..
|
// nothing bad..
|
||||||
|
@ -4010,14 +4010,15 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ctu(const char code[]) {
|
#define ctu(code) ctu_(code, __FILE__, __LINE__)
|
||||||
|
void ctu_(const char code[], const char* file, int line) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
CTU::FileInfo *ctu = CTU::getFileInfo(&tokenizer);
|
CTU::FileInfo *ctu = CTU::getFileInfo(&tokenizer);
|
||||||
|
|
||||||
|
@ -4033,7 +4034,7 @@ private:
|
||||||
delete ctu;
|
delete ctu;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ctu() {
|
void ctuTest() {
|
||||||
setMultiline();
|
setMultiline();
|
||||||
|
|
||||||
ctu("void f(int *fp) {\n"
|
ctu("void f(int *fp) {\n"
|
||||||
|
|
|
@ -260,7 +260,8 @@ private:
|
||||||
TEST_CASE(constVariableArrayMember); // #10371
|
TEST_CASE(constVariableArrayMember); // #10371
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const char code[], const char *filename = nullptr, bool experimental = false, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {
|
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
void check_(const char* file, int line, const char code[], const char *filename = nullptr, bool experimental = false, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -280,7 +281,7 @@ private:
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(settings, this);
|
Tokenizer tokenizer(settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, filename ? filename : "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, filename ? filename : "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check..
|
// Check..
|
||||||
CheckOther checkOther(&tokenizer, settings, this);
|
CheckOther checkOther(&tokenizer, settings, this);
|
||||||
|
@ -289,8 +290,8 @@ private:
|
||||||
(void)runSimpleChecks; // TODO Remove this
|
(void)runSimpleChecks; // TODO Remove this
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const char code[], Settings *s) {
|
void check_(const char* file, int line, const char code[], Settings *s) {
|
||||||
check(code,"test.cpp",false,true,true,false,s);
|
check_(file, line, code, "test.cpp", false, true, true, false, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkP(const char code[], const char *filename = "test.cpp") {
|
void checkP(const char code[], const char *filename = "test.cpp") {
|
||||||
|
@ -1300,7 +1301,8 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (style) The scope of the variable 'x' can be reduced.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) The scope of the variable 'x' can be reduced.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkOldStylePointerCast(const char code[]) {
|
#define checkOldStylePointerCast(code) checkOldStylePointerCast_(code, __FILE__, __LINE__)
|
||||||
|
void checkOldStylePointerCast_(const char code[], const char* file, int line) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -1311,7 +1313,7 @@ private:
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizerCpp(&settings, this);
|
Tokenizer tokenizerCpp(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizerCpp.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizerCpp.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);
|
CheckOther checkOtherCpp(&tokenizerCpp, &settings, this);
|
||||||
checkOtherCpp.warningOldStylePointerCast();
|
checkOtherCpp.warningOldStylePointerCast();
|
||||||
|
@ -1441,7 +1443,8 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (style) C-style pointer casting\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (style) C-style pointer casting\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkInvalidPointerCast(const char code[], bool portability = true, bool inconclusive = false) {
|
#define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
void checkInvalidPointerCast_(const char* file, int line, const char code[], bool portability = true, bool inconclusive = false) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -1455,7 +1458,7 @@ private:
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
CheckOther checkOtherCpp(&tokenizer, &settings, this);
|
CheckOther checkOtherCpp(&tokenizer, &settings, this);
|
||||||
checkOtherCpp.invalidPointerCast();
|
checkOtherCpp.invalidPointerCast();
|
||||||
|
|
|
@ -30,15 +30,15 @@ public:
|
||||||
private:
|
private:
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
|
||||||
|
#define check(code) check_(code, __FILE__, __LINE__)
|
||||||
void check(const char code[]) {
|
void check_(const char code[], const char* file, int line) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check for postfix operators..
|
// Check for postfix operators..
|
||||||
CheckPostfixOperator checkPostfixOperator(&tokenizer, &settings, this);
|
CheckPostfixOperator checkPostfixOperator(&tokenizer, &settings, this);
|
||||||
|
|
|
@ -261,7 +261,7 @@ private:
|
||||||
TEST_CASE(templateAlias5);
|
TEST_CASE(templateAlias5);
|
||||||
|
|
||||||
// Test TemplateSimplifier::instantiateMatch
|
// Test TemplateSimplifier::instantiateMatch
|
||||||
TEST_CASE(instantiateMatch);
|
TEST_CASE(instantiateMatchTest);
|
||||||
TEST_CASE(templateParameterWithoutName); // #8602 Template default parameter without name yields syntax error
|
TEST_CASE(templateParameterWithoutName); // #8602 Template default parameter without name yields syntax error
|
||||||
|
|
||||||
TEST_CASE(templateTypeDeduction1); // #8962
|
TEST_CASE(templateTypeDeduction1); // #8962
|
||||||
|
@ -302,7 +302,8 @@ private:
|
||||||
TEST_CASE(explicitBool2);
|
TEST_CASE(explicitBool2);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string tok(const char code[], bool debugwarnings = false, Settings::PlatformType type = Settings::Native) {
|
#define tok(...) tok_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
std::string tok_(const char* file, int line, const char code[], bool debugwarnings = false, Settings::PlatformType type = Settings::Native) {
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
settings.debugwarnings = debugwarnings;
|
settings.debugwarnings = debugwarnings;
|
||||||
|
@ -310,7 +311,7 @@ private:
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
|
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
return tokenizer.tokens()->stringifyList(nullptr, true);
|
return tokenizer.tokens()->stringifyList(nullptr, true);
|
||||||
}
|
}
|
||||||
|
@ -5614,16 +5615,17 @@ private:
|
||||||
ASSERT_EQUALS(expected, tok(code));
|
ASSERT_EQUALS(expected, tok(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool instantiateMatch(const char code[], const std::size_t numberOfArguments, const char patternAfter[]) {
|
#define instantiateMatch(code, numberOfArguments, patternAfter) instantiateMatch_(code, numberOfArguments, patternAfter, __FILE__, __LINE__)
|
||||||
|
bool instantiateMatch_(const char code[], const std::size_t numberOfArguments, const char patternAfter[], const char* file, int line) {
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
|
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp", "");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp", ""), file, line);
|
||||||
|
|
||||||
return TemplateSimplifier::instantiateMatch(tokenizer.tokens(), numberOfArguments, false, patternAfter);
|
return (TemplateSimplifier::instantiateMatch)(tokenizer.tokens(), numberOfArguments, false, patternAfter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void instantiateMatch() {
|
void instantiateMatchTest() {
|
||||||
// Ticket #8175
|
// Ticket #8175
|
||||||
ASSERT_EQUALS(false,
|
ASSERT_EQUALS(false,
|
||||||
instantiateMatch("ConvertHelper < From, To > c ;",
|
instantiateMatch("ConvertHelper < From, To > c ;",
|
||||||
|
|
|
@ -370,14 +370,15 @@ private:
|
||||||
TEST_CASE(simplifyVarDeclInitLists);
|
TEST_CASE(simplifyVarDeclInitLists);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native) {
|
#define tok(...) tok_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
std::string tok_(const char* file, int line, const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native) {
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
settings0.platform(type);
|
settings0.platform(type);
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
|
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
if (simplify)
|
if (simplify)
|
||||||
tokenizer.simplifyTokenList2();
|
tokenizer.simplifyTokenList2();
|
||||||
|
@ -385,14 +386,15 @@ private:
|
||||||
return tokenizer.tokens()->stringifyList(nullptr, !simplify);
|
return tokenizer.tokens()->stringifyList(nullptr, !simplify);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string tokWithWindows(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native) {
|
#define tokWithWindows(...) tokWithWindows_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
std::string tokWithWindows_(const char* file, int line, const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native) {
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
settings_windows.platform(type);
|
settings_windows.platform(type);
|
||||||
Tokenizer tokenizer(&settings_windows, this);
|
Tokenizer tokenizer(&settings_windows, this);
|
||||||
|
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
if (simplify)
|
if (simplify)
|
||||||
tokenizer.simplifyTokenList2();
|
tokenizer.simplifyTokenList2();
|
||||||
|
@ -400,44 +402,47 @@ private:
|
||||||
return tokenizer.tokens()->stringifyList(nullptr, !simplify);
|
return tokenizer.tokens()->stringifyList(nullptr, !simplify);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string tok(const char code[], const char filename[], bool simplify = true) {
|
std::string tok_(const char* file, int line, const char code[], const char filename[], bool simplify = true) {
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
|
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, filename);
|
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);
|
||||||
if (simplify)
|
if (simplify)
|
||||||
tokenizer.simplifyTokenList2();
|
tokenizer.simplifyTokenList2();
|
||||||
|
|
||||||
return tokenizer.tokens()->stringifyList(nullptr, false);
|
return tokenizer.tokens()->stringifyList(nullptr, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string tokWithNewlines(const char code[]) {
|
#define tokWithNewlines(code) tokWithNewlines_(code, __FILE__, __LINE__)
|
||||||
|
std::string tokWithNewlines_(const char code[], const char* file, int line) {
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
|
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
tokenizer.simplifyTokenList2();
|
tokenizer.simplifyTokenList2();
|
||||||
|
|
||||||
return tokenizer.tokens()->stringifyList(false, false, false, true, false);
|
return tokenizer.tokens()->stringifyList(false, false, false, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string tokWithStdLib(const char code[]) {
|
#define tokWithStdLib(code) tokWithStdLib_(code, __FILE__, __LINE__)
|
||||||
|
std::string tokWithStdLib_(const char code[], const char* file, int line) {
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
Tokenizer tokenizer(&settings_std, this);
|
Tokenizer tokenizer(&settings_std, this);
|
||||||
|
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
tokenizer.simplifyTokenList2();
|
tokenizer.simplifyTokenList2();
|
||||||
|
|
||||||
return tokenizer.tokens()->stringifyList(nullptr, false);
|
return tokenizer.tokens()->stringifyList(nullptr, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string tokenizeAndStringify(const char code[], bool simplify = false, bool expand = true, Settings::PlatformType platform = Settings::Native, const char* filename = "test.cpp", bool cpp11 = true) {
|
#define tokenizeAndStringify(...) tokenizeAndStringify_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
std::string tokenizeAndStringify_(const char* file, int linenr, const char code[], bool simplify = false, bool expand = true, Settings::PlatformType platform = Settings::Native, const char* filename = "test.cpp", bool cpp11 = true) {
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
settings1.debugwarnings = true;
|
settings1.debugwarnings = true;
|
||||||
|
@ -447,7 +452,7 @@ private:
|
||||||
// tokenize..
|
// tokenize..
|
||||||
Tokenizer tokenizer(&settings1, this);
|
Tokenizer tokenizer(&settings1, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, filename);
|
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, linenr);
|
||||||
if (simplify)
|
if (simplify)
|
||||||
tokenizer.simplifyTokenList2();
|
tokenizer.simplifyTokenList2();
|
||||||
|
|
||||||
|
@ -467,12 +472,13 @@ private:
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string tokenizeDebugListing(const char code[], bool simplify = false, const char filename[] = "test.cpp") {
|
#define tokenizeDebugListing(...) tokenizeDebugListing_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
std::string tokenizeDebugListing_(const char* file, int line, const char code[], bool simplify = false, const char filename[] = "test.cpp") {
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, filename);
|
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);
|
||||||
|
|
||||||
if (simplify)
|
if (simplify)
|
||||||
tokenizer.simplifyTokenList2();
|
tokenizer.simplifyTokenList2();
|
||||||
|
@ -1999,7 +2005,7 @@ private:
|
||||||
|
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
|
|
||||||
ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false));
|
ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false));
|
||||||
}
|
}
|
||||||
|
@ -2011,7 +2017,7 @@ private:
|
||||||
|
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
|
|
||||||
ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false));
|
ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false));
|
||||||
}
|
}
|
||||||
|
@ -2023,7 +2029,7 @@ private:
|
||||||
|
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
|
|
||||||
ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false));
|
ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false));
|
||||||
}
|
}
|
||||||
|
@ -2035,7 +2041,7 @@ private:
|
||||||
|
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
|
|
||||||
ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false));
|
ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false));
|
||||||
}
|
}
|
||||||
|
@ -2047,7 +2053,7 @@ private:
|
||||||
|
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
|
|
||||||
ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false));
|
ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false));
|
||||||
}
|
}
|
||||||
|
@ -3101,14 +3107,14 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define simplifyIfAndWhileAssign(code) simplifyIfAndWhileAssign_(code, __FILE__, __LINE__)
|
||||||
std::string simplifyIfAndWhileAssign(const char code[]) {
|
std::string simplifyIfAndWhileAssign_(const char code[], const char* file, int line) {
|
||||||
// tokenize..
|
// tokenize..
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
tokenizer.simplifyIfAndWhileAssign();
|
(tokenizer.simplifyIfAndWhileAssign)();
|
||||||
|
|
||||||
return tokenizer.tokens()->stringifyList(nullptr, false);
|
return tokenizer.tokens()->stringifyList(nullptr, false);
|
||||||
}
|
}
|
||||||
|
@ -3195,7 +3201,7 @@ private:
|
||||||
|
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr("{ while (!(m = q->push<Message>(x))) {} }");
|
std::istringstream istr("{ while (!(m = q->push<Message>(x))) {} }");
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
tokenizer.simplifyTokenList2();
|
tokenizer.simplifyTokenList2();
|
||||||
|
|
||||||
ASSERT_EQUALS("{ m = q . push < Message > ( x ) ; while ( ! m ) { m = q . push < Message > ( x ) ; } }", tokenizer.tokens()->stringifyList(nullptr, false));
|
ASSERT_EQUALS("{ m = q . push < Message > ( x ) ; while ( ! m ) { m = q . push < Message > ( x ) ; } }", tokenizer.tokens()->stringifyList(nullptr, false));
|
||||||
|
@ -4445,7 +4451,7 @@ private:
|
||||||
void duplicateDefinition() { // #3565 - wrongly detects duplicate definition
|
void duplicateDefinition() { // #3565 - wrongly detects duplicate definition
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr("{ x ; return a not_eq x; }");
|
std::istringstream istr("{ x ; return a not_eq x; }");
|
||||||
tokenizer.tokenize(istr, "test.c");
|
ASSERT(tokenizer.tokenize(istr, "test.c"));
|
||||||
Token *x_token = tokenizer.list.front()->tokAt(5);
|
Token *x_token = tokenizer.list.front()->tokAt(5);
|
||||||
ASSERT_EQUALS(false, tokenizer.duplicateDefinition(&x_token));
|
ASSERT_EQUALS(false, tokenizer.duplicateDefinition(&x_token));
|
||||||
}
|
}
|
||||||
|
@ -5234,14 +5240,15 @@ private:
|
||||||
"}"));
|
"}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string simplifyKnownVariables(const char code[]) {
|
#define simplifyKnownVariables(code) simplifyKnownVariables_(code, __FILE__, __LINE__)
|
||||||
|
std::string simplifyKnownVariables_(const char code[], const char* file, int line) {
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
tokenizer.simplifyKnownVariables();
|
(tokenizer.simplifyKnownVariables)();
|
||||||
|
|
||||||
return tokenizer.tokens()->stringifyList(nullptr, false);
|
return tokenizer.tokens()->stringifyList(nullptr, false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -199,7 +199,8 @@ private:
|
||||||
TEST_CASE(simplifyTypedefMacro);
|
TEST_CASE(simplifyTypedefMacro);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native, bool debugwarnings = true) {
|
#define tok(...) tok_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
std::string tok_(const char* file, int line, const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native, bool debugwarnings = true) {
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
settings0.certainty.enable(Certainty::inconclusive);
|
settings0.certainty.enable(Certainty::inconclusive);
|
||||||
|
@ -208,7 +209,7 @@ private:
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
|
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
return tokenizer.tokens()->stringifyList(nullptr, !simplify);
|
return tokenizer.tokens()->stringifyList(nullptr, !simplify);
|
||||||
}
|
}
|
||||||
|
@ -250,15 +251,15 @@ private:
|
||||||
return tokenizer.tokens()->stringifyList(nullptr, false);
|
return tokenizer.tokens()->stringifyList(nullptr, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define checkSimplifyTypedef(code) checkSimplifyTypedef_(code, __FILE__, __LINE__)
|
||||||
void checkSimplifyTypedef(const char code[]) {
|
void checkSimplifyTypedef_(const char code[], const char* file, int line) {
|
||||||
errout.str("");
|
errout.str("");
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
settings2.certainty.enable(Certainty::inconclusive);
|
settings2.certainty.enable(Certainty::inconclusive);
|
||||||
settings2.debugwarnings = true; // show warnings about unhandled typedef
|
settings2.debugwarnings = true; // show warnings about unhandled typedef
|
||||||
Tokenizer tokenizer(&settings2, this);
|
Tokenizer tokenizer(&settings2, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,8 @@ private:
|
||||||
TEST_CASE(scopeInfo2);
|
TEST_CASE(scopeInfo2);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string tok(const char code[], Settings::PlatformType type = Settings::Native, bool debugwarnings = true) {
|
#define tok(...) tok_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
std::string tok_(const char* file, int line, const char code[], Settings::PlatformType type = Settings::Native, bool debugwarnings = true) {
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
settings0.certainty.enable(Certainty::inconclusive);
|
settings0.certainty.enable(Certainty::inconclusive);
|
||||||
|
@ -104,7 +105,7 @@ private:
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
|
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
return tokenizer.tokens()->stringifyList(nullptr);
|
return tokenizer.tokens()->stringifyList(nullptr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,14 +50,15 @@ private:
|
||||||
TEST_CASE(customStrncat);
|
TEST_CASE(customStrncat);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const char code[]) {
|
#define check(code) check_(code, __FILE__, __LINE__)
|
||||||
|
void check_(const char code[], const char* file, int line) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check...
|
// Check...
|
||||||
CheckSizeof checkSizeof(&tokenizer, &settings, this);
|
CheckSizeof checkSizeof(&tokenizer, &settings, this);
|
||||||
|
|
|
@ -174,7 +174,8 @@ private:
|
||||||
TEST_CASE(checkMutexes);
|
TEST_CASE(checkMutexes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const char code[], const bool inconclusive=false, const Standards::cppstd_t cppstandard=Standards::CPPLatest) {
|
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
void check_(const char* file, int line, const char code[], const bool inconclusive = false, const Standards::cppstd_t cppstandard = Standards::CPPLatest) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -188,22 +189,23 @@ private:
|
||||||
|
|
||||||
CheckStl checkStl(&tokenizer, &settings, this);
|
CheckStl checkStl(&tokenizer, &settings, this);
|
||||||
|
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
checkStl.runChecks(&tokenizer, &settings, this);
|
checkStl.runChecks(&tokenizer, &settings, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const std::string &code, const bool inconclusive=false) {
|
void check_(const char* file, int line, const std::string& code, const bool inconclusive = false) {
|
||||||
check(code.c_str(), inconclusive);
|
check_(file, line, code.c_str(), inconclusive);
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkNormal(const char code[]) {
|
#define checkNormal(code) checkNormal_(code, __FILE__, __LINE__)
|
||||||
|
void checkNormal_(const char code[], const char* file, int line) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check..
|
// Check..
|
||||||
CheckStl checkStl(&tokenizer, &settings, this);
|
CheckStl checkStl(&tokenizer, &settings, this);
|
||||||
|
|
|
@ -60,14 +60,15 @@ private:
|
||||||
TEST_CASE(deadStrcmp);
|
TEST_CASE(deadStrcmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const char code[], const char filename[] = "test.cpp") {
|
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
void check_(const char* file, int line, const char code[], const char filename[] = "test.cpp") {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, filename);
|
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);
|
||||||
|
|
||||||
// Check char variable usage..
|
// Check char variable usage..
|
||||||
CheckString checkString(&tokenizer, &settings, this);
|
CheckString checkString(&tokenizer, &settings, this);
|
||||||
|
|
|
@ -121,6 +121,7 @@ extern std::ostringstream output;
|
||||||
|
|
||||||
#define TEST_CASE( NAME ) do { if (prepareTest(#NAME)) { setVerbose(false); NAME(); } } while (false)
|
#define TEST_CASE( NAME ) do { if (prepareTest(#NAME)) { setVerbose(false); NAME(); } } while (false)
|
||||||
#define ASSERT( CONDITION ) if (!assert_(__FILE__, __LINE__, (CONDITION))) return
|
#define ASSERT( CONDITION ) if (!assert_(__FILE__, __LINE__, (CONDITION))) return
|
||||||
|
#define ASSERT_LOC( CONDITION, FILE_, LINE_ ) assert_(FILE_, LINE_, (CONDITION))
|
||||||
#define CHECK_EQUALS( EXPECTED, ACTUAL ) assertEquals(__FILE__, __LINE__, (EXPECTED), (ACTUAL))
|
#define CHECK_EQUALS( EXPECTED, ACTUAL ) assertEquals(__FILE__, __LINE__, (EXPECTED), (ACTUAL))
|
||||||
#define ASSERT_EQUALS( EXPECTED, ACTUAL ) if (!assertEquals(__FILE__, __LINE__, (EXPECTED), (ACTUAL))) return
|
#define ASSERT_EQUALS( EXPECTED, ACTUAL ) if (!assertEquals(__FILE__, __LINE__, (EXPECTED), (ACTUAL))) return
|
||||||
#define ASSERT_EQUALS_WITHOUT_LINENUMBERS( EXPECTED, ACTUAL ) assertEqualsWithoutLineNumbers(__FILE__, __LINE__, EXPECTED, ACTUAL)
|
#define ASSERT_EQUALS_WITHOUT_LINENUMBERS( EXPECTED, ACTUAL ) assertEqualsWithoutLineNumbers(__FILE__, __LINE__, EXPECTED, ACTUAL)
|
||||||
|
|
|
@ -36,7 +36,8 @@ private:
|
||||||
TEST_CASE(createSummariesNoreturn);
|
TEST_CASE(createSummariesNoreturn);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string createSummaries(const char code[], const char filename[] = "test.cpp") {
|
#define createSummaries(...) createSummaries_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
std::string createSummaries_(const char* file, int line, const char code[], const char filename[] = "test.cpp") {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -44,7 +45,7 @@ private:
|
||||||
Settings settings;
|
Settings settings;
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, filename);
|
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);
|
||||||
return Summaries::create(&tokenizer, "");
|
return Summaries::create(&tokenizer, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,8 +82,7 @@ private:
|
||||||
const static SymbolDatabase* getSymbolDB_inner(Tokenizer& tokenizer, const char* code, const char* filename) {
|
const static SymbolDatabase* getSymbolDB_inner(Tokenizer& tokenizer, const char* code, const char* filename) {
|
||||||
errout.str("");
|
errout.str("");
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, filename);
|
return tokenizer.tokenize(istr, filename) ? tokenizer.getSymbolDatabase() : nullptr;
|
||||||
return tokenizer.getSymbolDatabase();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const Scope *findFunctionScopeByToken(const SymbolDatabase * db, const Token *tok) {
|
static const Scope *findFunctionScopeByToken(const SymbolDatabase * db, const Token *tok) {
|
||||||
|
@ -2147,7 +2146,8 @@ private:
|
||||||
ASSERT_EQUALS("char", arg1->typeEndToken()->str());
|
ASSERT_EQUALS("char", arg1->typeEndToken()->str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const char code[], bool debug = true, const char filename[] = "test.cpp") {
|
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
void check_(const char* file, int line, const char code[], bool debug = true, const char filename[] = "test.cpp") {
|
||||||
// Clear the error log
|
// Clear the error log
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -2157,7 +2157,7 @@ private:
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings1, this);
|
Tokenizer tokenizer(&settings1, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, filename);
|
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);
|
||||||
|
|
||||||
// force symbol database creation
|
// force symbol database creation
|
||||||
tokenizer.createSymbolDatabase();
|
tokenizer.createSymbolDatabase();
|
||||||
|
@ -7138,10 +7138,11 @@ private:
|
||||||
ASSERT(class_scope->functionList.begin()->functionScope == &*scope);
|
ASSERT(class_scope->functionList.begin()->functionScope == &*scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string typeOf(const char code[], const char pattern[], const char filename[] = "test.cpp", const Settings *settings = nullptr) {
|
#define typeOf(...) typeOf_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
std::string typeOf_(const char* file, int line, const char code[], const char pattern[], const char filename[] = "test.cpp", const Settings *settings = nullptr) {
|
||||||
Tokenizer tokenizer(settings ? settings : &settings2, this);
|
Tokenizer tokenizer(settings ? settings : &settings2, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, filename);
|
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);
|
||||||
const Token* tok;
|
const Token* tok;
|
||||||
for (tok = tokenizer.list.back(); tok; tok = tok->previous())
|
for (tok = tokenizer.list.back(); tok; tok = tok->previous())
|
||||||
if (Token::simpleMatch(tok, pattern, strlen(pattern)))
|
if (Token::simpleMatch(tok, pattern, strlen(pattern)))
|
||||||
|
|
|
@ -132,12 +132,13 @@ private:
|
||||||
TokenList::deleteTokens(token);
|
TokenList::deleteTokens(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Match(const std::string &code, const std::string &pattern, unsigned int varid=0) {
|
#define MatchCheck(...) MatchCheck_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
bool MatchCheck_(const char* file, int line, const std::string& code, const std::string& pattern, unsigned int varid = 0) {
|
||||||
static const Settings settings;
|
static const Settings settings;
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(";" + code + ";");
|
std::istringstream istr(";" + code + ";");
|
||||||
try {
|
try {
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
} catch (...) {}
|
} catch (...) {}
|
||||||
return Token::Match(tokenizer.tokens()->next(), pattern.c_str(), varid);
|
return Token::Match(tokenizer.tokens()->next(), pattern.c_str(), varid);
|
||||||
}
|
}
|
||||||
|
@ -762,7 +763,7 @@ private:
|
||||||
|
|
||||||
std::vector<std::string>::const_iterator test_op, test_ops_end = test_ops.end();
|
std::vector<std::string>::const_iterator test_op, test_ops_end = test_ops.end();
|
||||||
for (test_op = test_ops.begin(); test_op != test_ops_end; ++test_op) {
|
for (test_op = test_ops.begin(); test_op != test_ops_end; ++test_op) {
|
||||||
ASSERT_EQUALS(true, Match(*test_op, "%op%"));
|
ASSERT_EQUALS(true, MatchCheck(*test_op, "%op%"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Negative test against other operators
|
// Negative test against other operators
|
||||||
|
@ -771,7 +772,7 @@ private:
|
||||||
|
|
||||||
std::vector<std::string>::const_iterator other_op, other_ops_end = other_ops.end();
|
std::vector<std::string>::const_iterator other_op, other_ops_end = other_ops.end();
|
||||||
for (other_op = other_ops.begin(); other_op != other_ops_end; ++other_op) {
|
for (other_op = other_ops.begin(); other_op != other_ops_end; ++other_op) {
|
||||||
ASSERT_EQUALS_MSG(false, Match(*other_op, "%op%"), "Failing other operator: " + *other_op);
|
ASSERT_EQUALS_MSG(false, MatchCheck(*other_op, "%op%"), "Failing other operator: " + *other_op);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -784,7 +785,7 @@ private:
|
||||||
|
|
||||||
std::vector<std::string>::const_iterator test_op, test_ops_end = test_ops.end();
|
std::vector<std::string>::const_iterator test_op, test_ops_end = test_ops.end();
|
||||||
for (test_op = test_ops.begin(); test_op != test_ops_end; ++test_op) {
|
for (test_op = test_ops.begin(); test_op != test_ops_end; ++test_op) {
|
||||||
ASSERT_EQUALS(true, Match(*test_op, "%cop%"));
|
ASSERT_EQUALS(true, MatchCheck(*test_op, "%cop%"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Negative test against other operators
|
// Negative test against other operators
|
||||||
|
@ -794,7 +795,7 @@ private:
|
||||||
|
|
||||||
std::vector<std::string>::const_iterator other_op, other_ops_end = other_ops.end();
|
std::vector<std::string>::const_iterator other_op, other_ops_end = other_ops.end();
|
||||||
for (other_op = other_ops.begin(); other_op != other_ops_end; ++other_op) {
|
for (other_op = other_ops.begin(); other_op != other_ops_end; ++other_op) {
|
||||||
ASSERT_EQUALS_MSG(false, Match(*other_op, "%cop%"), "Failing other operator: " + *other_op);
|
ASSERT_EQUALS_MSG(false, MatchCheck(*other_op, "%cop%"), "Failing other operator: " + *other_op);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -444,7 +444,8 @@ private:
|
||||||
TEST_CASE(simplifyIfSwitchForInit4);
|
TEST_CASE(simplifyIfSwitchForInit4);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string tokenizeAndStringify(const char code[], bool expand = true, Settings::PlatformType platform = Settings::Native, const char* filename = "test.cpp", bool cpp11 = true) {
|
#define tokenizeAndStringify(...) tokenizeAndStringify_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
std::string tokenizeAndStringify_(const char* file, int linenr, const char code[], bool expand = true, Settings::PlatformType platform = Settings::Native, const char* filename = "test.cpp", bool cpp11 = true) {
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
settings1.debugwarnings = true;
|
settings1.debugwarnings = true;
|
||||||
|
@ -454,7 +455,7 @@ private:
|
||||||
// tokenize..
|
// tokenize..
|
||||||
Tokenizer tokenizer(&settings1, this);
|
Tokenizer tokenizer(&settings1, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, filename);
|
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, linenr);
|
||||||
|
|
||||||
// filter out ValueFlow messages..
|
// filter out ValueFlow messages..
|
||||||
const std::string debugwarnings = errout.str();
|
const std::string debugwarnings = errout.str();
|
||||||
|
@ -472,7 +473,8 @@ private:
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string tokenizeAndStringifyWindows(const char code[], bool expand = true, Settings::PlatformType platform = Settings::Native, const char* filename = "test.cpp", bool cpp11 = true) {
|
#define tokenizeAndStringifyWindows(...) tokenizeAndStringifyWindows_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
std::string tokenizeAndStringifyWindows_(const char* file, int linenr, const char code[], bool expand = true, Settings::PlatformType platform = Settings::Native, const char* filename = "test.cpp", bool cpp11 = true) {
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
settings_windows.debugwarnings = true;
|
settings_windows.debugwarnings = true;
|
||||||
|
@ -482,7 +484,7 @@ private:
|
||||||
// tokenize..
|
// tokenize..
|
||||||
Tokenizer tokenizer(&settings_windows, this);
|
Tokenizer tokenizer(&settings_windows, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, filename);
|
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, linenr);
|
||||||
|
|
||||||
// filter out ValueFlow messages..
|
// filter out ValueFlow messages..
|
||||||
const std::string debugwarnings = errout.str();
|
const std::string debugwarnings = errout.str();
|
||||||
|
@ -500,19 +502,20 @@ private:
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string tokenizeAndStringify(const char code[], const Settings &settings, const char filename[] = "test.cpp") {
|
std::string tokenizeAndStringify_(const char* file, int line, const char code[], const Settings &settings, const char filename[] = "test.cpp") {
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// tokenize..
|
// tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, filename);
|
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);
|
||||||
if (!tokenizer.tokens())
|
if (!tokenizer.tokens())
|
||||||
return "";
|
return "";
|
||||||
return tokenizer.tokens()->stringifyList(false, true, false, true, false, nullptr, nullptr);
|
return tokenizer.tokens()->stringifyList(false, true, false, true, false, nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string tokenizeDebugListing(const char code[], const char filename[] = "test.cpp") {
|
#define tokenizeDebugListing(...) tokenizeDebugListing_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
std::string tokenizeDebugListing_(const char* file, int line, const char code[], const char filename[] = "test.cpp") {
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
settings2.standards.c = Standards::C89;
|
settings2.standards.c = Standards::C89;
|
||||||
|
@ -520,7 +523,7 @@ private:
|
||||||
|
|
||||||
Tokenizer tokenizer(&settings2, this);
|
Tokenizer tokenizer(&settings2, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, filename);
|
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);
|
||||||
|
|
||||||
// result..
|
// result..
|
||||||
return tokenizer.tokens()->stringifyList(true,true,true,true,false);
|
return tokenizer.tokens()->stringifyList(true,true,true,true,false);
|
||||||
|
@ -2808,7 +2811,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token *tok = tokenizer.tokens();
|
const Token *tok = tokenizer.tokens();
|
||||||
// A body {}
|
// A body {}
|
||||||
ASSERT_EQUALS(true, tok->linkAt(2) == tok->tokAt(9));
|
ASSERT_EQUALS(true, tok->linkAt(2) == tok->tokAt(9));
|
||||||
|
@ -2833,7 +2836,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token *tok = tokenizer.tokens();
|
const Token *tok = tokenizer.tokens();
|
||||||
// a[10]
|
// a[10]
|
||||||
ASSERT_EQUALS(true, tok->linkAt(7) == tok->tokAt(9));
|
ASSERT_EQUALS(true, tok->linkAt(7) == tok->tokAt(9));
|
||||||
|
@ -2857,7 +2860,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token *tok = tokenizer.tokens();
|
const Token *tok = tokenizer.tokens();
|
||||||
// foo(
|
// foo(
|
||||||
ASSERT_EQUALS(true, tok->linkAt(6) == tok->tokAt(10));
|
ASSERT_EQUALS(true, tok->linkAt(6) == tok->tokAt(10));
|
||||||
|
@ -2877,7 +2880,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token *tok = tokenizer.tokens();
|
const Token *tok = tokenizer.tokens();
|
||||||
// template<
|
// template<
|
||||||
ASSERT_EQUALS(true, tok->tokAt(6) == tok->linkAt(4));
|
ASSERT_EQUALS(true, tok->tokAt(6) == tok->linkAt(4));
|
||||||
|
@ -2905,7 +2908,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token *tok = tokenizer.tokens();
|
const Token *tok = tokenizer.tokens();
|
||||||
|
|
||||||
// static_cast<
|
// static_cast<
|
||||||
|
@ -2922,7 +2925,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token *tok = tokenizer.tokens();
|
const Token *tok = tokenizer.tokens();
|
||||||
|
|
||||||
// nvwa<(x > y)>
|
// nvwa<(x > y)>
|
||||||
|
@ -2938,7 +2941,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token *tok = tokenizer.tokens();
|
const Token *tok = tokenizer.tokens();
|
||||||
|
|
||||||
// B<..>
|
// B<..>
|
||||||
|
@ -2954,7 +2957,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token *tok = tokenizer.tokens();
|
const Token *tok = tokenizer.tokens();
|
||||||
|
|
||||||
ASSERT_EQUALS(true, tok->tokAt(1) == tok->linkAt(18));
|
ASSERT_EQUALS(true, tok->tokAt(1) == tok->linkAt(18));
|
||||||
|
@ -2971,7 +2974,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token *tok = tokenizer.tokens();
|
const Token *tok = tokenizer.tokens();
|
||||||
|
|
||||||
ASSERT_EQUALS(true, tok->tokAt(2) == tok->linkAt(4));
|
ASSERT_EQUALS(true, tok->tokAt(2) == tok->linkAt(4));
|
||||||
|
@ -2987,7 +2990,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token *tok = tokenizer.tokens();
|
const Token *tok = tokenizer.tokens();
|
||||||
|
|
||||||
ASSERT_EQUALS(true, tok->tokAt(3) == tok->linkAt(9));
|
ASSERT_EQUALS(true, tok->tokAt(3) == tok->linkAt(9));
|
||||||
|
@ -3002,7 +3005,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token *tok = tokenizer.tokens();
|
const Token *tok = tokenizer.tokens();
|
||||||
|
|
||||||
ASSERT_EQUALS(true, tok->linkAt(3) == nullptr);
|
ASSERT_EQUALS(true, tok->linkAt(3) == nullptr);
|
||||||
|
@ -3014,7 +3017,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token *tok = tokenizer.tokens();
|
const Token *tok = tokenizer.tokens();
|
||||||
|
|
||||||
ASSERT_EQUALS(true, tok->linkAt(4) == nullptr);
|
ASSERT_EQUALS(true, tok->linkAt(4) == nullptr);
|
||||||
|
@ -3026,7 +3029,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token *tok = tokenizer.tokens();
|
const Token *tok = tokenizer.tokens();
|
||||||
|
|
||||||
ASSERT_EQUALS(true, tok->linkAt(1) == tok->tokAt(5));
|
ASSERT_EQUALS(true, tok->linkAt(1) == tok->tokAt(5));
|
||||||
|
@ -3038,7 +3041,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token *tok = tokenizer.tokens();
|
const Token *tok = tokenizer.tokens();
|
||||||
|
|
||||||
ASSERT_EQUALS(true, tok->linkAt(3) == nullptr);
|
ASSERT_EQUALS(true, tok->linkAt(3) == nullptr);
|
||||||
|
@ -3050,7 +3053,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token *tok = tokenizer.tokens();
|
const Token *tok = tokenizer.tokens();
|
||||||
ASSERT_EQUALS(true, tok->linkAt(1) == tok->tokAt(7));
|
ASSERT_EQUALS(true, tok->linkAt(1) == tok->tokAt(7));
|
||||||
}
|
}
|
||||||
|
@ -3061,7 +3064,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token *tok = tokenizer.tokens();
|
const Token *tok = tokenizer.tokens();
|
||||||
ASSERT_EQUALS(true, tok->linkAt(1) == tok->tokAt(7));
|
ASSERT_EQUALS(true, tok->linkAt(1) == tok->tokAt(7));
|
||||||
}
|
}
|
||||||
|
@ -3071,7 +3074,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token *tok = tokenizer.tokens();
|
const Token *tok = tokenizer.tokens();
|
||||||
ASSERT_EQUALS(true, tok->linkAt(1) == tok->tokAt(7));
|
ASSERT_EQUALS(true, tok->linkAt(1) == tok->tokAt(7));
|
||||||
ASSERT_EQUALS(true, tok->tokAt(1) == tok->linkAt(7));
|
ASSERT_EQUALS(true, tok->tokAt(1) == tok->linkAt(7));
|
||||||
|
@ -3082,7 +3085,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token *tok = tokenizer.tokens();
|
const Token *tok = tokenizer.tokens();
|
||||||
ASSERT_EQUALS(true, tok->linkAt(4) == tok->tokAt(8));
|
ASSERT_EQUALS(true, tok->linkAt(4) == tok->tokAt(8));
|
||||||
ASSERT_EQUALS(true, tok->tokAt(4) == tok->linkAt(8));
|
ASSERT_EQUALS(true, tok->tokAt(4) == tok->linkAt(8));
|
||||||
|
@ -3093,7 +3096,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token *tok = tokenizer.tokens();
|
const Token *tok = tokenizer.tokens();
|
||||||
ASSERT_EQUALS(true, tok->linkAt(1) == tok->tokAt(4));
|
ASSERT_EQUALS(true, tok->linkAt(1) == tok->tokAt(4));
|
||||||
ASSERT_EQUALS(true, tok->tokAt(1) == tok->linkAt(4));
|
ASSERT_EQUALS(true, tok->tokAt(1) == tok->linkAt(4));
|
||||||
|
@ -3105,7 +3108,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token *tok = tokenizer.tokens();
|
const Token *tok = tokenizer.tokens();
|
||||||
|
|
||||||
ASSERT_EQUALS(true, tok->linkAt(1) == tok->tokAt(4)); // <class R>
|
ASSERT_EQUALS(true, tok->linkAt(1) == tok->tokAt(4)); // <class R>
|
||||||
|
@ -3125,7 +3128,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token *tok = Token::findsimplematch(tokenizer.tokens(), "<");
|
const Token *tok = Token::findsimplematch(tokenizer.tokens(), "<");
|
||||||
ASSERT_EQUALS(true, tok->link() == tok->tokAt(4));
|
ASSERT_EQUALS(true, tok->link() == tok->tokAt(4));
|
||||||
ASSERT_EQUALS(true, tok->linkAt(4) == tok);
|
ASSERT_EQUALS(true, tok->linkAt(4) == tok);
|
||||||
|
@ -3139,7 +3142,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token *tok1 = Token::findsimplematch(tokenizer.tokens(), "struct")->tokAt(2);
|
const Token *tok1 = Token::findsimplematch(tokenizer.tokens(), "struct")->tokAt(2);
|
||||||
const Token *tok2 = Token::findsimplematch(tokenizer.tokens(), "{")->previous();
|
const Token *tok2 = Token::findsimplematch(tokenizer.tokens(), "{")->previous();
|
||||||
ASSERT_EQUALS(true, tok1->link() == tok2);
|
ASSERT_EQUALS(true, tok1->link() == tok2);
|
||||||
|
@ -3152,7 +3155,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token *tok1 = Token::findsimplematch(tokenizer.tokens(), "< Y");
|
const Token *tok1 = Token::findsimplematch(tokenizer.tokens(), "< Y");
|
||||||
const Token *tok2 = Token::findsimplematch(tok1, "> copy");
|
const Token *tok2 = Token::findsimplematch(tok1, "> copy");
|
||||||
ASSERT_EQUALS(true, tok1->link() == tok2);
|
ASSERT_EQUALS(true, tok1->link() == tok2);
|
||||||
|
@ -3165,7 +3168,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token *tok1 = tokenizer.tokens()->next();
|
const Token *tok1 = tokenizer.tokens()->next();
|
||||||
const Token *tok2 = tok1->tokAt(2);
|
const Token *tok2 = tok1->tokAt(2);
|
||||||
ASSERT_EQUALS(true, tok1->link() == tok2);
|
ASSERT_EQUALS(true, tok1->link() == tok2);
|
||||||
|
@ -3178,7 +3181,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token *tok1 = Token::findsimplematch(tokenizer.tokens(), "<");
|
const Token *tok1 = Token::findsimplematch(tokenizer.tokens(), "<");
|
||||||
const Token *tok2 = tok1->tokAt(2);
|
const Token *tok2 = tok1->tokAt(2);
|
||||||
ASSERT_EQUALS(true, tok1->link() == tok2);
|
ASSERT_EQUALS(true, tok1->link() == tok2);
|
||||||
|
@ -3191,7 +3194,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token *A = Token::findsimplematch(tokenizer.tokens(), "A <");
|
const Token *A = Token::findsimplematch(tokenizer.tokens(), "A <");
|
||||||
ASSERT_EQUALS(true, A->next()->link() == A->tokAt(3));
|
ASSERT_EQUALS(true, A->next()->link() == A->tokAt(3));
|
||||||
}
|
}
|
||||||
|
@ -3202,7 +3205,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
ASSERT_EQUALS(true, Token::simpleMatch(tokenizer.tokens()->next()->link(), "> void"));
|
ASSERT_EQUALS(true, Token::simpleMatch(tokenizer.tokens()->next()->link(), "> void"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3211,7 +3214,7 @@ private:
|
||||||
const char code[] = "a = f(x%x<--a==x>x);";
|
const char code[] = "a = f(x%x<--a==x>x);";
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
ASSERT(nullptr == Token::findsimplematch(tokenizer.tokens(), "<")->link());
|
ASSERT(nullptr == Token::findsimplematch(tokenizer.tokens(), "<")->link());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3220,7 +3223,7 @@ private:
|
||||||
const char code[] = "using std::list; list<t *> l;";
|
const char code[] = "using std::list; list<t *> l;";
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "<")->link());
|
ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "<")->link());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3232,7 +3235,7 @@ private:
|
||||||
"}";
|
"}";
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "<")->link());
|
ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "<")->link());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3244,7 +3247,7 @@ private:
|
||||||
"}\n";
|
"}\n";
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> ::")->link());
|
ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> ::")->link());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3256,7 +3259,7 @@ private:
|
||||||
"};\n";
|
"};\n";
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> [")->link());
|
ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> [")->link());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3269,7 +3272,7 @@ private:
|
||||||
"template <typename e> using baz = g<e>;\n";
|
"template <typename e> using baz = g<e>;\n";
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> ;")->link());
|
ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> ;")->link());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3284,7 +3287,7 @@ private:
|
||||||
"auto f = -e<1> == 0;\n";
|
"auto f = -e<1> == 0;\n";
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> ==")->link());
|
ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> ==")->link());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3303,7 +3306,7 @@ private:
|
||||||
"}\n";
|
"}\n";
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> . f (")->link());
|
ASSERT(nullptr != Token::findsimplematch(tokenizer.tokens(), "> . f (")->link());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3313,7 +3316,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token* tok1 = Token::findsimplematch(tokenizer.tokens(), "< class");
|
const Token* tok1 = Token::findsimplematch(tokenizer.tokens(), "< class");
|
||||||
const Token* tok2 = Token::findsimplematch(tok1, "> class");
|
const Token* tok2 = Token::findsimplematch(tok1, "> class");
|
||||||
ASSERT_EQUALS(true, tok1->link() == tok2);
|
ASSERT_EQUALS(true, tok1->link() == tok2);
|
||||||
|
@ -3326,7 +3329,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token* tok1 = Token::findsimplematch(tokenizer.tokens(), "< template");
|
const Token* tok1 = Token::findsimplematch(tokenizer.tokens(), "< template");
|
||||||
const Token* tok2 = Token::findsimplematch(tok1, "> struct");
|
const Token* tok2 = Token::findsimplematch(tok1, "> struct");
|
||||||
ASSERT_EQUALS(true, tok1->link() == tok2);
|
ASSERT_EQUALS(true, tok1->link() == tok2);
|
||||||
|
@ -3563,7 +3566,7 @@ private:
|
||||||
// tokenize..
|
// tokenize..
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
|
|
||||||
// Expected result..
|
// Expected result..
|
||||||
ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false));
|
ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false));
|
||||||
|
@ -3590,7 +3593,7 @@ private:
|
||||||
// tokenize..
|
// tokenize..
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false));
|
ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false));
|
||||||
|
|
||||||
const Token * VAS_Fail = Token::findsimplematch(tokenizer.tokens(), "VAS_Fail");
|
const Token * VAS_Fail = Token::findsimplematch(tokenizer.tokens(), "VAS_Fail");
|
||||||
|
@ -3610,7 +3613,7 @@ private:
|
||||||
// tokenize..
|
// tokenize..
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
|
|
||||||
// Expected result..
|
// Expected result..
|
||||||
ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false));
|
ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false));
|
||||||
|
@ -3645,7 +3648,7 @@ private:
|
||||||
// tokenize..
|
// tokenize..
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
|
|
||||||
// Expected result..
|
// Expected result..
|
||||||
ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false));
|
ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false));
|
||||||
|
@ -3686,7 +3689,7 @@ private:
|
||||||
// tokenize..
|
// tokenize..
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
|
|
||||||
// Expected result..
|
// Expected result..
|
||||||
ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false));
|
ASSERT_EQUALS(expected, tokenizer.tokens()->stringifyList(nullptr, false));
|
||||||
|
@ -4331,7 +4334,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
const Token *x = Token::findsimplematch(tokenizer.tokens(), "x");
|
const Token *x = Token::findsimplematch(tokenizer.tokens(), "x");
|
||||||
ASSERT_EQUALS(1, x->bits());
|
ASSERT_EQUALS(1, x->bits());
|
||||||
}
|
}
|
||||||
|
@ -6366,10 +6369,11 @@ private:
|
||||||
tokenizeAndStringify(code.c_str()); // just survive...
|
tokenizeAndStringify(code.c_str()); // just survive...
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isStartOfExecutableScope(int offset, const char code[]) {
|
#define isStartOfExecutableScope(offset, code) isStartOfExecutableScope_(offset, code, __FILE__, __LINE__)
|
||||||
|
bool isStartOfExecutableScope_(int offset, const char code[], const char* file, int line) {
|
||||||
Tokenizer tokenizer(&settings0, this);
|
Tokenizer tokenizer(&settings0, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
return Tokenizer::startOfExecutableScope(tokenizer.tokens()->tokAt(offset)) != nullptr;
|
return Tokenizer::startOfExecutableScope(tokenizer.tokens()->tokAt(offset)) != nullptr;
|
||||||
}
|
}
|
||||||
|
@ -6906,7 +6910,7 @@ private:
|
||||||
// tokenize..
|
// tokenize..
|
||||||
Tokenizer tokenizer(&s, this);
|
Tokenizer tokenizer(&s, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkConfiguration() {
|
void checkConfiguration() {
|
||||||
|
@ -6930,7 +6934,7 @@ private:
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
|
|
||||||
tokenizer.printUnknownTypes();
|
tokenizer.printUnknownTypes();
|
||||||
|
|
||||||
|
@ -6950,7 +6954,7 @@ private:
|
||||||
Settings settings;
|
Settings settings;
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
|
||||||
|
|
||||||
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
||||||
ASSERT_EQUALS(tok->str() == "(", tok->isCast());
|
ASSERT_EQUALS(tok->str() == "(", tok->isCast());
|
||||||
|
|
|
@ -104,7 +104,7 @@ private:
|
||||||
Settings settings;
|
Settings settings;
|
||||||
Tokenizer tokenizer{ &settings, nullptr };
|
Tokenizer tokenizer{ &settings, nullptr };
|
||||||
std::istringstream sample("void a(){} void main(){ if(true){a();} }");
|
std::istringstream sample("void a(){} void main(){ if(true){a();} }");
|
||||||
tokenizer.tokenize(sample, "test.cpp");
|
ASSERT(tokenizer.tokenize(sample, "test.cpp"));
|
||||||
|
|
||||||
const SymbolDatabase* sd = tokenizer.getSymbolDatabase();
|
const SymbolDatabase* sd = tokenizer.getSymbolDatabase();
|
||||||
const Scope& scope = *std::next(sd->scopeList.begin(), 3); //The scope of the if block
|
const Scope& scope = *std::next(sd->scopeList.begin(), 3); //The scope of the if block
|
||||||
|
|
|
@ -40,7 +40,8 @@ private:
|
||||||
TEST_CASE(checkFloatToIntegerOverflow);
|
TEST_CASE(checkFloatToIntegerOverflow);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const char code[], Settings* settings = nullptr, const char filename[] = "test.cpp", const std::string& standard = "c++11") {
|
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
void check_(const char* file, int line, const char code[], Settings* settings = nullptr, const char filename[] = "test.cpp", const std::string& standard = "c++11") {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -55,7 +56,7 @@ private:
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(settings, this);
|
Tokenizer tokenizer(settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, filename);
|
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);
|
||||||
|
|
||||||
// Check..
|
// Check..
|
||||||
CheckType checkType(&tokenizer, settings, this);
|
CheckType checkType(&tokenizer, settings, this);
|
||||||
|
|
|
@ -86,7 +86,7 @@ private:
|
||||||
TEST_CASE(trac_4871);
|
TEST_CASE(trac_4871);
|
||||||
TEST_CASE(syntax_error); // Ticket #5073
|
TEST_CASE(syntax_error); // Ticket #5073
|
||||||
TEST_CASE(trac_5970);
|
TEST_CASE(trac_5970);
|
||||||
TEST_CASE(valueFlowUninit);
|
TEST_CASE(valueFlowUninitTest);
|
||||||
TEST_CASE(valueFlowUninitBreak);
|
TEST_CASE(valueFlowUninitBreak);
|
||||||
TEST_CASE(valueFlowUninitStructMembers);
|
TEST_CASE(valueFlowUninitStructMembers);
|
||||||
TEST_CASE(uninitvar_ipa);
|
TEST_CASE(uninitvar_ipa);
|
||||||
|
@ -96,10 +96,11 @@ private:
|
||||||
TEST_CASE(isVariableUsageDeref); // *p
|
TEST_CASE(isVariableUsageDeref); // *p
|
||||||
|
|
||||||
// whole program analysis
|
// whole program analysis
|
||||||
TEST_CASE(ctu);
|
TEST_CASE(ctuTest);
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkUninitVar(const char code[], const char fname[] = "test.cpp", bool debugwarnings = false) {
|
#define checkUninitVar(...) checkUninitVar_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
void checkUninitVar_(const char* file, int line, const char code[], const char fname[] = "test.cpp", bool debugwarnings = false) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -107,7 +108,7 @@ private:
|
||||||
settings.debugwarnings = debugwarnings;
|
settings.debugwarnings = debugwarnings;
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, fname);
|
ASSERT_LOC(tokenizer.tokenize(istr, fname), file, line);
|
||||||
|
|
||||||
// Check for redundant code..
|
// Check for redundant code..
|
||||||
CheckUninitVar checkuninitvar(&tokenizer, &settings, this);
|
CheckUninitVar checkuninitvar(&tokenizer, &settings, this);
|
||||||
|
@ -3397,6 +3398,7 @@ private:
|
||||||
TODO_ASSERT_EQUALS("error", "", errout.str());
|
TODO_ASSERT_EQUALS("error", "", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define valueFlowUninit(...) valueFlowUninit_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
void valueFlowUninit2_value()
|
void valueFlowUninit2_value()
|
||||||
{
|
{
|
||||||
valueFlowUninit("void f() {\n"
|
valueFlowUninit("void f() {\n"
|
||||||
|
@ -4504,7 +4506,7 @@ private:
|
||||||
// FP Unknown type ASSERT_EQUALS("", errout.str());
|
// FP Unknown type ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void valueFlowUninit(const char code[], const char fname[] = "test.cpp")
|
void valueFlowUninit_(const char* file, int line, const char code[], const char fname[] = "test.cpp")
|
||||||
{
|
{
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
@ -4515,14 +4517,15 @@ private:
|
||||||
|
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, fname);
|
ASSERT_LOC(tokenizer.tokenize(istr, fname), file, line);
|
||||||
|
|
||||||
// Check for redundant code..
|
// Check for redundant code..
|
||||||
CheckUninitVar checkuninitvar(&tokenizer, &settings, this);
|
CheckUninitVar checkuninitvar(&tokenizer, &settings, this);
|
||||||
checkuninitvar.valueFlowUninit();
|
(checkuninitvar.valueFlowUninit)();
|
||||||
}
|
}
|
||||||
|
|
||||||
void valueFlowUninit() {
|
#define ctu(code) ctu_(__FILE__, __LINE__, code)
|
||||||
|
void valueFlowUninitTest() {
|
||||||
// #9735 - FN
|
// #9735 - FN
|
||||||
valueFlowUninit("typedef struct\n"
|
valueFlowUninit("typedef struct\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -5960,14 +5963,14 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ctu(const char code[]) {
|
void ctu_(const char* file, int line, const char code[]) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
CTU::FileInfo *ctu = CTU::getFileInfo(&tokenizer);
|
CTU::FileInfo *ctu = CTU::getFileInfo(&tokenizer);
|
||||||
|
|
||||||
|
@ -5983,7 +5986,7 @@ private:
|
||||||
delete ctu;
|
delete ctu;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ctu() {
|
void ctuTest() {
|
||||||
ctu("void f(int *p) {\n"
|
ctu("void f(int *p) {\n"
|
||||||
" a = *p;\n"
|
" a = *p;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
|
|
|
@ -68,7 +68,8 @@ private:
|
||||||
TEST_CASE(operatorOverload);
|
TEST_CASE(operatorOverload);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const char code[], Settings::PlatformType platform = Settings::Native) {
|
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
void check_(const char* file, int line, const char code[], Settings::PlatformType platform = Settings::Native) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -77,13 +78,13 @@ private:
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check for unused functions..
|
// Check for unused functions..
|
||||||
CheckUnusedFunctions checkUnusedFunctions(&tokenizer, &settings, this);
|
CheckUnusedFunctions checkUnusedFunctions(&tokenizer, &settings, this);
|
||||||
checkUnusedFunctions.parseTokens(tokenizer, "someFile.c", &settings);
|
checkUnusedFunctions.parseTokens(tokenizer, "someFile.c", &settings);
|
||||||
// check() returns error if and only if errout is not empty.
|
// check() returns error if and only if errout is not empty.
|
||||||
if (checkUnusedFunctions.check(this, settings)) {
|
if ((checkUnusedFunctions.check)(this, settings)) {
|
||||||
ASSERT(errout.str() != "");
|
ASSERT(errout.str() != "");
|
||||||
} else {
|
} else {
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
@ -439,13 +440,13 @@ private:
|
||||||
|
|
||||||
Tokenizer tokenizer2(&settings, this);
|
Tokenizer tokenizer2(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer2.tokenize(istr, fname.str().c_str());
|
ASSERT(tokenizer2.tokenize(istr, fname.str().c_str()));
|
||||||
|
|
||||||
c.parseTokens(tokenizer2, "someFile.c", &settings);
|
c.parseTokens(tokenizer2, "someFile.c", &settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for unused functions..
|
// Check for unused functions..
|
||||||
c.check(this, settings);
|
(c.check)(this, settings);
|
||||||
|
|
||||||
ASSERT_EQUALS("[test1.cpp:1]: (style) The function 'f' is never used.\n", errout.str());
|
ASSERT_EQUALS("[test1.cpp:1]: (style) The function 'f' is never used.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,7 +226,9 @@ private:
|
||||||
TEST_CASE(globalData);
|
TEST_CASE(globalData);
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkStructMemberUsage(const char code[], const std::list<Directive> *directives=nullptr) {
|
#define functionVariableUsage(...) functionVariableUsage_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
#define checkStructMemberUsage(...) checkStructMemberUsage_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
void checkStructMemberUsage_(const char* file, int line, const char code[], const std::list<Directive>* directives = nullptr) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -238,11 +240,11 @@ private:
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
tokenizer.setPreprocessor(&preprocessor);
|
tokenizer.setPreprocessor(&preprocessor);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check for unused variables..
|
// Check for unused variables..
|
||||||
CheckUnusedVar checkUnusedVar(&tokenizer, &settings, this);
|
CheckUnusedVar checkUnusedVar(&tokenizer, &settings, this);
|
||||||
checkUnusedVar.checkStructMemberUsage();
|
(checkUnusedVar.checkStructMemberUsage)();
|
||||||
}
|
}
|
||||||
|
|
||||||
void isRecordTypeWithoutSideEffects() {
|
void isRecordTypeWithoutSideEffects() {
|
||||||
|
@ -1572,15 +1574,14 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (style) struct member 'S::E' is never used.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (style) struct member 'S::E' is never used.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void functionVariableUsage(const char code[], const char filename[]="test.cpp") {
|
void functionVariableUsage_(const char* file, int line, const char code[], const char filename[] = "test.cpp") {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
if (!tokenizer.tokenize(istr, filename))
|
ASSERT_LOC(tokenizer.tokenize(istr, filename), file, line);
|
||||||
return;
|
|
||||||
|
|
||||||
// Check for unused variables..
|
// Check for unused variables..
|
||||||
CheckUnusedVar checkUnusedVar(&tokenizer, &settings, this);
|
CheckUnusedVar checkUnusedVar(&tokenizer, &settings, this);
|
||||||
|
|
|
@ -30,14 +30,15 @@ public:
|
||||||
private:
|
private:
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
|
||||||
void check(const char code[]) {
|
#define check(code) check_(code, __FILE__, __LINE__)
|
||||||
|
void check_(const char code[], const char* file, int line) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
// Check..
|
// Check..
|
||||||
CheckVaarg checkVaarg;
|
CheckVaarg checkVaarg;
|
||||||
|
|
|
@ -178,11 +178,12 @@ private:
|
||||||
return !val.isImpossible();
|
return !val.isImpossible();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool testValueOfXKnown(const char code[], unsigned int linenr, int value) {
|
#define testValueOfXKnown(...) testValueOfXKnown_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
bool testValueOfXKnown_(const char* file, int line, const char code[], unsigned int linenr, int value) {
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
||||||
if (tok->str() == "x" && tok->linenr() == linenr) {
|
if (tok->str() == "x" && tok->linenr() == linenr) {
|
||||||
|
@ -198,11 +199,11 @@ private:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool testValueOfXKnown(const char code[], unsigned int linenr, const std::string& expr, int value) {
|
bool testValueOfXKnown_(const char* file, int line, const char code[], unsigned int linenr, const std::string& expr, int value) {
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
for (const Token* tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
for (const Token* tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
||||||
if (tok->str() == "x" && tok->linenr() == linenr) {
|
if (tok->str() == "x" && tok->linenr() == linenr) {
|
||||||
|
@ -218,11 +219,12 @@ private:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool testValueOfXImpossible(const char code[], unsigned int linenr, int value) {
|
#define testValueOfXImpossible(...) testValueOfXImpossible_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
bool testValueOfXImpossible_(const char* file, int line, const char code[], unsigned int linenr, int value) {
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
||||||
if (tok->str() == "x" && tok->linenr() == linenr) {
|
if (tok->str() == "x" && tok->linenr() == linenr) {
|
||||||
|
@ -238,12 +240,12 @@ private:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool testValueOfXImpossible(const char code[], unsigned int linenr, const std::string& expr, int value)
|
bool testValueOfXImpossible_(const char* file, int line, const char code[], unsigned int linenr, const std::string& expr, int value)
|
||||||
{
|
{
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
for (const Token* tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
for (const Token* tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
||||||
if (tok->str() == "x" && tok->linenr() == linenr) {
|
if (tok->str() == "x" && tok->linenr() == linenr) {
|
||||||
|
@ -259,11 +261,12 @@ private:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool testValueOfXInconclusive(const char code[], unsigned int linenr, int value) {
|
#define testValueOfXInconclusive(code, linenr, value) testValueOfXInconclusive_(code, linenr, value, __FILE__, __LINE__)
|
||||||
|
bool testValueOfXInconclusive_(const char code[], unsigned int linenr, int value, const char* file, int line) {
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
||||||
if (tok->str() == "x" && tok->linenr() == linenr) {
|
if (tok->str() == "x" && tok->linenr() == linenr) {
|
||||||
|
@ -279,11 +282,12 @@ private:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool testValueOfX(const char code[], unsigned int linenr, int value) {
|
#define testValueOfX(...) testValueOfX_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
bool testValueOfX_(const char* file, int line, const char code[], unsigned int linenr, int value) {
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
||||||
if (tok->str() == "x" && tok->linenr() == linenr) {
|
if (tok->str() == "x" && tok->linenr() == linenr) {
|
||||||
|
@ -297,12 +301,12 @@ private:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool testValueOfX(const char code[], unsigned int linenr, const std::string& expr, int value)
|
bool testValueOfX_(const char* file, int line, const char code[], unsigned int linenr, const std::string& expr, int value)
|
||||||
{
|
{
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
for (const Token* tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
for (const Token* tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
||||||
if (tok->str() == "x" && tok->linenr() == linenr) {
|
if (tok->str() == "x" && tok->linenr() == linenr) {
|
||||||
|
@ -317,11 +321,11 @@ private:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool testValueOfX(const char code[], unsigned int linenr, float value, float diff) {
|
bool testValueOfX_(const char* file, int line, const char code[], unsigned int linenr, float value, float diff) {
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
||||||
if (tok->str() == "x" && tok->linenr() == linenr) {
|
if (tok->str() == "x" && tok->linenr() == linenr) {
|
||||||
|
@ -336,11 +340,12 @@ private:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getErrorPathForX(const char code[], unsigned int linenr) {
|
#define getErrorPathForX(code, linenr) getErrorPathForX_(code, linenr, __FILE__, __LINE__)
|
||||||
|
std::string getErrorPathForX_(const char code[], unsigned int linenr, const char* file, int line) {
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
||||||
if (tok->str() != "x" || tok->linenr() != linenr)
|
if (tok->str() != "x" || tok->linenr() != linenr)
|
||||||
|
@ -360,11 +365,11 @@ private:
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool testValueOfX(const char code[], unsigned int linenr, const char value[], ValueFlow::Value::ValueType type) {
|
bool testValueOfX_(const char* file, int line, const char code[], unsigned int linenr, const char value[], ValueFlow::Value::ValueType type) {
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
||||||
if (tok->str() == "x" && tok->linenr() == linenr) {
|
if (tok->str() == "x" && tok->linenr() == linenr) {
|
||||||
|
@ -378,11 +383,12 @@ private:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool testLifetimeOfX(const char code[], unsigned int linenr, const char value[], ValueFlow::Value::LifetimeScope lifetimeScope = ValueFlow::Value::LifetimeScope::Local) {
|
#define testLifetimeOfX(...) testLifetimeOfX_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
bool testLifetimeOfX_(const char* file, int line, const char code[], unsigned int linenr, const char value[], ValueFlow::Value::LifetimeScope lifetimeScope = ValueFlow::Value::LifetimeScope::Local) {
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
||||||
if (tok->str() == "x" && tok->linenr() == linenr) {
|
if (tok->str() == "x" && tok->linenr() == linenr) {
|
||||||
|
@ -396,11 +402,11 @@ private:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool testValueOfX(const char code[], unsigned int linenr, int value, ValueFlow::Value::ValueType type) {
|
bool testValueOfX_(const char* file, int line, const char code[], unsigned int linenr, int value, ValueFlow::Value::ValueType type) {
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
||||||
if (tok->str() == "x" && tok->linenr() == linenr) {
|
if (tok->str() == "x" && tok->linenr() == linenr) {
|
||||||
|
@ -414,11 +420,11 @@ private:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool testValueOfX(const char code[], unsigned int linenr, ValueFlow::Value::MoveKind moveKind) {
|
bool testValueOfX_(const char* file, int line, const char code[], unsigned int linenr, ValueFlow::Value::MoveKind moveKind) {
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
||||||
if (tok->str() == "x" && tok->linenr() == linenr) {
|
if (tok->str() == "x" && tok->linenr() == linenr) {
|
||||||
|
@ -432,11 +438,12 @@ private:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool testConditionalValueOfX(const char code[], unsigned int linenr, int value) {
|
#define testConditionalValueOfX(code, linenr, value) testConditionalValueOfX_(code, linenr, value, __FILE__, __LINE__)
|
||||||
|
bool testConditionalValueOfX_(const char code[], unsigned int linenr, int value, const char* file, int line) {
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
|
|
||||||
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
||||||
if (tok->str() == "x" && tok->linenr() == linenr) {
|
if (tok->str() == "x" && tok->linenr() == linenr) {
|
||||||
|
@ -470,29 +477,31 @@ private:
|
||||||
settings.debugwarnings = false;
|
settings.debugwarnings = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<ValueFlow::Value> tokenValues(const char code[], const char tokstr[], const Settings *s = nullptr) {
|
#define tokenValues(...) tokenValues_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
std::list<ValueFlow::Value> tokenValues_(const char* file, int line, const char code[], const char tokstr[], const Settings *s = nullptr) {
|
||||||
Tokenizer tokenizer(s ? s : &settings, this);
|
Tokenizer tokenizer(s ? s : &settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
errout.str("");
|
errout.str("");
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
const Token *tok = Token::findmatch(tokenizer.tokens(), tokstr);
|
const Token *tok = Token::findmatch(tokenizer.tokens(), tokstr);
|
||||||
return tok ? tok->values() : std::list<ValueFlow::Value>();
|
return tok ? tok->values() : std::list<ValueFlow::Value>();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<ValueFlow::Value> tokenValues(const char code[], const char tokstr[], ValueFlow::Value::ValueType vt, const Settings *s = nullptr) {
|
std::list<ValueFlow::Value> tokenValues_(const char* file, int line, const char code[], const char tokstr[], ValueFlow::Value::ValueType vt, const Settings *s = nullptr) {
|
||||||
std::list<ValueFlow::Value> values = tokenValues(code, tokstr, s);
|
std::list<ValueFlow::Value> values = tokenValues_(file, line, code, tokstr, s);
|
||||||
values.remove_if([&](const ValueFlow::Value& v) {
|
values.remove_if([&](const ValueFlow::Value& v) {
|
||||||
return v.valueType != vt;
|
return v.valueType != vt;
|
||||||
});
|
});
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> lifetimeValues(const char code[], const char tokstr[], const Settings *s = nullptr) {
|
#define lifetimeValues(...) lifetimeValues_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
std::vector<std::string> lifetimeValues_(const char* file, int line, const char code[], const char tokstr[], const Settings *s = nullptr) {
|
||||||
std::vector<std::string> result;
|
std::vector<std::string> result;
|
||||||
Tokenizer tokenizer(s ? s : &settings, this);
|
Tokenizer tokenizer(s ? s : &settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
errout.str("");
|
errout.str("");
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
||||||
const Token *tok = Token::findmatch(tokenizer.tokens(), tokstr);
|
const Token *tok = Token::findmatch(tokenizer.tokens(), tokstr);
|
||||||
if (!tok)
|
if (!tok)
|
||||||
return result;
|
return result;
|
||||||
|
@ -506,8 +515,9 @@ private:
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ValueFlow::Value valueOfTok(const char code[], const char tokstr[]) {
|
#define valueOfTok(code, tokstr) valueOfTok_(code, tokstr, __FILE__, __LINE__)
|
||||||
std::list<ValueFlow::Value> values = tokenValues(code, tokstr);
|
ValueFlow::Value valueOfTok_(const char code[], const char tokstr[], const char* file, int line) {
|
||||||
|
std::list<ValueFlow::Value> values = tokenValues_(file, line, code, tokstr);
|
||||||
return values.size() == 1U && !values.front().isTokValue() ? values.front() : ValueFlow::Value();
|
return values.size() == 1U && !values.front().isTokValue() ? values.front() : ValueFlow::Value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -219,7 +219,8 @@ private:
|
||||||
TEST_CASE(structuredBindings);
|
TEST_CASE(structuredBindings);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string tokenize(const char code[], const char filename[] = "test.cpp") {
|
#define tokenize(...) tokenize_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
std::string tokenize_(const char* file, int line, const char code[], const char filename[] = "test.cpp") {
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
@ -230,7 +231,7 @@ private:
|
||||||
|
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, filename);
|
ASSERT_LOC((tokenizer.tokenize)(istr, filename), file, line);
|
||||||
|
|
||||||
// result..
|
// result..
|
||||||
Token::stringifyOptions options = Token::stringifyOptions::forDebugVarId();
|
Token::stringifyOptions options = Token::stringifyOptions::forDebugVarId();
|
||||||
|
@ -238,7 +239,8 @@ private:
|
||||||
return tokenizer.tokens()->stringifyList(options);
|
return tokenizer.tokens()->stringifyList(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string tokenizeExpr(const char code[], const char filename[] = "test.cpp") {
|
#define tokenizeExpr(...) tokenizeExpr_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
std::string tokenizeExpr_(const char* file, int line, const char code[], const char filename[] = "test.cpp") {
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
@ -249,7 +251,7 @@ private:
|
||||||
|
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, filename);
|
ASSERT_LOC((tokenizer.tokenize)(istr, filename), file, line);
|
||||||
|
|
||||||
// result..
|
// result..
|
||||||
Token::stringifyOptions options = Token::stringifyOptions::forDebugExprId();
|
Token::stringifyOptions options = Token::stringifyOptions::forDebugExprId();
|
||||||
|
@ -257,7 +259,8 @@ private:
|
||||||
return tokenizer.tokens()->stringifyList(options);
|
return tokenizer.tokens()->stringifyList(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string compareVaridsForVariable(const char code[], const char varname[], const char filename[] = "test.cpp") {
|
#define compareVaridsForVariable(...) compareVaridsForVariable_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
std::string compareVaridsForVariable_(const char* file, int line, const char code[], const char varname[], const char filename[] = "test.cpp") {
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
@ -268,7 +271,7 @@ private:
|
||||||
|
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, filename);
|
ASSERT_LOC((tokenizer.tokenize)(istr, filename), file, line);
|
||||||
|
|
||||||
unsigned int varid = ~0U;
|
unsigned int varid = ~0U;
|
||||||
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
|
||||||
|
|
Loading…
Reference in New Issue