AutosarC++19_03-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

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
      {
      }
    }

    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 [7]: Rule 0-1-10 Every defined function shall be called at least once.
  • HIC++ v4.0 [9]: 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

ignore_copy_assignment_operators

ignore_copy_assignment_operators : bool = False

Whether uncalled copy assignment operators are allowed.

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

Whether uncalled copy constructors are allowed.

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

Whether uncalled move assignment operators are allowed.

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

Whether uncalled move constructors are allowed.

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

Whether only defined functions should be checked for being uncalled.
 

only_check_internal_or_private_methods

only_check_internal_or_private_methods : bool = True

Whether only function with internal linkage or private functions should be checked for being uncalled. This is a shortcut for a visibility.
 

only_check_static_or_private_methods

only_check_static_or_private_methods : bool = False

Whether only static functions or private functions should be checked for being uncalled. This is a shortcut for a visibility.
 

only_check_unit_locals

only_check_unit_locals : bool = False

Whether only global static functions should be checked for being uncalled.

Note: this option is automatically activated during single-file analysis.

 

suppress_attribute_maybe_unused

suppress_attribute_maybe_unused

Type: FilterAction

Default: 'suppress'

Filter action to apply to violations for objects marked as [[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

Type: list[list[Visibility] | Visibility]

Default: []

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.
 

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