Skip to content

Suppression guidelines #1173

Closed
Closed

Description

@annagrin

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.

Activity

  1. cubbimew commented on Mar 22, 2018

    @cubbimew
    Member

    we need ifdefs around suppressions to make sure they even compile.

    Sounds like a compiler bug: [dcl.attr]p6 says Any attribute-token that is not recognized by the implementation is ignored

  2. hsutter commented on Mar 26, 2018

    @hsutter
    Contributor

    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

  3. AndrewPardoe commented on Mar 26, 2018

    @AndrewPardoe
    Contributor

    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).
    
  4. hsutter commented on Mar 26, 2018

    @hsutter
    Contributor

    Note that this is specified to be quoteless in In.force

  5. daveedvdv commented on Apr 13, 2023

    @daveedvdv

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

  6. hsutter commented on Feb 15, 2024

    @hsutter
    Contributor

    Editors call: Thanks! Sorry for the lag -- this has been addressed with #2178.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions