You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The C++ Core Guidelines are there to help you write better and safer code. However, you might find an instance where a rule or a profile shouldn't be applied. It's easy to suppress it directly in the code. You can use the `[[gsl::suppress]]` attribute to keep C++ Core Check from detecting and reporting any violation of a rule in the following code block. You can mark individual statements to suppress specific rules. You can even suppress the entire bounds profile by writing `[[gsl::suppress(bounds)]]` without including a specific rule number.
107
+
The C++ Core Guidelines are there to help you write better and safer code. However, you might find an instance where a rule or a profile shouldn't be applied. It's easy to suppress it directly in the code. You can use the `[[gsl::suppress]]` attribute to keep C++ Core Check from detecting and reporting any violation of a rule in the following code block. You can mark individual statements to suppress specific rules. You can even suppress the entire bounds profile by writing `[[gsl::suppress("bounds")]]` without including a specific rule number.
108
108
109
109
## Supported rule sets
110
110
@@ -197,10 +197,10 @@ The Microsoft C++ compiler has limited support for the `[[gsl::suppress]]` attri
197
197
198
198
```cpp
199
199
// Suppress only warnings from the 'r.11' rule in expression.
200
-
[[gsl::suppress(r.11)]] newint;
200
+
[[gsl::suppress("r.11")]] newint;
201
201
202
202
// Suppress all warnings from the 'r' rule group (resource management) in block.
203
-
[[gsl::suppress(r)]]
203
+
[[gsl::suppress("r")]]
204
204
{
205
205
new int;
206
206
}
@@ -209,7 +209,7 @@ The Microsoft C++ compiler has limited support for the `[[gsl::suppress]]` attri
209
209
// For declarations, you might need to use the surrounding block.
210
210
// Macros are not expanded inside of attributes.
211
211
// Use plain numbers instead of macros from the warnings.h.
The Microsoft-specific `[[gsl::suppress(rules)]]` attribute is used to suppress warnings from checkers that enforce [Guidelines Support Library (GSL)](https://github.com/Microsoft/GSL) rules in code. For example, consider this code snippet:
82
+
`<tag>` is a string that specifies the name of the rule to suppress. The optional `justification` field allows you to explain why a warning is being disabled or suppressed. This value will appear in the SARIF output when the `/analyze:log:includesuppressed` option is specified. Its value is a UTF-8 encoded narrow string literal. The `[[gsl::suppress]]` attribute is available in Visual Studio 2022 version 17.14 and later versions.
83
+
84
+
The Microsoft-specific `[[gsl::suppress]]` attribute is used to suppress warnings from checkers that enforce [Guidelines Support Library (GSL)](https://github.com/Microsoft/GSL) rules in code. For example, consider this code snippet:
83
85
84
86
```cpp
85
87
intmain()
86
88
{
87
89
int arr[10]; // GSL warning C26494 will be fired
88
90
int* p = arr; // GSL warning C26485 will be fired
89
-
[[gsl::suppress(bounds.1)]] // This attribute suppresses Bounds rule #1
@@ -102,7 +104,7 @@ The example raises these warnings:
102
104
103
105
-[C26481](../code-quality/c26481.md) (Bounds Rule 1: Don't use pointer arithmetic. Use span instead.)
104
106
105
-
The first two warnings fire when you compile this code with the CppCoreCheck code analysis tool installed and activated. But the third warning doesn't fire because of the attribute. You can suppress the entire bounds profile by writing `[[gsl::suppress(bounds)]]` without including a specific rule number. The C++ Core Guidelines are designed to help you write better and safer code. The suppress attribute makes it easy to turn off the warnings when they aren't wanted.
107
+
The first two warnings fire when you compile this code with the CppCoreCheck code analysis tool installed and activated. But the third warning doesn't fire because of the attribute. You can suppress the entire bounds profile by writing `[[gsl::suppress("bounds")]]` without including a specific rule number. The C++ Core Guidelines are designed to help you write better and safer code. The suppress attribute makes it easy to turn off the warnings when they aren't wanted.
@@ -26,17 +26,26 @@ The following warning-specifier parameters are available.
26
26
|--|--|
27
27
|`1`, `2`, `3`, `4`| Apply the given level to the specified warnings. Also turns on a specified warning that is off by default. |
28
28
|`default`| Reset warning behavior to its default value. Also turns on a specified warning that is off by default. The warning will be generated at its default, documented, level.<br /><br /> For more information, see [Compiler warnings that are off by default](../preprocessor/compiler-warnings-that-are-off-by-default.md). |
29
-
|`disable`| Don't issue the specified warning messages. |
29
+
|`disable`| Don't issue the specified warning messages. The optional **`justification`** property is allowed. |
30
30
|`error`| Report the specified warnings as errors. |
31
31
|`once`| Display the specified message(s) only one time. |
32
-
|`suppress`| Pushes the current state of the pragma on the stack, disables the specified warning for the next line, and then pops the warning stack so that the pragma state is reset. |
32
+
|`suppress`| Pushes the current state of the pragma on the stack, disables the specified warning for the next line, and then pops the warning stack so that the pragma state is reset. The optional **`justification`** property is allowed. |
33
33
34
34
The following code statement illustrates that a *`warning-number-list`* parameter can contain multiple warning numbers, and that multiple *`warning-specifier`* parameters can be specified in the same pragma directive.
However, when the **`justification`** field is present, only one warning number can be specified. The following code statement illustrates the use of the **`justification`** field.
The **`justification`** fields allows you to explain why a warning is being disable or
47
+
suppressed. The **`justification`** field is only supported for the **`disable`** and **`suppress`***`warning-specifier`*. This value will appear in the SARIF output when the `/analyze:log:includesuppressed` option is specified. Its value is a UTF-8 encoded narrow string literal.
48
+
40
49
This directive is functionally equivalent to the following code:
0 commit comments