Fixed false positive #7953: Support type conversion operators returning pointers
This commit is contained in:
parent
c280bcedb4
commit
996501a449
|
@ -1734,7 +1734,7 @@ void CheckClass::checkConst()
|
|||
continue;
|
||||
} else if (func->isOperator() && Token::Match(previous, ";|{|}|public:|private:|protected:")) { // Operator without return type: conversion operator
|
||||
const std::string& opName = func->tokenDef->str();
|
||||
if (opName.compare(8, 5, "const") != 0 && opName.back() == '&')
|
||||
if (opName.compare(8, 5, "const") != 0 && (opName.back() == '&' || opName.back() == '*'))
|
||||
continue;
|
||||
} else {
|
||||
// don't warn for unknown types..
|
||||
|
|
|
@ -3320,12 +3320,28 @@ private:
|
|||
}
|
||||
|
||||
void constoperator4() {
|
||||
// #7953
|
||||
checkConst("class A {\n"
|
||||
" int c;\n"
|
||||
"public:\n"
|
||||
" operator int*() { return &c; };\n"
|
||||
"};");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkConst("class A {\n"
|
||||
" int c;\n"
|
||||
"public:\n"
|
||||
" operator const int*() { return &c; };\n"
|
||||
"};");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::operatorconstint*' can be const.\n", errout.str());
|
||||
|
||||
// #2375
|
||||
checkConst("struct Fred {\n"
|
||||
" int array[10];\n"
|
||||
" typedef int* (Fred::*UnspecifiedBoolType);\n"
|
||||
" operator UnspecifiedBoolType() { };\n"
|
||||
"};");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::operatorint**' can be const.\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::operatorint**' can be const.\n", "", errout.str());
|
||||
|
||||
checkConst("struct Fred {\n"
|
||||
" int array[10];\n"
|
||||
|
|
Loading…
Reference in New Issue