From f2331031c26b47f1e5f8338effc49cd3e086f56a Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 30 Sep 2025 12:46:24 +0200 Subject: [PATCH 1/4] Update tokenize.cpp --- lib/tokenize.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c148b250396..1541375c174 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9542,6 +9542,8 @@ void Tokenizer::simplifyCPPAttribute() Token* head = skipCPPOrAlignAttribute(tok)->next(); while (isCPPAttribute(head) || isAlignAttribute(head)) head = skipCPPOrAlignAttribute(head)->next(); + if (!head) + syntaxError(tok); head->isAttributeMaybeUnused(true); } else if (Token::findsimplematch(tok->tokAt(2), "unused", tok->link())) { Token* head = skipCPPOrAlignAttribute(tok)->next(); From 45810da451f72628cf423485ada35b1c5f9cfeef Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 30 Sep 2025 12:51:27 +0200 Subject: [PATCH 2/4] Update testgarbage.cpp --- test/testgarbage.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index b2632e13500..aac83163223 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -257,6 +257,7 @@ class TestGarbage : public TestFixture { TEST_CASE(garbageCode226); TEST_CASE(garbageCode227); TEST_CASE(garbageCode228); + TEST_CASE(garbageCode229); TEST_CASE(garbageCodeFuzzerClientMode1); // test cases created with the fuzzer client, mode 1 @@ -1768,6 +1769,10 @@ class TestGarbage : public TestFixture { ASSERT_NO_THROW(checkCode("void f() { enum { A = [=]() mutable { return 0; }() }; }")); ASSERT_NO_THROW(checkCode("enum { A = [=](void) mutable -> int { return 0; }() };")); } + void garbageCode229() { // #14126 + ASSERT_THROW_INTERNAL(checkCode("void f() {} [[maybe_unused]]"), SYNTAX); + } + void syntaxErrorFirstToken() { ASSERT_THROW_INTERNAL(checkCode("&operator(){[]};"), SYNTAX); // #7818 From d3407b49942a31cf8926bc805c6d278d6deabb4d Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 1 Oct 2025 09:45:22 +0200 Subject: [PATCH 3/4] Update tokenize.cpp --- lib/tokenize.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 66dfc49a003..232caf89b37 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9550,6 +9550,8 @@ void Tokenizer::simplifyCPPAttribute() Token* head = skipCPPOrAlignAttribute(tok)->next(); while (isCPPAttribute(head) || isAlignAttribute(head)) head = skipCPPOrAlignAttribute(head)->next(); + if (!head) + syntaxError(tok); head->isAttributeUnused(true); } else if (Token::Match(tok->previous(), ") [ [ expects|ensures|assert default|audit|axiom| : %name% <|<=|>|>= %num% ] ]")) { const Token *vartok = tok->tokAt(4); From 7b7ab3238b9fbd3a84e2c19a023d8b842509ff65 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 1 Oct 2025 09:47:33 +0200 Subject: [PATCH 4/4] Update testgarbage.cpp --- test/testgarbage.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index aac83163223..d5549cb26cf 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -1771,6 +1771,7 @@ class TestGarbage : public TestFixture { } void garbageCode229() { // #14126 ASSERT_THROW_INTERNAL(checkCode("void f() {} [[maybe_unused]]"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("void f() {} [[unused]]"), SYNTAX); }