Redundant pointer op; Fixed false positives when macro is used
This commit is contained in:
parent
9a9f14bd8a
commit
87554bed7a
|
@ -2674,10 +2674,10 @@ void CheckOther::checkRedundantPointerOp()
|
|||
return;
|
||||
|
||||
for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) {
|
||||
if (!tok->isUnaryOp("&") || !tok->astOperand1()->isUnaryOp("*"))
|
||||
continue;
|
||||
if (tok->isExpandedMacro() && tok->str() == "(")
|
||||
tok = tok->link();
|
||||
|
||||
if (tok->isExpandedMacro())
|
||||
if (!tok->isUnaryOp("&") || !tok->astOperand1()->isUnaryOp("*"))
|
||||
continue;
|
||||
|
||||
// variable
|
||||
|
|
|
@ -8179,12 +8179,18 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:2]: (style) Redundant pointer operation on 'ptr' - it's already a pointer.\n", errout.str());
|
||||
|
||||
// no warning for macros
|
||||
check("#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\n"
|
||||
"void f(struct mutex *mut) {\n"
|
||||
" MUTEX_LOCK(*mut);\n"
|
||||
"}\n", nullptr, false, true);
|
||||
checkP("#define MUTEX_LOCK(m) pthread_mutex_lock(&(m))\n"
|
||||
"void f(struct mutex *mut) {\n"
|
||||
" MUTEX_LOCK(*mut);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkP("#define B(op) bar(op)\n"
|
||||
"#define C(orf) B(&orf)\n"
|
||||
"void foo(const int * pkey) {\n"
|
||||
" C(*pkey);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void test_isSameExpression() { // see #5738
|
||||
|
|
Loading…
Reference in New Issue