AutosarC++18_03-A3.1.6

Trivial accessor and mutator functions should be inlined

Required inputs: IR

Rationale

Inlining trivial accessors and mutators saves time and space, as it reduces multiple syntax elements that has to be repeated.

Example
//% $Id: A3-1-6.cpp 305629 2018-01-29 13:29:25Z piotr.serwa $
#include <cstdint>

class A {
public:
  A(std::int32_t l) noexcept : limit{l} {}
  // compliant
  std::int32_t Limit() const noexcept { return limit; }
  // compliant
  void SetLimit(std::int32_t l) { limit = l; }

  // non-compliant
  // std::int32_t Limit() const noexcept
  //{
  // open file, read data, close file
  // return value
  //}
  // non-compliant
  // void SetLimit(std::int32_t l)
  //{
  // open file, write data, close file
  //}

private:
  std::int32_t limit;
};
See Also
  • JSF December 2005 [7]: AV Rule 122: Trivial accessor and mutator functions should be inlined.

Possible Messages

Key

Text

Severity

Disabled

missing_inline

Trivial accessor and mutator functions should be inlined.

None

False

Options

exclude_constructor_destructors

exclude_constructor_destructors : bool = True

Whether to exclude constructors/destructors from inspected functions.
 

exclude_operator_functions

exclude_operator_functions : bool = False

Whether to exclude operator functions from inspected functions.
 

exclude_virtual_functions

exclude_virtual_functions : bool = True

Whether to exclude virtual functions from inspected functions.
 

require_this_read_write

require_this_read_write : bool = False

Whether to require a read/write on this for a function to be considered a trivial accessor/mutator.