Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8664,6 +8664,9 @@ void Tokenizer::findGarbageCode() const
}
if (!Token::Match(tok->next(), "( !!)"))
syntaxError(tok);
if (Token::simpleMatch(tok->linkAt(1), ") }")) {
syntaxError(tok->linkAt(1)->next());
}
if (tok->str() != "for") {
if (isGarbageExpr(tok->next(), tok->linkAt(1), cpp && (mSettings.standards.cpp>=Standards::cppstd_t::CPP17)))
syntaxError(tok);
Expand Down
4 changes: 2 additions & 2 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,13 +771,13 @@ class TestCondition : public TestFixture {

check("void f(size_t x) {\n"
" if (x == sizeof(int)) {}\n"
" else { if (x == sizeof(long))} {}\n"
" else { if (x == sizeof(long)) {} }\n"
"}\n");
ASSERT_EQUALS("", errout_str());

check("void f(size_t x) {\n"
" if (x == sizeof(long)) {}\n"
" else { if (x == sizeof(long long))} {}\n"
" else { if (x == sizeof(long long)) {} }\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}
Expand Down
6 changes: 2 additions & 4 deletions test/testgarbage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -883,8 +883,7 @@ class TestGarbage : public TestFixture {
}

void garbageCode102() { // #6846 (segmentation fault)
(void)checkCode("struct Object { ( ) ; Object & operator= ( Object ) { ( ) { } if ( this != & b ) } }");
ignore_errout(); // we do not care about the output
ASSERT_THROW_INTERNAL(checkCode("struct Object { ( ) ; Object & operator= ( Object ) { ( ) { } if ( this != & b ) } }"), SYNTAX);
}

void garbageCode103() { // #6824
Expand Down Expand Up @@ -1251,8 +1250,7 @@ class TestGarbage : public TestFixture {
const char code[] = "template <bool foo = std::value &&>\n"
"static std::string foo(char *Bla) {\n"
" while (Bla[1] && Bla[1] != ',') }\n";
(void)checkCode(code);
ignore_errout(); // we are not interested in the output
ASSERT_THROW_INTERNAL(checkCode(code), SYNTAX);
}

void garbageCode153() {
Expand Down
3 changes: 1 addition & 2 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3672,8 +3672,7 @@ class TestSymbolDatabase : public TestFixture {
}

void symboldatabase36() { // ticket #4892
check("void struct ( ) { if ( 1 ) } int main ( ) { }");
ASSERT_EQUALS("", errout_str());
ASSERT_THROW_INTERNAL(check("void struct ( ) { if ( 1 ) } int main ( ) { }"), SYNTAX);
}

void symboldatabase37() {
Expand Down
9 changes: 7 additions & 2 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5345,8 +5345,8 @@ class TestTokenizer : public TestFixture {
ASSERT_EQUALS("; x = 123 ;", tokenizeAndStringify(";x=({123;});"));
ASSERT_EQUALS("; x = y ;", tokenizeAndStringify(";x=({y;});"));
// #13419: Do not simplify compound statements in for loop
ASSERT_EQUALS("void foo ( int x ) { for ( ; ( { { } ; x < 1 ; } ) ; ) }",
tokenizeAndStringify("void foo(int x) { for (;({ {}; x<1; });) }"));
ASSERT_EQUALS("void foo ( int x ) { for ( ; ( { { } ; x < 1 ; } ) ; ) { ; } }",
tokenizeAndStringify("void foo(int x) { for (;({ {}; x<1; });); }"));
}

void simplifyOperatorName1() {
Expand Down Expand Up @@ -7627,6 +7627,11 @@ class TestTokenizer : public TestFixture {

ASSERT_THROW_INTERNAL(tokenizeAndStringify("{ for (()()) }"), SYNTAX); // #11643

ASSERT_THROW_INTERNAL(tokenizeAndStringify("void f(const std::vector<std::string>& v) {\n" // #14326
" for (const std::string&s : v)\n"
"}"),
SYNTAX);

ASSERT_NO_THROW(tokenizeAndStringify("S* g = ::new(ptr) S();")); // #12552
ASSERT_NO_THROW(tokenizeAndStringify("void f(int* p) { return ::delete p; }"));

Expand Down
Loading