diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index b485b3fb2cc..c2ecb907028 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8765,6 +8765,8 @@ void Tokenizer::findGarbageCode() const syntaxError(tok, prev == tok->previous() ? (prev->str() + " " + tok->str()) : (prev->str() + " .. " + tok->str())); } } + else if (tok->isStandardType() && tok->next() && tok->str() == tok->strAt(1) && tok->str() != "long") + syntaxError(tok); } // invalid struct declaration diff --git a/test/cli/other_test.py b/test/cli/other_test.py index 2ff65efc052..8f543924ae7 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -788,7 +788,7 @@ def test_addon_misc(tmpdir): f.write(""" extern void f() { - char char* [] = {"a" "b"} + const char* c[] = {"a" "b"}; } """) @@ -800,7 +800,7 @@ def test_addon_misc(tmpdir): assert lines == [ 'Checking {} ...'.format(test_file) ] - assert stderr == '{}:4:26: style: String concatenation in array initialization, missing comma? [misc-stringConcatInArrayInit]\n'.format(test_file) + assert stderr == '{}:4:28: style: String concatenation in array initialization, missing comma? [misc-stringConcatInArrayInit]\n'.format(test_file) def test_invalid_addon_json(tmpdir): diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index d7e6ed8345b..5f6b67867f7 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -259,6 +259,7 @@ class TestGarbage : public TestFixture { TEST_CASE(garbageCode228); TEST_CASE(garbageCode229); TEST_CASE(garbageCode230); + TEST_CASE(garbageCode231); TEST_CASE(garbageCodeFuzzerClientMode1); // test cases created with the fuzzer client, mode 1 @@ -1775,6 +1776,9 @@ class TestGarbage : public TestFixture { void garbageCode230() { // #14432 ASSERT_THROW_INTERNAL(checkCode("e U U,i"), SYNTAX); } + void garbageCode231() { + ASSERT_THROW_INTERNAL(checkCode("char char* [] = {\"a\" \"b\"}"), SYNTAX); + } void syntaxErrorFirstToken() {