Repository navigation
Description
We have a collection of related open issues asking about the GSL [[gsl::suppress(tag)]] syntax:
- #1173
- #1799
- #2042
- #2043
- #2044
- #2046
We should resolve these now that we are writing standards papers proposing to standardize this syntax.
Status quo suppress syntax summary
The current general syntax is:
[[gsl::suppress( tag, justification:"message" )]]
Currently the Guidelines support only suppressing an individual rule (e.g., [[gsl::suppress(C.160)]]) or one of the three profiles type, bounds, and lifetime (e.g., [[gsl::suppress(bounds)]]).
Categorized open issues
The open issues are:
-
Invalid attribute syntax for
tag. Suppression guidelines #1173 and Maketagingsl::suppress(tag)be a string literal #2042 point out thattagis not a valid C++ expression whentagis of a form likeR.11, and that Clang already requirestagto be a string. The Microsoft GSL implementation has to kludge this as a workaround because the tag is nonportable. Suppression guidelines #1173, Maketagingsl::suppress(tag)be a string literal #2042, and @daveedvdv Daveed Vandevoorde saytagshould be a string literal"tag", as Clang already does. -
Valid attribute syntax:
justification:"message"is not a valid C++ expression. -
Selecting a rule by anchor name. Is a rule's header's HTML anchor name still a valid
taginsidegsl::suppress? #2044 asks whether we would support using anchor names, such as[[gsl::suppress(Rh-public)]](instead of by its number,[[suppress(C.134])]]). -
Selecting groups of rules. Are profile names the only way of selecting multiple rules in a single
taginsidegsl::suppress? #2046 asks whether granular suppression such as[[gsl::suppress(C)]]to suppress allCrules, or[[gsl::suppress(C.ctor)]]to suppress all rules in that subsection, should be supported. If the latter is supported then the subsection conventions should be regularized, as they are currently mostly for editorial/reading convenience and are not mechanically consistent in different parts of the Guidelines. -
Selecting individual Enforcements. Should rules be divided to have separate enforcements? #1799 notes that it would be useful to number a rule's Enforcements so they can be enabled/disabled individually. We said in Aug 2021 we were considering doing that.
-
#taganchors are brittle / hard to link to. It appears there are issues with directly linking to each Guideline's stable anchor, which we intended tools be able to do. Is a rule's header's HTML anchor name still a validtaginsidegsl::suppress? #2044 points out that HTML anchors in the github.io "prettified" version of the Guidelines change the anchor of a rule to append the rule's title text, which interferes with being a consistent anchor that checkers can link to. For example, for I.13 it gives the permalinkhttps://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#i13-do-not-pass-an-array-as-a-single-pointerinstead ofhttps://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#i13. Directly linking to an issue in the github.com.mdsource does not appear to work.
Suggestion for discussion
I think the core change we need is to make the syntax grammatical, to make it more portable (including to follow existing practice) and suitable for standardization:
- make the tag a string literal
- make the justification just a string literal
So the syntax would be:
[[gsl::suppress( "tag", "justification message" )]]
which is more proposable for standardization as:
[[suppress( "tag", "justification message" )]]
We should also fix the #tag anchors so they are in fact linkable by tools.
It seems like numbering the Enforcements of each rule would be useful.
I don't think we need to support suppressing a rule by its anchor name (those names are primarily for tools to link to the Guidelines, not for users to refer to in code) or suppressing groups of rules other than the safety profiles. I think the status quo is sufficient, to suppress a single rule by its name (e.g., C.134) and the three safety profiles by name (e.g., bounds).
ETA Bonus question: Should the "tag" allow a comma- and/or whitespace-delimited list that ignores whitespace, such as [[suppress( "type_safety, bounds_safety", "justification message")]] or [[suppress( "type_safety bounds_safety", "justification message")]] ?
Activity
hsutter commentedon Feb 15, 2024
Editors call:
tagshould be"tag"as string literals, not std::strings or string_views, and:tagthat is not a valid existing rule name should be rejected (e.g., reject an HTML link)justification:"string-literal"as is#i13hsutter commentedon Feb 15, 2024
All edits have been applied and other issues closed, so this can now be closed.