Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
12 changes: 12 additions & 0 deletions lib/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplifyUsing() already sets fIsSimplifiedTypedef, see e.g. here:

tok1->isSimplifiedTypedef(true);

So we should either use only the existing flag, or use the new one everywhere.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, that's strange, then we shouldn't have a false positive in the first place. I'll look in to it. Thanks!

};

enum : std::uint8_t {
Expand Down
3 changes: 3 additions & 0 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading