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
6 changes: 6 additions & 0 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8690,6 +8690,12 @@ void Tokenizer::findGarbageCode() const
syntaxError(tok);
if (Token::Match(tok, "^ %op%") && !Token::Match(tok->next(), "[>*+-!~]"))
syntaxError(tok);
if (Token::Match(tok, ": [)]=]"))
syntaxError(tok);
if (Token::Match(tok, "typedef [,;]"))
syntaxError(tok);
if (Token::Match(tok, "! %comp%"))
syntaxError(tok);

if (tok->link() && Token::Match(tok, "[([]") && (!tok->tokAt(-1) || !tok->tokAt(-1)->isControlFlowKeyword())) {
const Token* const end = tok->link();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
assert({:=4;})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v o(i a){$ i;for(i:)a=[]0;}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
n a(){!!=!!?:b}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{for(typedef,typedef;);}
6 changes: 3 additions & 3 deletions test/testgarbage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ class TestGarbage : public TestFixture {
ASSERT_THROW_INTERNAL_EQUALS(checkCode("{ xs :: i(:) ! ! x/5 ! !\n"
"i, :: a :: b integer, } foo2(x) :: j(:)\n"
"b type(*), d(:), a x :: end d(..), foo end\n"
"foo4 b d(..), a a x type(*), b foo2 b"), INTERNAL, "Internal error. AST cyclic dependency.");
"foo4 b d(..), a a x type(*), b foo2 b"), SYNTAX, "syntax error");
}

void garbageCode100() { // #6840
Expand Down Expand Up @@ -987,7 +987,7 @@ class TestGarbage : public TestFixture {
}

void garbageCode125() {
ASSERT_THROW_INTERNAL(checkCode("{ T struct B : T valueA_AA ; } T : [ T > ( ) { B } template < T > struct A < > : ] { ( ) { return valueA_AC struct { : } } b A < int > AC ( ) a_aa.M ; ( ) ( ) }"), UNKNOWN_MACRO);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these UNKNOWN_MACRO in the garbage tests felt undesired.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We mostly use the "if it's uppercase, it's a macro" heuristic, so...

ASSERT_THROW_INTERNAL(checkCode("{ T struct B : T valueA_AA ; } T : [ T > ( ) { B } template < T > struct A < > : ] { ( ) { return valueA_AC struct { : } } b A < int > AC ( ) a_aa.M ; ( ) ( ) }"), SYNTAX);
ASSERT_THROW_INTERNAL(checkCode("template < Types > struct S :{ ( S < ) S >} { ( ) { } } ( ) { return S < void > ( ) }"),
SYNTAX);
}
Expand Down Expand Up @@ -1661,7 +1661,7 @@ class TestGarbage : public TestFixture {

void garbageCode206() {
ASSERT_EQUALS("[test.cpp:1] syntax error: operator", getSyntaxError("void foo() { for (auto operator new : int); }"));
ASSERT_EQUALS("[test.cpp:1] syntax error: operator", getSyntaxError("void foo() { for (a operator== :) }"));
ASSERT_EQUALS("[test.cpp:1] syntax error", getSyntaxError("void foo() { for (a operator== :) }"));
}

void garbageCode207() { // #8750
Expand Down