conditionally unused parameters can be declared using maybe_unused attribute. (#1863)

* conditionally unused parameters can be declared using maybe_unused attribute.

* move to Notes and add example

* whitespace?

* ok got the whitespace

* adjust example
This commit is contained in:
apenn-msft
2022-02-10 13:34:32 -08:00
committed by GitHub
parent eb2f4d7756
commit ead60212f3

View File

@@ -2849,12 +2849,24 @@ Suppression of unused parameter warnings.
##### Example ##### Example
X* find(map<Blob>& m, const string& s, Hint); // once upon a time, a hint was used widget* find(const set<widget>& s, const widget& w, Hint); // once upon a time, a hint was used
##### Note ##### Note
Allowing parameters to be unnamed was introduced in the early 1980 to address this problem. Allowing parameters to be unnamed was introduced in the early 1980 to address this problem.
If parameters are conditionally unused, declare them with the `[[maybe_unused]]` attribute.
For example:
template <typename Value>
Value* find(const set<Value>& s, const Value& v, [[maybe_unused]] Hint h)
{
if constexpr (sizeof(Value) > CacheSize)
{
// a hint is used only if Value is of a certain size
}
}
##### Enforcement ##### Enforcement
Flag named unused parameters. Flag named unused parameters.