AutosarC++17_03-A13.2.3¶
A relational operator shall return a boolean value
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
Rationale
Returning a type “bool” from a relational operator is consistent with the C++ Standard Library.
Example
// $Id: A13-2-3.cpp 271687 2017-03-23 08:57:35Z piotr.tanski $
#include <cstdint>
class A {};
bool operator==(A const &, A const &) noexcept // Compliant
{
return true;
}
bool operator<(A const &, A const &) noexcept // Compliant
{
return false;
}
bool operator!=(A const &lhs, A const &rhs) noexcept // Compliant
{
return !(operator==(lhs, rhs));
}
std::int32_t operator>(A const &, A const &) noexcept // Non-compliant
{
return -1;
}
A operator>=(A const &, A const &) noexcept // Non-compliant
{
return A{};
}
const A &operator<=(A const &lhs, A const &rhs) noexcept // Non-compliant
{
return lhs;
}
See Also
- HIC++ v4.0 [8]: 13.2.2 Ensure that the return type of an overloaded binary operator matches the built-in counterparts.
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
relational_bool |
A relational operator shall return a boolean value. |
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
This rule has no individual options.