AutosarC++18_03-A0.1.4¶
There shall be no unused named parameters in non-virtual functions
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
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 <string>
#include <type_traits>
// 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 [10]: 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¶
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_address_taken_functions¶
ignore_address_taken_functions : bool = False
inspect_constexprs¶
inspect_constexprs : bool = False
inspect_nonvirtual_functions¶
inspect_nonvirtual_functions : bool = True
inspect_virtual_functions¶
inspect_virtual_functions : bool = False
inspect_virtual_functions_directly¶
inspect_virtual_functions_directly : bool = False
report_all_virtual_functions¶
report_all_virtual_functions : bool = False
report_unnamed_parameters¶
report_unnamed_parameters : bool = False
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.
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.