AutosarC++18_10-A13.5.2¶
All user-defined conversion operators shall be defined explicit
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
Rationale
Without explicit keyword, a single user defined conversion can be invoked in a standard conversion sequence, which can lead to accidental errors.
Example
// $Id: A13-5-2.cpp 303121 2018-01-09 09:03:52Z michal.szczepankiewicz $
class A
{
public:
explicit A(double d) : d(d) {}
explicit operator double() const { return d; } // Compliant
private:
double d;
};
int main(void)
{
A a{3.1415926535897932384626433832795028841971693993751058209749445923078};
double tmp1{a};
// float tmp2{a}; //compilation error instead of warning, prevents from data
// precision loss
return 0;
}
See Also
- HIC++ v4.0 [9]: 12.1.1: Do not declare implicit user defined conversions.
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
user_defined_conversion_explicit |
All user-defined conversion operators shall be defined explicit. |
None |
False |
Options¶
This rule shares the following common options: confidence, exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
suppress_conditionally_explicit¶
suppress_conditionally_explicit : bool = True