Qt-Autosar-A0.1.4

There shall be no unused named parameters in non-virtual functions

Required inputs: IR

Unused function parameters clutter the code and confuse readers about the function's interface. They may indicate incomplete refactoring or mistakes in the function implementation. Removed or unused parameters should be either removed entirely (if not required by an interface) or marked with mechanisms to indicate they are intentionally unused (like [[maybe_unused]] in C++17).
Bad code (unused parameter):
void ProcessData(int data, int unused) {  // ERROR: unused parameter
    std::cout << "Data: " << data << std::endl;
}

struct Foo {
    virtual void VirtualFunc(const std::string& arg) {
        // ERROR: parameter is unused here and in every overridden function
        std::cout << "Virtual function called" << std::endl;
    }
};

struct Bar : public Foo {
    void VirtualFunc(const std::string& arg) override {
        std::cout << "Overridden function called" << std::endl;
    }
};
Good code (parameter removed when not needed):
void ProcessData(int data) {  // OK: only needed parameters
    std::cout << "Data: " << data << std::endl;
}
Good code (using (void) cast for C and older C++):
void Callback(int i) {
    (void)i;  // OK: clearly intentional, works in C and C++
    ProcessEvent();
}
Good code (using C++17 [[maybe_unused]]):
struct Foo {
    virtual void VirtualFunc([[maybe_unused]] const std::string& arg) {
        // OK: explicitly marked as intentionally unused
        std::cout << "Virtual function called" << std::endl;
    }
};
Good code (using unnamed parameter):
void Callback(int /*unused_parameter*/) {  // OK: clearly intentional
    ProcessEvent();
}

Possible Messages

Key

Text

Severity

Disabled

unused_parameter

Unused named parameter of non-virtual function

None

False

Options

ignore_address_taken_functions

ignore_address_taken_functions : bool = False

Ignore parameters of functions that had their address taken.
 

inspect_constexprs

inspect_constexprs : bool = False

If enabled, more unused parameters may be detected by evaluating if-constexpr blocks, particularly in template instances.
 

inspect_nonvirtual_functions

inspect_nonvirtual_functions : bool = True

Whether parameters of non-virtual functions should be checked.
 

inspect_virtual_functions

inspect_virtual_functions : bool = False

Whether virtual functions should be checked.
 

inspect_virtual_functions_directly

inspect_virtual_functions_directly : bool = False

Whether parameters of virtual functions should be checked regardless of further refinements using a yet unused parameter. This is the MISRA policy.
 

report_all_virtual_functions

report_all_virtual_functions : bool = False

If enabled, violations for virtual functions will be reported for all definitions. This option only applies if inspect_virtual_functions is enabled.
 

report_unnamed_parameters

report_unnamed_parameters : bool = False

Whether unnamed unused parameters should be reported as well.
 

suppress_attribute_maybe_unused

suppress_attribute_maybe_unused : FilterAction = '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.
 

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.