== Why is this an issue?

include::../description.adoc[]

=== Exceptions

There are some cases when you want to have an unused parameter (usually because the function has to conform to a fixed prototype, or because it is virtual, or it will be called from a template). In this case, and if the parameter is never used, an accepted practice is to leave it unnamed. If it is only sometimes used (for instance, depending on conditional compilation), you may, since {cpp}17, use the ``\[[maybe_unused]]`` attribute to be explicit about it.

[source,cpp]
----
void f([[maybe_unused]] int i) {
  assert(i < 42); // In optimized mode, this assert will be removed, and "i" will be unused
}
----

In case of Objective-C, it is acceptable to have unused parameters if the method is supposed to be overridden. Additionally, since Objective-C blocks don't allow unnamed parameters while they are typically used as callbacks, it is acceptable to have unused parameters in blocks.

== How to fix it

include::../how-to-fix-it.adoc[]

=== Code examples

==== Noncompliant code example

[source,cpp,diff-id=1,diff-type=noncompliant]
----
void doSomething(int a, int b) { // Noncompliant, "b" is unused
  compute(a);
}
----

==== Compliant solution

[source,cpp,diff-id=1,diff-type=compliant]
----
void doSomething(int a) {
  compute(a);
}
----

== Resources

* MISRA {cpp}:2008, 0-1-11 - There shall be no unused parameters (named or unnamed) in nonvirtual functions.
* MISRA C:2012, 2.7 - There should be no unused parameters in functions
* https://wiki.sei.cmu.edu/confluence/x/5dUxBQ[CERT, MSC12-C.] - Detect and remove code that has no effect or is never executed
* {cpp} Core Guidelines - https://github.com/isocpp/CppCoreGuidelines/blob/e49158a/CppCoreGuidelines.md#f9-unused-parameters-should-be-unnamed[F.9: Unused parameters should be unnamed]

ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

include::../message.adoc[]

'''
== Comments And Links
(visible only on this page)

include::../comments-and-links.adoc[]

endif::env-github,rspecator-view[]
