Qt-Autosar-A13.2.2

A binary arithmetic operator and a bitwise operator shall return a “prvalue”

Required inputs: IR

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

allow_bitwise_shift

allow_bitwise_shift : bool = True

Whether to allow non-basic values for operator>> or operator<<.