Skip to content

MSVC static analyser warns for gsl::narrow_cast, to use gsl::narrow_cast #688

Closed

Description

@Farwaykorse

When gsl/gsl is included in the precompiled header, everything is compiled, and checked by the static analyser.

The static analyser in MSVC, using the CppCoreCheckRules, returns a single curious warning:

c:\src\vcpkg\installed\x64-windows\include\gsl\gsl_util(93): warning C26472: Don't use a static_cast for arithmetic conversions. Use brace initialization, gsl::narrow_cast or gsl::narow (type.1).

How about preceding the static_cast in narrow_cast with [[gsl::suppress(type.1)]]?

Activity

  1. beinhaerter commented on May 28, 2018

    @beinhaerter
    Contributor

    Please compare PR #642 .
    If [[gsl::suppress(type.1)]] really works with MSVC (did you test it?) it might be a better alternative than the change that I suggested.

  2. Farwaykorse commented on May 30, 2018

    @Farwaykorse
    ContributorAuthor

    Yes, this is the same issue as in #642.

    I did test it (for the case mentioned here):
    For MSVC (VS v15.7) it works.
    But there was an issue when compiling with Clang (v6.0.0 on Windows).

    I'll add a comment in the pull request.

  3. Farwaykorse commented on Oct 11, 2018

    @Farwaykorse
    ContributorAuthor

    Fixed with #703.

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

Metadata

Metadata

Assignees

No one assigned

    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