@@ -481,8 +481,9 @@ void CheckClass::noConstructorError(const Token *tok, const std::string &classna
481481 " The " + std::string (isStruct ? " struct" : " class" ) + " '" + classname +
482482 " ' does not have a constructor.\n "
483483 " The " + std::string (isStruct ? " struct" : " class" ) + " '" + classname +
484- " 'does not have a constructor but it has attributes. "
485- " The attributes are not initialized which may cause bugs or undefined behavior." );
484+ " ' does not have a constructor although it has private member variables. "
485+ " Member variables of builtin types are left uninitialized when the class is "
486+ " instanciated. That may cause bugs or undefined behavior." );
486487}
487488
488489void CheckClass::uninitVarError (const Token *tok, const std::string &classname, const std::string &varname)
@@ -492,7 +493,7 @@ void CheckClass::uninitVarError(const Token *tok, const std::string &classname,
492493
493494void CheckClass::operatorEqVarError (const Token *tok, const std::string &classname, const std::string &varname)
494495{
495- reportError (tok, Severity::warning, " operatorEqVarError" , " Member variable '" + classname + " ::" + varname + " ' is not assigned a value in '" + classname + " ::operator=" + " ' " );
496+ reportError (tok, Severity::warning, " operatorEqVarError" , " Member variable '" + classname + " ::" + varname + " ' is not assigned a value in '" + classname + " ::operator='. " );
496497}
497498
498499// ---------------------------------------------------------------------------
@@ -657,7 +658,7 @@ void CheckClass::privateFunctions()
657658
658659void CheckClass::unusedPrivateFunctionError (const Token *tok, const std::string &classname, const std::string &funcname)
659660{
660- reportError (tok, Severity::style, " unusedPrivateFunction" , " Unused private function '" + classname + " ::" + funcname + " '" );
661+ reportError (tok, Severity::style, " unusedPrivateFunction" , " Unused private function: '" + classname + " ::" + funcname + " '" );
661662}
662663
663664// ---------------------------------------------------------------------------
@@ -749,7 +750,7 @@ void CheckClass::checkMemsetType(const Scope *start, const Token *tok, const Sco
749750
750751void CheckClass::memsetError (const Token *tok, const std::string &memfunc, const std::string &classname, const std::string &type)
751752{
752- reportError (tok, Severity::error, " memsetClass" , " Using '" + memfunc + " ' on " + type + " that contains a " + classname);
753+ reportError (tok, Severity::error, " memsetClass" , " Using '" + memfunc + " ' on " + type + " that contains a " + classname + " . " );
753754}
754755
755756// ---------------------------------------------------------------------------
@@ -790,7 +791,7 @@ void CheckClass::operatorEq()
790791
791792void CheckClass::operatorEqReturnError (const Token *tok, const std::string &className)
792793{
793- reportError (tok, Severity::style, " operatorEq" , " \ '" + className + " ::operator=' should return \ '" + className + " &\' " );
794+ reportError (tok, Severity::style, " operatorEq" , " '" + className + " ::operator=' should return '" + className + " &'. " );
794795}
795796
796797// ---------------------------------------------------------------------------
@@ -880,7 +881,7 @@ void CheckClass::checkReturnPtrThis(const Scope *scope, const Function *func, co
880881
881882void CheckClass::operatorEqRetRefThisError (const Token *tok)
882883{
883- reportError (tok, Severity::style, " operatorEqRetRefThis" , " 'operator=' should return reference to self " );
884+ reportError (tok, Severity::style, " operatorEqRetRefThis" , " 'operator=' should return reference to 'this' instance. " );
884885}
885886
886887// ---------------------------------------------------------------------------
@@ -1003,7 +1004,10 @@ bool CheckClass::hasAssignSelf(const Function *func, const Token *rhs)
10031004
10041005void CheckClass::operatorEqToSelfError (const Token *tok)
10051006{
1006- reportError (tok, Severity::warning, " operatorEqToSelf" , " 'operator=' should check for assignment to self" );
1007+ reportError (tok, Severity::warning, " operatorEqToSelf" ,
1008+ " 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n "
1009+ " 'operator=' should check for assignment to self to ensure that each block of dynamically "
1010+ " allocated memory is owned and managed by only one instance of the class." );
10071011}
10081012
10091013// ---------------------------------------------------------------------------
@@ -1125,7 +1129,11 @@ void CheckClass::virtualDestructor()
11251129
11261130void CheckClass::virtualDestructorError (const Token *tok, const std::string &Base, const std::string &Derived)
11271131{
1128- reportError (tok, Severity::error, " virtualDestructor" , " Class " + Base + " which is inherited by class " + Derived + " does not have a virtual destructor" );
1132+ reportError (tok, Severity::error, " virtualDestructor" , " Class '" + Base + " ' which is inherited by class '" + Derived + " ' does not have a virtual destructor.\n "
1133+ " Class '" + Base + " ' which is inherited by class '" + Derived + " ' does not have a virtual destructor. "
1134+ " If you destroy instances of the derived class by deleting a pointer that points to the base class, only "
1135+ " the destructor of the base class is executed. Thus, dynamic memory that is managed by the derived class "
1136+ " could leak. This can be avoided by adding a virtual destructor to the base class." );
11291137}
11301138
11311139// ---------------------------------------------------------------------------
@@ -1152,7 +1160,7 @@ void CheckClass::thisSubtraction()
11521160
11531161void CheckClass::thisSubtractionError (const Token *tok)
11541162{
1155- reportError (tok, Severity::warning, " thisSubtraction" , " Suspicious pointer subtraction" );
1163+ reportError (tok, Severity::warning, " thisSubtraction" , " Suspicious pointer subtraction. Did you intend to write '->'? " );
11561164}
11571165
11581166// ---------------------------------------------------------------------------
@@ -1540,26 +1548,21 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func)
15401548
15411549void CheckClass::checkConstError (const Token *tok, const std::string &classname, const std::string &funcname)
15421550{
1543- reportError (tok, Severity::style, " functionConst" ,
1544- " Technically the member function '" + classname + " ::" + funcname + " ' can be const.\n "
1545- " The member function '" + classname + " ::" + funcname + " ' can be made a const "
1546- " function. Making this function const function should not cause compiler errors. "
1547- " Even though the function can be made const function technically it may not make "
1548- " sense conceptually. Think about your design and task of the function first - is "
1549- " it a function that must not change object internal state?" , true );
1551+ checkConstError2 (tok, 0 , classname, funcname);
15501552}
15511553
15521554void CheckClass::checkConstError2 (const Token *tok1, const Token *tok2, const std::string &classname, const std::string &funcname)
15531555{
15541556 std::list<const Token *> toks;
15551557 toks.push_back (tok1);
1556- toks.push_back (tok2);
1558+ if (tok2)
1559+ toks.push_back (tok2);
15571560 reportError (toks, Severity::style, " functionConst" ,
15581561 " Technically the member function '" + classname + " ::" + funcname + " ' can be const.\n "
15591562 " The member function '" + classname + " ::" + funcname + " ' can be made a const "
1560- " function. Making this function const function should not cause compiler errors. "
1563+ " function. Making this function ' const' should not cause compiler errors. "
15611564 " Even though the function can be made const function technically it may not make "
1562- " sense conceptually. Think about your design and task of the function first - is "
1565+ " sense conceptually. Think about your design and the task of the function first - is "
15631566 " it a function that must not change object internal state?" , true );
15641567}
15651568
@@ -1644,8 +1647,10 @@ void CheckClass::initializerListError(const Token *tok1, const Token *tok2, cons
16441647 toks.push_back (tok2);
16451648 reportError (toks, Severity::style, " initializerList" ,
16461649 " Member variable '" + classname + " ::" +
1647- varname + " ' is in the wrong order in the initializer list.\n "
1648- " Members are initialized in the order they are declared, not the "
1650+ varname + " ' is in the wrong place in the initializer list.\n "
1651+ " Member variable '" + classname + " ::" +
1652+ varname + " ' is in the wrong place in the initializer list. "
1653+ " Members are initialized in the order they are declared, not in the "
16491654 " order they are in the initializer list. Keeping the initializer list "
16501655 " in the same order that the members were declared prevents order dependent "
16511656 " initialization errors." , true );
0 commit comments