From 646afb772f9ce9aa7843922742d0a940f6c1f595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Fri, 4 Dec 2026 13:23:42 +0100 Subject: [PATCH 1/2] test --- test/testgarbage.cpp | 2 +- test/testtokenize.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index c798950b8e3..07570ff0630 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -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 diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index dcd1534a84f..c256b99dcd8 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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); @@ -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"); From dee187f7c0e6de46a54f21510a1d59fc53fc1d5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Fri, 4 Dec 2026 13:23:56 +0100 Subject: [PATCH 2/2] fix --- lib/tokenize.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 4dbd696f36a..c9e13d2e9e9 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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());