Skip to content

Commit 543d0dd

Browse files
authored
export proper syntax for GSL_SUPPRESS for new VS (#1213)
A new Visual Studio version will soon be available that deprecates the old syntax for gsl::suppress. Customers will now get a C4875 diagnostic on suppressions that look like `gsl::suppress(x)` urging them to use `gsl::suppress("x")` instead. This change updates the `GSL_SUPPRESS` macro to preprocess GSL_SUPPRESS(x) to gsl::suppress("x") on clang and new versions of MSVC.
1 parent 494e6e9 commit 543d0dd

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ dyn_array | &#x26
4949
move_owner | ☐ | A helper function that moves one `owner` to the other
5050
[final_action](docs/headers.md#user-content-H-util-final_action) | ☑ | A RAII style class that invokes a functor on its destruction
5151
[finally](docs/headers.md#user-content-H-util-finally) | ☑ | A helper function instantiating [final_action](docs/headers.md#user-content-H-util-final_action)
52-
[GSL_SUPPRESS](docs/headers.md#user-content-H-assert-gsl_suppress) | ☑ | A macro that takes an argument and turns it into `[[gsl::suppress(x)]]` or `[[gsl::suppress("x")]]`
52+
[GSL_SUPPRESS](docs/headers.md#user-content-H-assert-gsl_suppress) | ☑ | A macro that takes an argument and turns it into `[[gsl::suppress(x)]]` or `[[gsl::suppress("x")]]` depending on the compiler.
5353
[[implicit]] | ☐ | A "marker" to put on single-argument constructors to explicitly make them non-explicit
5454
[index](docs/headers.md#user-content-H-util-index) | ☑ | A type to use for all container and array indexing (currently an alias for `std::ptrdiff_t`)
5555
[narrow](docs/headers.md#user-content-H-narrow-narrow) | ☑ | A checked version of `narrow_cast`; it can throw [narrowing_error](docs/headers.md#user-content-H-narrow-narrowing_error)

docs/headers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ See [GSL.assert: Assertions](https://isocpp.github.io/CppCoreGuidelines/CppCoreG
4949
This macro can be used to suppress a code analysis warning.
5050
5151
The core guidelines request tools that check for the rules to respect suppressing a rule by writing
52-
`[[gsl::suppress(tag)]]` or `[[gsl::suppress(tag, justification: "message")]]`.
52+
`[[gsl::suppress("tag")]]` or `[[gsl::suppress("tag", justification: "message")]]`.
5353
54-
Clang does not use exactly that syntax, but requires `tag` to be put in double quotes `[[gsl::suppress("tag")]]`.
54+
Older versions of MSVC (VS 2022 and earlier) only understand `[[gsl::suppress(tag)]]` without the double quotes around `tag`.
5555
5656
For portable code you can use `GSL_SUPPRESS(tag)`.
5757

include/gsl/assert

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@
4747
//
4848
#if defined(__clang__)
4949
#define GSL_SUPPRESS(x) [[gsl::suppress(#x)]]
50-
#else
51-
#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__NVCC__)
52-
#define GSL_SUPPRESS(x) [[gsl::suppress(x)]]
50+
#elif defined(_MSC_VER) && _MSC_VER >= 1950
51+
// Visual Studio versions after 2022 (_MSC_VER > 1944) support the justification message.
52+
#define GSL_SUPPRESS(x) [[gsl::suppress(#x)]]
53+
#elif defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__NVCC__)
54+
#define GSL_SUPPRESS(x) [[gsl::suppress(#x)]]
5355
#else
5456
#define GSL_SUPPRESS(x)
55-
#endif // _MSC_VER
56-
#endif // __clang__
57+
#endif // defined(__clang__)
5758

5859
#if defined(__clang__) || defined(__GNUC__)
5960
#define GSL_LIKELY(x) __builtin_expect(!!(x), 1)

0 commit comments

Comments
 (0)