AutosarC++17_10-A0.1.3¶
Every function defined in an anonymous namespace, or static function with internal linkage, or private member function shall be used
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
Rationale
Functions which are not callable from outside the compilation unit in which they are defined, or from outside the class implementation to which they pertain, and which are not used may be symptomatic of serious problems, such as poor software design or missing paths in flow control.
This rule enforces developers to statically and explicitly use every such function in the source code. A function does not necessarily need to be called at run-time. Rule M0-1-1 detects all unreachable code occurrences.
Note that this rule applies equally to static and non-static private member functions.
Example
//% $Id: A0-1-3.cpp 291350 2017-10-17 14:31:34Z jan.babst $
#include <cstdint>
static void F1() // Compliant
{}
namespace {
void F2() // Non-compliant, defined function never used
{}
} // namespace
class C {
public:
C() : x(0) {}
void M1(std::int32_t i) // Compliant, member function is used
{
x = i;
}
void M2(std::int32_t i,
std::int32_t j) // Compliant, never used but declared
// as public
{
x = (i > j) ? i : j;
}
protected:
void M1ProtectedImpl(std::int32_t j) // Compliant, never used but declared
// as protected
{
x = j;
}
private:
std::int32_t x;
void M1PrivateImpl(
std::int32_t j) // Non-compliant, private member function never used
{
x = j;
}
};
int main(int, char **) {
F1();
C c;
c.M1(1);
return 0;
}
See Also
- MISRA C++ 2008 [6]: Rule 0-1-10 required Every defined function shall be called at least once.
- HIC++ v4.0 [8]: 1.2.2 Ensure that no expression or sub-expression is redundant.
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
declared_function_not_called |
Declared function is not called |
None |
False |
defined_function_not_called |
Defined function is not called |
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
ignore_copy_assignment_operators¶
ignore_copy_assignment_operators : bool = False
Other rules like the "rule of three" might require copy assignment operators as part of good class design, even if there are currently no callers of the copy assignment operator.
ignore_copy_constructors¶
ignore_copy_constructors : bool = False
Other rules like the "rule of three" might require copy constructors as part of good class design, even if there are currently no callers of the copy constructor.
ignore_move_assignment_operators¶
ignore_move_assignment_operators : bool = False
Other rules like the "rule of three" might require move assignment operators as part of good class design, even if there are currently no callers of the move assignment operator.
ignore_move_constructors¶
ignore_move_constructors : bool = False
Other rules like the "rule of three" might require move constructors as part of good class design, even if there are currently no callers of the move constructor.
only_check_defined_functions¶
only_check_defined_functions : bool = True
only_check_internal_or_private_methods¶
only_check_internal_or_private_methods : bool = True
only_check_static_or_private_methods¶
only_check_static_or_private_methods : bool = False
only_check_unit_locals¶
only_check_unit_locals : bool = False
Note: this option is automatically activated during single-file analysis.
suppress_attribute_maybe_unused¶
suppress_attribute_maybe_unused
Filter action to apply to violations for objects marked asType: FilterAction
Default:
'suppress'
[[maybe_unused]] or __attribute__((unused)).
If set to "suppress", findings will be reported but marked as suppressed.
If set to "exclude", findings will not be reported at all.
If set to "normal", no special treatment is applied and the finding is reported as usual.
visibility¶
visibility
Describes which functions should be checked for being uncalled as a disjunction of conditions where list elements may be conjunctions given as sublists. If the list is empty no restrictions apply apart those given by the shortcut options only_check_static_or_private_methods or only_check_internal_or_private_methods.Type: list[list[Visibility] | Visibility]
Default:
[]
Option Types¶
These types are used by options listed above:
FilterAction¶
Used for the return value of add_filter() callbacks.normal
The violation proceeds as usual.exclude
The violation is excluded: The violation is discarded as if `--exclude` applied to it. The following filters won't get to see the violation, and it will not be imported into the database under any circumstances.suppress
The violation is suppressed as if `AXIVION DISABLE` applied to it. Whether the violation gets imported into the database is controlled by the Axivion CI configuration.Visibility¶
PRIVATE
STATIC
NON_VIRTUAL
IN_ANONYMOUS_NAMESPACE