AutosarC++18_03-A3.1.6¶
Trivial accessor and mutator functions should be inlined
Required inputs: IR
| Level | advisory |
|---|---|
| Target | design |
| Enforcement | automated |
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¶
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
exclude_constructor_destructors¶
exclude_constructor_destructors : bool = True
exclude_operator_functions¶
exclude_operator_functions : bool = False
exclude_virtual_functions¶
exclude_virtual_functions : bool = True
require_this_read_write¶
require_this_read_write : bool = False