AutosarC++18_10-A13.2.2¶
A binary arithmetic operator and a bitwise operator shall return a “prvalue”
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
Rationale
Returning a type “T” from binary arithmetic and bitwise operators is consistent with the C++ Standard Library.
See: prvalue.
Example
// $Id: A13-2-2.cpp 271687 2017-03-23 08:57:35Z piotr.tanski $
#include <cstdint>
class A
{
};
A operator+(A const&, A const&) noexcept // Compliant
{
return A{};
}
std::int32_t operator/(A const&, A const&) noexcept // Compliant
{
return 0;
}
A operator&(A const&, A const&)noexcept // Compliant
{
return A{};
}
const A operator-(A const&, std::int32_t) noexcept // Non-compliant
{
return A{};
}
A* operator|(A const&, A const&) noexcept // Non-compliant
{
return new A{};
}
See Also
- HIC++ v4.0 [9]: 13.2.2 Ensure that the return type of an overloaded binary operator matches the built-in counterparts.
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
arith_bitwise_basic_value |
Binary arithmetic or bitwise operator shall return a basic 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
allow_bitwise_shift¶
allow_bitwise_shift : bool = True
operator>> or
operator<<.