diff --git a/lib/checkother.cpp b/lib/checkother.cpp index bbc6bdb90d0..26b4dc20dc2 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2024,7 +2024,7 @@ void CheckOther::checkConstPointer() // continue; if (!isConstPointerVariable(p, *mSettings)) continue; - if (p->typeStartToken() && p->typeStartToken()->isSimplifiedTypedef() && !(Token::simpleMatch(p->typeEndToken(), "*") && !p->typeEndToken()->isSimplifiedTypedef())) + if (p->typeStartToken() && p->typeStartToken()->isSimplifiedTypedefOrUsing() && !(Token::simpleMatch(p->typeEndToken(), "*") && !p->typeEndToken()->isSimplifiedTypedefOrUsing())) continue; constVariableError(p, p->isArgument() ? p->scope()->function : nullptr); } diff --git a/lib/token.h b/lib/token.h index 51fe1b6b7d0..6df353b3f66 100644 --- a/lib/token.h +++ b/lib/token.h @@ -655,6 +655,17 @@ class CPPCHECKLIB Token { setFlag(fIsSimplifiedTypedef, b); } + bool isSimplifiedUsing() const { + return getFlag(fIsSimplifiedUsing); + } + void isSimplifiedUsing(bool b) { + setFlag(fIsSimplifiedUsing, b); + } + + bool isSimplifiedTypedefOrUsing() const { + return isSimplifiedTypedef() || isSimplifiedUsing(); + } + bool isIncompleteConstant() const { return getFlag(fIsIncompleteConstant); } @@ -1509,6 +1520,7 @@ class CPPCHECKLIB Token { fIsInitComma = (1ULL << 43), // Is this comma located inside some {..}. i.e: {1,2,3,4} fIsInitBracket = (1ULL << 44), // Is this bracket used as a part of variable initialization i.e: int a{5}, b(2); fIsAnonymous = (1ULL << 45), // Is this a token added for an unnamed member + fIsSimplifiedUsing = (1ULL << 46), }; enum : std::uint8_t { diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 193fa5bbb4d..6646fa64afe 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2998,6 +2998,9 @@ bool Tokenizer::simplifyUsing() if (!usingEnd) continue; + for (Token *typeTok = start; typeTok != usingEnd; typeTok = typeTok->next()) + typeTok->isSimplifiedUsing(true); + // Move struct defined in using out of using. // using T = struct t { }; => struct t { }; using T = struct t; // fixme: this doesn't handle attributes diff --git a/test/testother.cpp b/test/testother.cpp index 88c83eba4b1..83fec2469af 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4763,6 +4763,12 @@ class TestOther : public TestFixture { " return [](int* p) { return *p; }(&i);\n" "}\n"); ASSERT_EQUALS("[test.cpp:3:20]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); + + check("using IntPtr = int *;\n" + "int* foo(IntPtr bar) {\n" + " return bar = 0;\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void constArray() {