Treat syntaxError and cppcheckError as InternalErrors (throw as exception, #4268)
This commit is contained in:
parent
b23aebf2f0
commit
7e4081f7f5
|
@ -399,22 +399,22 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
|||
return;
|
||||
} catch (const InternalError &e) {
|
||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
||||
ErrorLogger::ErrorMessage::FileLocation loc2;
|
||||
loc2.setfile(Path::toNativeSeparators(FileName));
|
||||
locationList.push_back(loc2);
|
||||
ErrorLogger::ErrorMessage::FileLocation loc;
|
||||
if (e.token) {
|
||||
loc.line = e.token->linenr();
|
||||
const std::string fixedpath = Path::toNativeSeparators(_tokenizer.list.file(e.token));
|
||||
loc.setfile(fixedpath);
|
||||
} else {
|
||||
ErrorLogger::ErrorMessage::FileLocation loc2;
|
||||
loc2.setfile(Path::toNativeSeparators(FileName));
|
||||
locationList.push_back(loc2);
|
||||
loc.setfile(_tokenizer.getSourceFilePath());
|
||||
}
|
||||
locationList.push_back(loc);
|
||||
const ErrorLogger::ErrorMessage errmsg(locationList,
|
||||
Severity::error,
|
||||
e.errorMessage,
|
||||
"cppcheckError",
|
||||
e.id,
|
||||
false);
|
||||
|
||||
_errorLogger.reportErr(errmsg);
|
||||
|
|
|
@ -28,9 +28,17 @@
|
|||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
InternalError::InternalError(const Token *tok, const std::string &errorMsg) :
|
||||
InternalError::InternalError(const Token *tok, const std::string &errorMsg, Type type) :
|
||||
token(tok), errorMessage(errorMsg)
|
||||
{
|
||||
switch (type) {
|
||||
case SYNTAX:
|
||||
id = "syntaxError";
|
||||
break;
|
||||
case INTERNAL:
|
||||
id = "cppcheckError";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ErrorLogger::ErrorMessage::ErrorMessage()
|
||||
|
|
|
@ -35,9 +35,11 @@ class TokenList;
|
|||
|
||||
/** @brief Simple container to be thrown when internal error is detected. */
|
||||
struct InternalError {
|
||||
InternalError(const Token *tok, const std::string &errorMsg);
|
||||
enum Type {SYNTAX, INTERNAL};
|
||||
InternalError(const Token *tok, const std::string &errorMsg, Type type = INTERNAL);
|
||||
const Token *token;
|
||||
std::string errorMessage;
|
||||
std::string id;
|
||||
};
|
||||
|
||||
/** @brief enum class for severity. Used when reporting errors. */
|
||||
|
|
|
@ -8158,14 +8158,15 @@ void Tokenizer::eraseDeadCode(Token *begin, const Token *end)
|
|||
|
||||
void Tokenizer::syntaxError(const Token *tok) const
|
||||
{
|
||||
reportError(tok, Severity::error, "syntaxError", "syntax error");
|
||||
throw InternalError(tok, "syntax error", InternalError::SYNTAX);
|
||||
}
|
||||
|
||||
void Tokenizer::syntaxError(const Token *tok, char c) const
|
||||
{
|
||||
reportError(tok, Severity::error, "syntaxError",
|
||||
std::string("Invalid number of character (") + c + ") " +
|
||||
"when these macros are defined: '" + _configuration + "'.");
|
||||
throw InternalError(tok,
|
||||
std::string("Invalid number of character (") + c + ") " +
|
||||
"when these macros are defined: '" + _configuration + "'.",
|
||||
InternalError::SYNTAX);
|
||||
}
|
||||
|
||||
void Tokenizer::unhandled_macro_class_x_y(const Token *tok) const
|
||||
|
@ -8182,8 +8183,7 @@ void Tokenizer::unhandled_macro_class_x_y(const Token *tok) const
|
|||
|
||||
void Tokenizer::cppcheckError(const Token *tok) const
|
||||
{
|
||||
reportError(tok, Severity::error, "cppcheckError",
|
||||
"Analysis failed. If the code is valid then please report this failure.");
|
||||
throw InternalError(tok, "Analysis failed. If the code is valid then please report this failure.", InternalError::INTERNAL);
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
// Helper function to check wether number is zero (0 or 0.0 or 0E+0) or not?
|
||||
|
@ -8828,8 +8828,6 @@ void Tokenizer::simplifyConst()
|
|||
void Tokenizer::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings)
|
||||
{
|
||||
Tokenizer t(settings, errorLogger);
|
||||
t.syntaxError(0, ' ');
|
||||
t.cppcheckError(0);
|
||||
t.duplicateTypedefError(0, 0, "variable");
|
||||
t.duplicateDeclarationError(0, 0, "variable");
|
||||
t.duplicateEnumError(0, 0, "variable");
|
||||
|
|
|
@ -563,11 +563,11 @@ private:
|
|||
ASSERT_EQUALS(";;alloc;;", getcode("char *s; s = new char[10]; memcpy(s,a);", "s", true));
|
||||
|
||||
// #2112 - Segmentation fault in the getcode function
|
||||
getcode("page *one = foo();\n"
|
||||
"ASSERT(one, return 0)\n"
|
||||
"const int two = rand();\n"
|
||||
"return 0;\n"
|
||||
"}", "one");
|
||||
ASSERT_THROW(getcode("page *one = foo();\n"
|
||||
"ASSERT(one, return 0)\n"
|
||||
"const int two = rand();\n"
|
||||
"return 0;\n"
|
||||
"}", "one"), InternalError);
|
||||
|
||||
// ticket #2336: calling member function with same name as a white_list function
|
||||
ASSERT_EQUALS(";;use;", getcode("char *s; foo.write(s);", "s"));
|
||||
|
@ -1407,14 +1407,13 @@ private:
|
|||
|
||||
void switch4() {
|
||||
// See tickets #2518 #2555 #4171
|
||||
check("void f() {\n"
|
||||
" switch MAKEWORD(1)\n"
|
||||
" {\n"
|
||||
" case 0:\n"
|
||||
" return;\n"
|
||||
" }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(check("void f() {\n"
|
||||
" switch MAKEWORD(1)\n"
|
||||
" {\n"
|
||||
" case 0:\n"
|
||||
" return;\n"
|
||||
" }\n"
|
||||
"}"), InternalError);
|
||||
}
|
||||
|
||||
void ret5() {
|
||||
|
@ -4224,9 +4223,9 @@ private:
|
|||
}
|
||||
|
||||
void garbageCode() {
|
||||
check("void h(int l) {\n"
|
||||
" while\n" // Don't crash (#3870)
|
||||
"}");
|
||||
ASSERT_THROW(check("void h(int l) {\n"
|
||||
" while\n" // Don't crash (#3870)
|
||||
"}"), InternalError);
|
||||
}
|
||||
|
||||
void ptrptr() {
|
||||
|
|
|
@ -2383,9 +2383,9 @@ private:
|
|||
|
||||
|
||||
void crash1() {
|
||||
check("int f() {\n"
|
||||
" return if\n"
|
||||
"}");
|
||||
ASSERT_THROW(check("int f() {\n"
|
||||
" return if\n"
|
||||
"}"), InternalError);
|
||||
}
|
||||
|
||||
void nullpointer_internal_error() { // ticket #5080
|
||||
|
|
|
@ -2362,7 +2362,7 @@ private:
|
|||
" return sizeof...(args);\n"
|
||||
" }();\n"
|
||||
"}";
|
||||
tok(code);
|
||||
ASSERT_THROW(tok(code), InternalError);
|
||||
}
|
||||
|
||||
void template43() { // #5097 - Assert due to '>>' in 'B<A<C>>' not being treated as end of template instantation
|
||||
|
@ -5298,8 +5298,7 @@ private:
|
|||
}
|
||||
|
||||
void simplifyTypedef81() { // ticket #2603 segmentation fault
|
||||
checkSimplifyTypedef("typedef\n");
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(checkSimplifyTypedef("typedef\n"), InternalError);
|
||||
|
||||
checkSimplifyTypedef("typedef constexpr\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
@ -5334,16 +5333,13 @@ private:
|
|||
|
||||
void simplifyTypedef84() { // ticket #2630 (segmentation fault)
|
||||
const char code1[] = "typedef y x () x\n";
|
||||
checkSimplifyTypedef(code1);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(checkSimplifyTypedef(code1), InternalError);
|
||||
|
||||
const char code2[] = "typedef struct template <>\n";
|
||||
checkSimplifyTypedef(code2);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(checkSimplifyTypedef(code2), InternalError);
|
||||
|
||||
const char code3[] = "typedef ::<>\n";
|
||||
checkSimplifyTypedef(code3);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(checkSimplifyTypedef(code3), InternalError);
|
||||
}
|
||||
|
||||
void simplifyTypedef85() { // ticket #2651
|
||||
|
@ -5604,8 +5600,7 @@ private:
|
|||
|
||||
void simplifyTypedef96() { // ticket #2886 (segmentation fault)
|
||||
const char code[] = "typedef struct x { }\n";
|
||||
tok(code);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(tok(code), InternalError);
|
||||
}
|
||||
|
||||
void simplifyTypedef97() { // ticket #2983 (segmentation fault)
|
||||
|
@ -5649,8 +5644,7 @@ private:
|
|||
void simplifyTypedef101() { // ticket #3003 (segmentation fault)
|
||||
const char code[] = "typedef a x[];\n"
|
||||
"y = x\n";
|
||||
tok(code);
|
||||
ASSERT_EQUALS("[test.cpp:2]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(tok(code), InternalError);
|
||||
}
|
||||
|
||||
void simplifyTypedef102() { // ticket #3004
|
||||
|
@ -5693,8 +5687,7 @@ private:
|
|||
|
||||
void simplifyTypedef107() { // ticket #3963 (bad code => segmentation fault)
|
||||
const char code[] = "typedef int x[]; int main() { return x }";
|
||||
tok(code);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(tok(code), InternalError);
|
||||
}
|
||||
|
||||
void simplifyTypedefFunction1() {
|
||||
|
@ -6947,8 +6940,7 @@ private:
|
|||
|
||||
void enum16() { // ticket #1988
|
||||
const char code[] = "enum D : auto * { FF = 0 };";
|
||||
checkSimplifyEnum(code);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(checkSimplifyEnum(code), InternalError);
|
||||
}
|
||||
|
||||
void enum17() { // ticket #2381
|
||||
|
@ -7029,8 +7021,7 @@ private:
|
|||
|
||||
void enum25() { // ticket #2966 (segmentation fault)
|
||||
const char code[] = "enum x :\n";
|
||||
checkSimplifyEnum(code);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(checkSimplifyEnum(code), InternalError);
|
||||
}
|
||||
|
||||
void enum26() { // ticket #2975 (segmentation fault)
|
||||
|
@ -7041,8 +7032,7 @@ private:
|
|||
|
||||
void enum27() { // ticket #3005 (segmentation fault)
|
||||
const char code[] = "enum : x\n";
|
||||
checkSimplifyEnum(code);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(checkSimplifyEnum(code), InternalError);
|
||||
}
|
||||
|
||||
void enum28() {
|
||||
|
@ -7186,8 +7176,7 @@ private:
|
|||
"struct bytecode {};\n"
|
||||
"jv jq_next() { opcode = ((opcode) +NUM_OPCODES);\n"
|
||||
"}";
|
||||
checkSimplifyEnum(code);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(checkSimplifyEnum(code), InternalError);
|
||||
}
|
||||
|
||||
void removestd() {
|
||||
|
|
|
@ -89,8 +89,6 @@ private:
|
|||
TEST_CASE(insert1);
|
||||
TEST_CASE(insert2);
|
||||
|
||||
TEST_CASE(invalidcode);
|
||||
|
||||
TEST_CASE(stlBoundaries1);
|
||||
TEST_CASE(stlBoundaries2);
|
||||
TEST_CASE(stlBoundaries3);
|
||||
|
@ -1271,20 +1269,6 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void invalidcode() {
|
||||
errout.str("");
|
||||
const std::string src = "void f()\n"
|
||||
"{\n"
|
||||
" for (\n"
|
||||
"}\n";
|
||||
|
||||
Settings settings;
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
std::istringstream istr(src);
|
||||
ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp"));
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Invalid number of character (() when these macros are defined: ''.\n", errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void stlBoundaries1() {
|
||||
|
|
|
@ -116,7 +116,9 @@ private:
|
|||
static const Settings settings;
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
std::istringstream istr(code);
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
try {
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
} catch (...) {}
|
||||
return Token::Match(tokenizer.tokens(), pattern.c_str(), varid);
|
||||
}
|
||||
|
||||
|
|
|
@ -777,7 +777,7 @@ private:
|
|||
|
||||
void tokenize19() {
|
||||
// #3006 - added hasComplicatedSyntaxErrorsInTemplates to avoid segmentation fault
|
||||
tokenizeAndStringify("x < () <");
|
||||
ASSERT_THROW(tokenizeAndStringify("x < () <"), InternalError);
|
||||
|
||||
// #3496 - make sure hasComplicatedSyntaxErrorsInTemplates works
|
||||
ASSERT_EQUALS("void a ( Fred * f ) { for ( ; n < f . x ( ) ; ) { } }",
|
||||
|
@ -802,7 +802,7 @@ private:
|
|||
|
||||
// #4195 - segfault for "enum { int f ( ) { return = } r = f ( ) ; }"
|
||||
void tokenize24() {
|
||||
tokenizeAndStringify("enum { int f ( ) { return = } r = f ( ) ; }");
|
||||
ASSERT_THROW(tokenizeAndStringify("enum { int f ( ) { return = } r = f ( ) ; }"), InternalError);
|
||||
}
|
||||
|
||||
// #4239 - segfault for "f ( struct { int typedef T x ; } ) { }"
|
||||
|
@ -854,14 +854,12 @@ private:
|
|||
|
||||
{
|
||||
const std::string code("struct A { template<int> struct { }; };");
|
||||
ASSERT_EQUALS("", tokenizeAndStringify(code.c_str(), true));
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(tokenizeAndStringify(code.c_str(), true), InternalError);
|
||||
}
|
||||
|
||||
{
|
||||
const std::string code("enum ABC { A,B, typedef enum { C } };");
|
||||
tokenizeAndStringify(code.c_str(), true);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(tokenizeAndStringify(code.c_str(), true), InternalError);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -893,27 +891,32 @@ private:
|
|||
" )\n"
|
||||
"}";
|
||||
|
||||
tokenizeAndStringify(code);
|
||||
try {
|
||||
tokenizeAndStringify(code);
|
||||
assertThrowFail(__FILE__, __LINE__);
|
||||
}
|
||||
catch (InternalError& e) {
|
||||
ASSERT_EQUALS("Analysis failed. If the code is valid then please report this failure.", e.errorMessage);
|
||||
ASSERT_EQUALS("cppcheckError", e.id);
|
||||
ASSERT_EQUALS(5, e.token->linenr());
|
||||
}
|
||||
}
|
||||
|
||||
void wrong_syntax4() { // #3618
|
||||
const char code[] = "typedef void (x) (int); return x&";
|
||||
|
||||
tokenizeAndStringify(code);
|
||||
ASSERT_THROW(tokenizeAndStringify(code), InternalError);
|
||||
}
|
||||
|
||||
void wrong_syntax_if_macro() {
|
||||
// #2518 #4171
|
||||
tokenizeAndStringify("void f() { if MACRO(); }", false);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(tokenizeAndStringify("void f() { if MACRO(); }", false), InternalError);
|
||||
|
||||
// #4668 - note there is no semicolon after MACRO()
|
||||
tokenizeAndStringify("void f() { if (x) MACRO() {} }", false);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(tokenizeAndStringify("void f() { if (x) MACRO() {} }", false), InternalError);
|
||||
|
||||
// #4810 - note there is no semicolon after MACRO()
|
||||
tokenizeAndStringify("void f() { if (x) MACRO() else ; }", false);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(tokenizeAndStringify("void f() { if (x) MACRO() else ; }", false), InternalError);
|
||||
}
|
||||
|
||||
void wrong_syntax_class_x_y() {
|
||||
|
@ -974,31 +977,23 @@ private:
|
|||
|
||||
//wrong syntax
|
||||
{
|
||||
tokenizeAndStringify("void f() {switch (n) { case: z(); break;}}");
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(tokenizeAndStringify("void f() {switch (n) { case: z(); break;}}"), InternalError);
|
||||
|
||||
tokenizeAndStringify("void f() {switch (n) { case;: z(); break;}}");
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(tokenizeAndStringify("void f() {switch (n) { case;: z(); break;}}"), InternalError);
|
||||
|
||||
tokenizeAndStringify("void f() {switch (n) { case {}: z(); break;}}");
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(tokenizeAndStringify("void f() {switch (n) { case {}: z(); break;}}"), InternalError);
|
||||
|
||||
tokenizeAndStringify("void f() {switch (n) { case 0?{1}:{2} : z(); break;}}");
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(tokenizeAndStringify("void f() {switch (n) { case 0?{1}:{2} : z(); break;}}"), InternalError);
|
||||
|
||||
tokenizeAndStringify("void f() {switch (n) { case 0?1;:{2} : z(); break;}}");
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(tokenizeAndStringify("void f() {switch (n) { case 0?1;:{2} : z(); break;}}"), InternalError);
|
||||
|
||||
tokenizeAndStringify("void f() {switch (n) { case 0?(1?{3:4}):2 : z(); break;}}");
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(tokenizeAndStringify("void f() {switch (n) { case 0?(1?{3:4}):2 : z(); break;}}"), InternalError);
|
||||
|
||||
//ticket #4234
|
||||
tokenizeAndStringify("( ) { switch break ; { switch ( x ) { case } y break ; : } }");
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(tokenizeAndStringify("( ) { switch break ; { switch ( x ) { case } y break ; : } }"), InternalError);
|
||||
|
||||
//ticket #4267
|
||||
tokenizeAndStringify("f ( ) { switch break; { switch ( x ) { case } case break; -6: ( ) ; } }");
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(tokenizeAndStringify("f ( ) { switch break; { switch ( x ) { case } case break; -6: ( ) ; } }"), InternalError);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1007,15 +1002,15 @@ private:
|
|||
}
|
||||
|
||||
void garbageCode2() { //#4300 (segmentation fault)
|
||||
tokenizeAndStringify("enum { D = 1 struct { } ; } s.b = D;");
|
||||
ASSERT_THROW(tokenizeAndStringify("enum { D = 1 struct { } ; } s.b = D;"), InternalError);
|
||||
}
|
||||
|
||||
void garbageCode3() { //#4849 (segmentation fault in Tokenizer::simplifyStructDecl (invalid code))
|
||||
tokenizeAndStringify("enum { D = 2 s ; struct y { x } ; } { s.a = C ; s.b = D ; }");
|
||||
ASSERT_THROW(tokenizeAndStringify("enum { D = 2 s ; struct y { x } ; } { s.a = C ; s.b = D ; }"), InternalError);
|
||||
}
|
||||
|
||||
void garbageCode4() { // #4887
|
||||
tokenizeAndStringify("void f ( ) { = a ; if ( 1 ) if = ( 0 ) ; }");
|
||||
ASSERT_THROW(tokenizeAndStringify("void f ( ) { = a ; if ( 1 ) if = ( 0 ) ; }"), InternalError);
|
||||
}
|
||||
|
||||
void garbageCode5() { // #5168
|
||||
|
@ -1028,12 +1023,12 @@ private:
|
|||
}
|
||||
|
||||
void garbageCode7() {
|
||||
tokenizeAndStringify("1 (int j) { return return (c) * sizeof } y[1];", /*simplify=*/true);
|
||||
ASSERT_THROW(tokenizeAndStringify("1 (int j) { return return (c) * sizeof } y[1];", /*simplify=*/true), InternalError);
|
||||
tokenizeAndStringify("foo(Args&&...) fn void = { } auto template<typename... bar(Args&&...)", /*simplify=*/true);
|
||||
}
|
||||
|
||||
void garbageCode8() {
|
||||
tokenizeAndStringify("{ enum struct : };", true);
|
||||
ASSERT_THROW(tokenizeAndStringify("{ enum struct : };", true), InternalError);
|
||||
}
|
||||
|
||||
void simplifyFileAndLineMacro() { // tokenize 'return - __LINE__' correctly
|
||||
|
@ -1482,8 +1477,7 @@ private:
|
|||
|
||||
void ifAddBraces20() { // #5012 - syntax error 'else }'
|
||||
const char code[] = "void f() { if(x) {} else }";
|
||||
tokenizeAndStringify(code,true);
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(tokenizeAndStringify(code, true), InternalError);
|
||||
}
|
||||
|
||||
void whileAddBraces() {
|
||||
|
@ -1872,7 +1866,7 @@ private:
|
|||
void simplifyKnownVariables16() {
|
||||
// ticket #807 - segmentation fault when macro isn't found
|
||||
const char code[] = "void f ( ) { int n = 1; DISPATCH(while); }";
|
||||
simplifyKnownVariables(code);
|
||||
ASSERT_THROW(simplifyKnownVariables(code), InternalError);
|
||||
}
|
||||
|
||||
void simplifyKnownVariables17() {
|
||||
|
@ -5367,17 +5361,15 @@ private:
|
|||
|
||||
void simplifyFunctionParametersErrors() {
|
||||
//same parameters...
|
||||
tokenizeAndStringify("void foo(x, x)\n"
|
||||
" int x;\n"
|
||||
" int x;\n"
|
||||
"{}\n");
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(tokenizeAndStringify("void foo(x, x)\n"
|
||||
" int x;\n"
|
||||
" int x;\n"
|
||||
"{}\n"), InternalError);
|
||||
|
||||
tokenizeAndStringify("void foo(x, y)\n"
|
||||
" int x;\n"
|
||||
" int x;\n"
|
||||
"{}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(tokenizeAndStringify("void foo(x, y)\n"
|
||||
" int x;\n"
|
||||
" int x;\n"
|
||||
"{}\n"), InternalError);
|
||||
|
||||
tokenizeAndStringify("void foo(int, int)\n"
|
||||
"{}\n");
|
||||
|
@ -6221,8 +6213,7 @@ private:
|
|||
Settings settings;
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
std::istringstream istr(code);
|
||||
ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp"));
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid number of character ({) when these macros are defined: ''.\n", errout.str());
|
||||
ASSERT_THROW(tokenizer.tokenize(istr, "test.cpp"), InternalError);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -6231,8 +6222,7 @@ private:
|
|||
Settings settings;
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
std::istringstream istr(code);
|
||||
ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp"));
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid number of character (() when these macros are defined: ''.\n", errout.str());
|
||||
ASSERT_THROW(tokenizer.tokenize(istr, "test.cpp"), InternalError);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -6255,8 +6245,7 @@ private:
|
|||
Settings settings;
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
std::istringstream istr(code);
|
||||
ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp", "ABC"));
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Invalid number of character (() when these macros are defined: 'ABC'.\n", errout.str());
|
||||
ASSERT_THROW(tokenizer.tokenize(istr, "test.cpp", "ABC"), InternalError);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -6268,8 +6257,7 @@ private:
|
|||
Settings settings;
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
std::istringstream istr(code);
|
||||
ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp"));
|
||||
ASSERT_EQUALS("[test.cpp:2]: (error) Invalid number of character ({) when these macros are defined: ''.\n", errout.str());
|
||||
ASSERT_THROW(tokenizer.tokenize(istr, "test.cpp"), InternalError);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -6281,8 +6269,7 @@ private:
|
|||
Settings settings;
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
std::istringstream istr(code);
|
||||
ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp"));
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Invalid number of character ([) when these macros are defined: ''.\n", errout.str());
|
||||
ASSERT_THROW(tokenizer.tokenize(istr, "test.cpp"), InternalError);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -6296,8 +6283,14 @@ private:
|
|||
Settings settings;
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
std::istringstream istr(code);
|
||||
ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp"));
|
||||
ASSERT_EQUALS("[test.cpp:2]: (error) Invalid number of character (() when these macros are defined: ''.\n", errout.str());
|
||||
try {
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
assertThrowFail(__FILE__, __LINE__);
|
||||
} catch (InternalError& e) {
|
||||
ASSERT_EQUALS("Invalid number of character (() when these macros are defined: ''.", e.errorMessage);
|
||||
ASSERT_EQUALS("syntaxError", e.id);
|
||||
ASSERT_EQUALS(2, e.token->linenr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6361,8 +6354,7 @@ private:
|
|||
std::istringstream istr("x<y<int> xyz;\n");
|
||||
Settings settings;
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(tokenizer.tokenize(istr, "test.cpp"), InternalError);
|
||||
}
|
||||
|
||||
// bad code
|
||||
|
@ -6376,8 +6368,7 @@ private:
|
|||
" >::type ConcreteVisitableOrDummy;\n");
|
||||
Settings settings;
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(tokenizer.tokenize(istr, "test.cpp"), InternalError);
|
||||
}
|
||||
|
||||
// code is ok, don't show syntax error
|
||||
|
@ -7194,7 +7185,7 @@ private:
|
|||
ASSERT_EQUALS("void f(){ MACRO( ab: b=0;, foo)}", labels_("void f() { MACRO(ab: b=0;, foo)}"));
|
||||
ASSERT_EQUALS("void f(){ MACRO( bar, ab:{&(* b. x)=0;})}", labels_("void f() { MACRO(bar, ab: {&(*b.x)=0;})}"));
|
||||
//don't crash with garbage code
|
||||
ASSERT_EQUALS("switch(){ case}", labels_("switch(){case}"));
|
||||
ASSERT_THROW(labels_("switch(){case}"), InternalError);
|
||||
}
|
||||
|
||||
void simplifyInitVar() {
|
||||
|
|
|
@ -582,11 +582,10 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// Ticket #3480 - Don't crash garbage code
|
||||
checkUninitVar("int f()\n"
|
||||
"{\n"
|
||||
" return if\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) syntax error\n", errout.str());
|
||||
ASSERT_THROW(checkUninitVar("int f()\n"
|
||||
"{\n"
|
||||
" return if\n"
|
||||
"}"), InternalError);
|
||||
|
||||
// Ticket #3873 (false positive)
|
||||
checkUninitVar("MachineLoopRange *MachineLoopRanges::getLoopRange(const MachineLoop *Loop) {\n"
|
||||
|
|
|
@ -131,7 +131,6 @@ private:
|
|||
TEST_CASE(localvarStruct1);
|
||||
TEST_CASE(localvarStruct2);
|
||||
TEST_CASE(localvarStruct3);
|
||||
TEST_CASE(localvarStruct4); // Ticket #31: sigsegv on incomplete struct
|
||||
TEST_CASE(localvarStruct5);
|
||||
TEST_CASE(localvarStruct6);
|
||||
TEST_CASE(localvarStructArray);
|
||||
|
@ -2865,13 +2864,6 @@ private:
|
|||
"[test.cpp:4]: (style) Unused variable: z\n", "", errout.str());
|
||||
}
|
||||
|
||||
void localvarStruct4() {
|
||||
/* This must not SIGSEGV: */
|
||||
functionVariableUsage("void foo()\n"
|
||||
"{\n"
|
||||
" struct { \n");
|
||||
}
|
||||
|
||||
void localvarStruct5() {
|
||||
functionVariableUsage("int foo() {\n"
|
||||
" A a;\n"
|
||||
|
|
Loading…
Reference in New Issue