@@ -1692,9 +1692,11 @@ void CheckClass::checkConst()
16921692
16931693 for (func = scope->functionList .begin (); func != scope->functionList .end (); ++func) {
16941694 // does the function have a body?
1695- if (func->type != Function::eFunction || !func->hasBody () || func->isFriend () || func->isStatic () || func->isVirtual ())
1695+ if (func->type != Function::eFunction || !func->hasBody ())
1696+ continue ;
1697+ // don't warn for friend/static/virtual methods
1698+ if (func->isFriend () || func->isStatic () || func->isVirtual ())
16961699 continue ;
1697-
16981700 // get last token of return type
16991701 const Token *previous = func->tokenDef ->previous ();
17001702
@@ -1728,36 +1730,36 @@ void CheckClass::checkConst()
17281730 }
17291731
17301732 // check if base class function is virtual
1731- if (!scope->definedType ->derivedFrom .empty ()) {
1732- if (func->isImplicitlyVirtual (true ))
1733- continue ;
1734- }
1733+ if (!scope->definedType ->derivedFrom .empty () && func->isImplicitlyVirtual (true ))
1734+ continue ;
17351735
17361736 bool memberAccessed = false ;
17371737 // if nothing non-const was found. write error..
1738- if (checkConstFunc (scope, &*func, memberAccessed)) {
1739- std::string classname = scope->className ;
1740- const Scope *nest = scope->nestedIn ;
1741- while (nest && nest->type != Scope::eGlobal) {
1742- classname = std::string (nest->className + " ::" + classname);
1743- nest = nest->nestedIn ;
1744- }
1745-
1746- // get function name
1747- std::string functionName = (func->tokenDef ->isName () ? " " : " operator" ) + func->tokenDef ->str ();
1738+ if (!checkConstFunc (scope, &*func, memberAccessed))
1739+ continue ;
17481740
1749- if (func->tokenDef ->str () == " (" )
1750- functionName += " )" ;
1751- else if (func->tokenDef ->str () == " [" )
1752- functionName += " ]" ;
1741+ if (func->isConst () && (memberAccessed || func->isOperator ()))
1742+ continue ;
17531743
1754- if (!func->isConst () || (!memberAccessed && !func->isOperator ())) {
1755- if (func->isInline ())
1756- checkConstError (func->token , classname, functionName, !memberAccessed && !func->isOperator ());
1757- else // not inline
1758- checkConstError2 (func->token , func->tokenDef , classname, functionName, !memberAccessed && !func->isOperator ());
1759- }
1744+ std::string classname = scope->className ;
1745+ const Scope *nest = scope->nestedIn ;
1746+ while (nest && nest->type != Scope::eGlobal) {
1747+ classname = std::string (nest->className + " ::" + classname);
1748+ nest = nest->nestedIn ;
17601749 }
1750+
1751+ // get function name
1752+ std::string functionName = (func->tokenDef ->isName () ? " " : " operator" ) + func->tokenDef ->str ();
1753+
1754+ if (func->tokenDef ->str () == " (" )
1755+ functionName += " )" ;
1756+ else if (func->tokenDef ->str () == " [" )
1757+ functionName += " ]" ;
1758+
1759+ if (func->isInline ())
1760+ checkConstError (func->token , classname, functionName, !memberAccessed && !func->isOperator ());
1761+ else // not inline
1762+ checkConstError2 (func->token , func->tokenDef , classname, functionName, !memberAccessed && !func->isOperator ());
17611763 }
17621764 }
17631765}
0 commit comments