CppCoreGuidelines icon indicating copy to clipboard operation
CppCoreGuidelines copied to clipboard

Make `tag` in `gsl::suppress(tag)` be a string literal

Open dmitrykobets-msft opened this issue 3 years ago • 1 comments

The current specification In.force: Enforcement explicitly requires "message" in [[gsl::suppress(tag, justification: "message")]] to be a string literal, but doesn't require tag to be a string literal i.e., [[gsl::suppress("tag", justification: "message")]].

If tag were a string literal, then parsing it would not lose any information. Otherwise, parsing has limitations (https://eel.is/c%2B%2Bdraft/dcl.attr), for instance treating the .11 inside gsl::suppress(R.11) as a floating point literal 0.110000.

Clang already requires tag to be a string, rejecting something like [[gsl::suppress(R.11)]], requiring [[gsl::suppress("R.11")]]. The current GSL implementation therefore needs to special-case this:

//
// make suppress attributes parse for some compilers
// Hopefully temporary until suppression standardization occurs
//
#if defined(__clang__)
#define GSL_SUPPRESS(x) [[gsl::suppress("#x")]]
#else
#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__NVCC__)
#define GSL_SUPPRESS(x) [[gsl::suppress(x)]]
#else
#define GSL_SUPPRESS(x)
#endif // _MSC_VER
#endif // __clang__

dmitrykobets-msft avatar Feb 17 '23 19:02 dmitrykobets-msft

Editors call: We will consider this in connection with #2044 and #2048.

hsutter avatar Jul 27 '23 16:07 hsutter

Editors call: We agree, it should be a string literal. We'll fix the Guidelines to show that.

hsutter avatar Feb 15 '24 21:02 hsutter