Unused parameters are misleading. Whatever the values passed to such parameters, the behavior will be the same. 


There are some cases when you want to have an unused parameter (usually because the function has to conform to a fixed prototype, because it is virtual or it is going to 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.


----
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.

== Noncompliant Code Example

----
void doSomething(int a, int b) { // Noncompliant, "b" is unused
  compute(a);
}
----

== Compliant Solution

----
void doSomething(int a) {
  compute(a);
}
----

== See

* 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
* https://github.com/isocpp/CppCoreGuidelines/blob/036324/CppCoreGuidelines.md#f9-unused-parameters-should-be-unnamed[{cpp} Core Guidelines - F.9] - Unused parameters should be unnamed

ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)

include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]
