CCS - CC++ Function Definition: f25a
CCS - CC++ Function Definition: f25b
CCS - CC++ Function Definition: f25c
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
26) Preserve natural semantics for overloaded operators.
// bad 26, dangerous to overload primitive operators in local project code
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
27) Prefer the canonical forms of arithmetic and assignment operators.
If the "L@R" case is overloaded, then the "L@=R" MUST be overloaded, and L@R MUST
be defined in terms of L@=R
// bad 27, the minus is intentionally missing the -= case
// good 27
CCS - CC++ Function Definition: operator+=
CCS - CC++ Function Definition: operator+
// bad 27, no operator-=
CCS - CC++ Function Definition: operator-
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
28) Prefer the canonical form of ++ and --. Prefer calling the prefix forms.
// if your class builds ++foo, then handle the foo++ case.
// bad 28, the minus is intentionally missing postfix case
// good 28
T& operator++ ( ) {} // ++foo
const T operator++ ( int ) {} // foo++
// bad 28, no postfix case
T& operator-- ( ) {} // prefix imp
main() {
T i;
++i;
i.operator++(); // prefix actuality
i++;
i.operator++(0); // postfix actuality
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
// 30) Avoid overloading &&, ||, or , (comma).
// bad 30
// ok 30
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
// 31) Don't write code that depends on the order of evaluation of function arguments.
// bad 31, don't return side-effect
CCS - CC++ Function Definition: inc31
CCS - CC++ Function Definition: f31
// bad 31, don't call with multiple side-effect on same object
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
// 33) Prefer minimal classes to monolithic classes.
the theory here is that if any of the five major components of a class are greater than
the miller-number [ 7 ], then the class is too big. the definition of 'monolithic class' is
user selectable.
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
34) Prefer composition to inheritance.
//private:
CCS - CC++ Function Definition: f34
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
// 36) Prefer providing abstract interfaces.
// if a class doesn't have a base, then verify that pure abstraction is used
// bad abstract class without pure interface
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
37) Public inheritance is substitutability. Inherit, not to reuse, but to be reused.
// verify that inheritance specializes the usage
CCS - CC++ Function Definition: C37
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
// 38) Practice safe overriding.
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
39) Consider making virtual functions nonpublic, and public functions nonvirtual.
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
40) Avoid providing implicit conversions.
// bad 40, implicit type conversion associatd with this class
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
41) Make data members private, except in behaviorless aggregates (C-stylestructs).
// The essence here is that member's that are derived from class must be private
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
// 42) Don't give away your internals.
CCS - CC++ Function Definition: f42
// here the public function f42 is 'giving away' private data
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
// 42) Don't give away your internals.
CCS - CC++ Function Definition: f42
// here the public function f42 is 'giving away' private data
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
// 43) Pimpl judiciously.
CCS - CC++ Function Definition: operator=
// boost example
namespace boost {
template class shared_ptr ;
struct Foo;
typedef boost::shared_ptr FooPtr;
struct FooPtrOps
bool operator()( const FooPtr & a, const FooPtr & b )
void operator()( const FooPtr & a )
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
// 44) Prefer writing nonmember nonfriend functions.
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
// 45) Always provide new and delete together.
// verify that the new & deletes balance
// bad 45, for C45B the delete is missing
// static void * operator delete(void*, size_t);
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
// 46) If you provide any class-specific new, provide all of the standard forms (plain, in-place, and nothrow).
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
// 58) Keep types and functions in separate namespaces unless they're specifically intended to work together.
namespace std {
template class vector {
CCS - CC++ Function Definition: operator+
CCS - CC++ Function Definition: f58
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
// 59. Namespaces and Modules. Don't write namespace usings in a header file or before an #include.
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
// 60) Avoid allocating and deallocating memory in different modules.
// two files 60.cpp that defines and allocates object, and 60a.cpp that de-allocates
CCS - CC++ Function Definition: f60
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
// 60) Avoid allocating and deallocating memory in different modules.
// two files 60.cpp that defines and allocates object, and 60a.cpp that de-allocates
// C60 *c60 = new C60; // allocate c60 in 60.cpp
CCS - CC++ Function Definition: f60a
// bad c60 not defined in this module
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
// 61) Don't define entities with linkage in a header file.
CCS - CC++ Function Definition: f61
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
// 62) Don't allow exceptions to propagate across module boundaries.
CCS - CC++ Function Definition: main
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
// 62) Don't allow exceptions to propagate across module boundaries.
CCS - CC++ Function Definition: f62a
// bad this throw is based on object outside of this module
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
// 63) Use sufficiently portable types in a module's interface.
//#include // load namespace std;
//using namespace std; // here its explicit
// for simplictiy create our own silly little namespace std;
// good portable, stdlib param and return
// good portable low level types
// not portable, two warnings, function and parameter are abstract and not stdlib
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
// 65) Customize intentionally and explicitly.
CCS - CC++ Function Definition: f65
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
// 95. Type Safety. - Don't use C-style casts.
// bad, don't use old style c casting
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
96) Don't memcpy or memcmp non-PODs.
CCS - CC++ Function Definition: f96
// bad 96, don't use memcpy
// bad 96, don't use memcmp
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
// 97) Don't use unions to reinterpret representation.
CCS - CC++ Function Definition: f97
// bad 97
// bad 97
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
98) Don't use varargs (ellipsis).
// bad 98, ...
ABRAXAS SOFTWARE - CodeCheck CCS Test-Suite CCS
99) Don't use invalid objects. Don't use unsafe functions.
CCS - CC++ Function Definition: m99
// bad 99, don't use unsafe functions