mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2025-12-17 04:44:34 +03:00
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:
@@ -2849,12 +2849,24 @@ Suppression of unused parameter warnings.
|
||||
|
||||
##### 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
|
||||
|
||||
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
|
||||
|
||||
Flag named unused parameters.
|
||||
|
||||
Reference in New Issue
Block a user