From ead60212f347416bd255ec5eddc55dfb4435d58c Mon Sep 17 00:00:00 2001 From: apenn-msft <62863214+apenn-msft@users.noreply.github.com> Date: Thu, 10 Feb 2022 13:34:32 -0800 Subject: [PATCH] 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 --- CppCoreGuidelines.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 77e21c7..b0b0c9c 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -2849,12 +2849,24 @@ Suppression of unused parameter warnings. ##### Example - X* find(map& m, const string& s, Hint); // once upon a time, a hint was used + widget* find(const set& 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 + Value* find(const set& 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.