diff --git a/lib/checkother.cpp b/lib/checkother.cpp index cce598aaf7c5..7b4958c28591 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -944,6 +944,9 @@ void CheckOther::checkVariableScope() if (!var || !var->isLocal() || var->isConst()) continue; + if (var->nameToken()->isExpandedMacro()) + continue; + const bool isPtrOrRef = var->isPointer() || var->isReference(); const bool isSimpleType = var->typeStartToken()->isStandardType() || var->typeStartToken()->isEnumType() || (var->typeStartToken()->isC() && var->type() && var->type()->isStructType()); if (!isPtrOrRef && !isSimpleType && !astIsContainer(var->nameToken())) diff --git a/test/testother.cpp b/test/testother.cpp index b70317233019..9e0447518596 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -100,6 +100,7 @@ class TestOther : public TestFixture { TEST_CASE(varScope35); TEST_CASE(varScope36); // #12158 TEST_CASE(varScope37); // #12158 + TEST_CASE(varScope38); TEST_CASE(oldStylePointerCast); TEST_CASE(invalidPointerCast); @@ -1688,6 +1689,16 @@ class TestOther : public TestFixture { ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'i' can be reduced.\n", errout_str()); } + void varScope38() { + checkP("bool dostuff();\n" // #12519 + "#define DOSTUFF(c) if (c < 5) { if (c) b = dostuff(); }\n" + "#define DOSTUFFEX(c) { bool b = false; DOSTUFF(c); }\n" + "void f(int a) {\n" + " DOSTUFFEX(a);\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); + } + #define checkOldStylePointerCast(code) checkOldStylePointerCast_(code, __FILE__, __LINE__) void checkOldStylePointerCast_(const char code[], const char* file, int line) {