Skip to content

Commit ca96f8c

Browse files
committed
docs for gsl::suppress
1 parent 4132e72 commit ca96f8c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

docs/cpp/attributes.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,18 @@ The `[[noreturn]]` attribute specifies that a function never returns; in other w
7777

7878
## Microsoft-specific attributes
7979

80-
### `[[gsl::suppress(rules)]]`
80+
### `[[gsl::suppress(<tag> [, justification: <narrow-string-literal>])]]`
8181

82-
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:
8385

8486
```cpp
8587
int main()
8688
{
8789
int arr[10]; // GSL warning C26494 will be fired
8890
int* p = arr; // GSL warning C26485 will be fired
89-
[[gsl::suppress(bounds.1)]] // This attribute suppresses Bounds rule #1
91+
[[gsl::suppress("bounds.1", justification: "This attribute suppresses Bounds rule #1")]]
9092
{
9193
int* q = p + 1; // GSL warning C26481 suppressed
9294
p = q--; // GSL warning C26481 suppressed
@@ -102,7 +104,7 @@ The example raises these warnings:
102104

103105
- [C26481](../code-quality/c26481.md) (Bounds Rule 1: Don't use pointer arithmetic. Use span instead.)
104106

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

107109
### `[[msvc::flatten]]`
108110

0 commit comments

Comments
 (0)