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
GSL library uses attributes like [[gsl::suppress(type.1)]] to suppress warnings.
Different compilers require different syntax (clang) or do not recognize them (gcc). This means that using suppress in GSL itself is complicated - not every static analysis tool will be able to suppress them, and we need ifdefs around suppressions to make sure they even compile.
Currently [[gsl::suppress]] are only recognized by CppCoreCheck. not compilers, which could have some warnings from Cpp Core Guidelines as well (for example, unitialized variables)
Would be great to create a standard suppression mechanism for compiler and static analysis warnings.
Thanks Anna, some more context Anna provided separately:
MSVC understands [[gsl::suppress(something.x)]]
Clang understands [[gsl::suppress(“something.x”)]]
GCC doesn't understand them on a line inside a function
Per our discussion. the core problem is that Clang does recognize this suppression, but expects a different format of the suppression. But it's also an issue that there's not a standard way to suppress diagnostics.
We don't believe there is a WG21-level issue concerning this syntax. Clang's string format is expressive, but requires tokenization to parse it. MSVC's is tokenized.
Note that In.force recommends the tokenized syntax:
Tools that implement these rules shall respect the following syntax to explicitly suppress a rule:
[[gsl::suppress(tag)]]
where “tag” is the anchor name of the item where the Enforcement rule appears (e.g., for C.134 it is “Rh-public”), the name of a profile group-of-rules (“type”, “bounds”, or “lifetime”), or a specific rule in a profile (type.4, or bounds.2).
I'm surprised by the choice of syntax here. Attribute arguments rely on balanced token sequences. In something like gsl::suppress(r.10), r.10 is two tokens (r and .10). Semantically, it has no difference from gsl::suppress(r.1). Presumably that's why Clang requires a quoted string instead.
Activity
cubbimew commentedon Mar 22, 2018
Sounds like a compiler bug: [dcl.attr]p6 says Any attribute-token that is not recognized by the implementation is ignored
hsutter commentedon Mar 26, 2018
Thanks Anna, some more context Anna provided separately:
MSVC understands [[gsl::suppress(something.x)]]
Clang understands [[gsl::suppress(“something.x”)]]
GCC doesn't understand them on a line inside a function
AndrewPardoe commentedon Mar 26, 2018
Per our discussion. the core problem is that Clang does recognize this suppression, but expects a different format of the suppression. But it's also an issue that there's not a standard way to suppress diagnostics.
We don't believe there is a WG21-level issue concerning this syntax. Clang's string format is expressive, but requires tokenization to parse it. MSVC's is tokenized.
Note that In.force recommends the tokenized syntax:
hsutter commentedon Mar 26, 2018
Note that this is specified to be quoteless in In.force
daveedvdv commentedon Apr 13, 2023
A late comment on this.
I'm surprised by the choice of syntax here. Attribute arguments rely on balanced token sequences. In something like
gsl::suppress(r.10),r.10is two tokens (rand.10). Semantically, it has no difference fromgsl::suppress(r.1). Presumably that's why Clang requires a quoted string instead.hsutter commentedon Feb 15, 2024
Editors call: Thanks! Sorry for the lag -- this has been addressed with #2178.