MISRA C++:2008 Rule 12-1-3
All constructors that are callable with a single argument of fundamental type shall be declared explicit
Description
Rule Definition
All constructors that are callable with a single argument of fundamental type shall be declared explicit.
Rationale
Class constructors that are callable with a single argument of a fundamental type can be
inadvertently invoked by the compiler to convert a fundamental type variable into the class.
Such implicit conversion can occur in unexpected places, resulting in unexpected behavior.
Declare constructors that are callable with a single argument of fundamental type as
explicit
.
Polyspace Implementation
Polyspace® reports a violation of this rule if a constructor satisfies all these conditions:
The constructor has a single argument, or one argument that is not default initialized.
The single argument or the argument that is not default initialized has a fundamental type, such as integral types, floating point types, and
void
types.The constructor is not declared as
explicit
.
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Special Member Functions |
Category: Required |
Version History
Introduced in R2013b