Skip to content
Open
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 @@ -9004,6 +9004,9 @@ void Tokenizer::findGarbageCode() const
else if (Token::Match(tok, "[`\\@]"))
syntaxError(tok);

else if (Token::Match(tok, ".|->") && !Token::Match(tok->next(), "%name%|~|*|::") && !Token::simpleMatch(tok->previous(), "operator"))
syntaxError(tok, tok->str() + tok->strAt(1));

// UNKNOWN_MACRO(return)
if (tok->isKeyword() && Token::Match(tok, "throw|return )") && Token::Match(tok->linkAt(1)->previous(), "%name% ("))
unknownMacroError(tok->linkAt(1)->previous());
Expand Down
2 changes: 1 addition & 1 deletion test/testgarbage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,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\n"), SYNTAX, "syntax error");
"foo4 b d(..), a a x type(*), b foo2 b\n"), SYNTAX, "syntax error: ..");
}

void garbageCode100() { // #6840
Expand Down
11 changes: 11 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ class TestTokenizer : public TestFixture {
// Make sure the Tokenizer::findGarbageCode() does not have false positives
// The TestGarbage ensures that there are true positives
TEST_CASE(findGarbageCode);
TEST_CASE(memberAccessWithoutName);
TEST_CASE(checkEnableIf);
TEST_CASE(checkTemplates);
TEST_CASE(checkNamespaces);
Expand Down Expand Up @@ -8068,6 +8069,16 @@ class TestTokenizer : public TestFixture {
ignore_errout();
}

void memberAccessWithoutName() {
const char code[] = "void f(void) {\n"
"\ti = x->(a, b);\n"
"}\n";
ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify(code, dinit(TokenizeOptions, $.cpp = false)), SYNTAX, "syntax error: ->(");
ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("void f(P *p) { p->1; }\n"), SYNTAX, "syntax error: ->1");
ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("void f(P p) { p.; }\n"), SYNTAX, "syntax error: .;");
ASSERT_NO_THROW(tokenizeAndStringify("void f(P *p) { p.operator->(); }\n"));
}

void findGarbageCode() { // Test Tokenizer::findGarbageCode()
// C++ try/catch in global scope
ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("try { }\n"), SYNTAX, "syntax error: keyword 'try' is not allowed in global scope");
Expand Down
Loading