MISRAC++2008-12-1-3 (C++ only)
In this section:
Synopsis
(Required) All constructors that are callable with a single argument of fundamental type shall be declared explicit.
Enabled by default
Yes
Severity/Certainty
Low/Medium

Full description
Constructors that can be called with a single argument are not declared explicit. Conversion operators shall also be set explicit. This check is identical to CPU-ctor-implicit, MISRAC++2023-15.1.3.
Coding standards
- CERT OOP32-CPP
Ensure that single-argument constructors are marked "explicit"
- MISRA C++ 2023 15.1.3
(Required) Conversion operators and constructors that are callable with a single argument shall be explicit
Code examples
The following code example fails the check and will give a warning:
class C{
C(double x){} //should be explicit
};
The following code example passes the check and will not give a warning about this issue:
class C{
explicit C(double x){} //OK
};