AutosarC++18_10-A0.1.4

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

Required inputs: IR

Rationale

Unused named parameters are often a result of a design changes and can lead to mismatched parameter lists.

Note: This rule does not apply to unnamed parameters, as they are widely used in SFINAE and concept compliance.

Example
//% $Id: A0-1-4.cpp 305588 2018-01-29 11:07:35Z michal.szczepankiewicz $

    #include <type_traits>
    #include <string>

    //Logger.hpp
    class Logger
    {
    public:
        struct console_t {};
        struct file_t {};

         constexpr static console_t console = console_t();
         constexpr static file_t file = file_t();

         void init(console_t);
         void init(file_t, const std::string& prefix);
    };

    //Logger.cpp
    void Logger::init(console_t)
    {
    //initialization for a console logger
    }
    void Logger::init(file_t, const std::string& prefix)
    {
    //initialization for a file logger for a given prefix path
    }

    //Message.h
    struct MessagePolicy {};
    struct WriteMessagePolicy final : public MessagePolicy { };

    template <typename T> struct is_mutable : std::false_type {};
    template <> struct is_mutable<WriteMessagePolicy> : std::true_type {};

    template <typename T, typename Policy = MessagePolicy>
    class Message
    {
    public:
        static_assert(std::is_base_of<MessagePolicy, Policy>::value == true, "Givenparameter is not derived from MessagePolicy");
        using value_type = T;

         template<typename U = void>
         void set(T&& u, typename std::enable_if<is_mutable<Policy>::value, U>::type*= 0)
         {
              v = u;
         }

    private:
        value_type v;
    };

    int main(int, char**)
    {
        Logger log;
        log.init(Logger::console);
        log.init(Logger::file, std::string("/tmp/"));

         Message<uint8_t> read;
         Message<uint8_t, WriteMessagePolicy> write;

         //read.set(uint8_t(12)); Compilation error
         write.set(uint8_t(12));

         return 0;
    }
See Also
  • C++ Core Guidelines [11]: F.9: Unused parameters should be unnamed

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

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.
 

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.