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

Rule:  PCA#010Checked automatically with code checker

Synopsis:Do not use unions with non-POD types
Severity Level:6
Category:Parts of C++ to Avoid


C++11 gave us the possibility to use non-POD types within unions. E.g.

    T one;
    V two;
} foo; 

If you use these kind of unions you are mostly on your own, e.g. concerning deletion of union objects and how to determine what the default value will be. A note in the C++ standard explains this (9.5/2): "If any non-static data member of a union has a non-trivial default constructor (12.1), copy constructor (12.8), move constructor (12.8), copy assignment operator (12.8), move assignment operator (12.8), or destructor (12.4), the corresponding member function of the union must be user-provided or it will be implicitly deleted (8.4.3) for the union."

Literature References: