AutosarC++19_03-A13.2.2

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

Required inputs: IR

Binary arithmetic and bitwise operators should return a basic value (an unqualified, non-pointer, non-reference type) rather than pointers, references, or qualified types. Returning a reference to a member or a const-qualified value results in hard-to-use interfaces and can cause unexpected behavior.
Bad code (returning reference to member):
class MyInt {
    int value_;
public:
    int& operator+(int rhs) {  // ERROR: returns reference to member
        value_ += rhs;
        return value_;
    }
};
Bad code (returning const qualified):
class MyInt {
    int value_;
public:
    const int operator+(int rhs) {  // ERROR: returns const int
        return value_ + rhs;
    }
};
Good code (returning basic value):
class MyInt {
    int value_;
public:
    int operator+(int rhs) { return value_ + rhs; }  // OK: returns by value
};

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<<.