TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
C++ Coding Standard
Search

Category: Object Life Cycle

Synopsis:Initialization and Copying


Description:
This chapter concerns the declaring, initializing and copying of objects. These guidelines increase robustness and readability of the code. Furthermore, they may also improve the performance.

Coding Rules

NameCheckedSynopsis
I.2 Checked automatically with code checker Avoid non-const global variables
OLC#001 Checked automatically with code checker If objects of a class should never be copied, then the copy constructor and the copy assignment operator shall be declared as deleted functions
OLC#002 Checked automatically with code checker Copy assignment operators shall be implemented with the swap idiom
OLC#003 Checked automatically with code checker A function must never return, or in any other way give access to, references or pointers to local variables outside the scope in which they are declared
OLC#004 Checked automatically with code checker Every variable of a built-in type that is declared is to be given a value before it is used
OLC#005 Checked automatically with code checker Don't call virtual functions in constructors and destructors
OLC#006 Checked automatically with code checker Variables and types are to be declared with the smallest possible scope
OLC#007 Use direct- instead of copy-initialization in object declarations of class type
OLC#008 If it must be possible to instantiate a class via a default constructor, always define a default constructor which explicitly initializes data members
OLC#009 Checked automatically with code checker Literals should be used only on the definition of constants and enumerations
OLC#010 Checked automatically with code checker Declare each variable in a separate declaration statement
OLC#011 Avoid unnecessary copying of objects that are costly to copy
OLC#012 Checked automatically with code checker Do not initialise static variables with other (external) static variables
OLC#013 Checked automatically with code checker Data members do not have to be reset in a destructor
OLC#014 Minimize the number of temporary objects that are created as return values from methods/functions or as arguments to methods/functions
OLC#015 Checked automatically with code checker A variable must be initialized within the scope of its usage
OLC#016 Checked automatically with code checker Do not re-declare a visible name in a nested scope
OLC#017 Checked automatically with code checker Initialize all data members of built-in types
OLC#018 Checked automatically with code checker Let the order of the initializer list be: first base class constructor(s), then data members in the same order of declaration as in the header file
OLC#019 Checked automatically with code checker If passing the "this" pointer to a constructor initializer list, be aware that the object is not yet fully constructed
OLC#020 Checked automatically with code checker Don't pass member variables to the base class in the constructor's initializer list
OLC#021 Checked automatically with code checker Initialize atomic variables correctly
R.35 Checked automatically with code checker Take a shared_ptr<widget>& parameter to express that a function might reseat the shared pointer
R.37 Checked automatically with code checker Do not pass a pointer or reference obtained from an aliased smart pointer