Skip to content

[clang-tidy] False positives bugprone-dynamic-static-initializers #145680

Open
@carlosgalvezp

Description

@carlosgalvezp

I believe the check warns incorrectly in the following cases:

#include <limits>

template <typename T>
constexpr T kMin{std::numeric_limits<T>::min()};

template <int n>
struct X
{
  static constexpr int xn{n};
};
$ clang-tidy --checks=-*,bugprone-dynamic-static-initializers foo.hpp -- -fno-threadsafe-statics
589 warnings generated.
/tmp/foo.hpp:4:13: warning: static variable 'kMin' may be dynamically initialized in this header file [bugprone-dynamic-static-initializers]
    4 | constexpr T kMin{std::numeric_limits<T>::min()};
      |             ^
/tmp/foo.hpp:9:24: warning: static variable 'xn' may be dynamically initialized in this header file [bugprone-dynamic-static-initializers]
    9 |   static constexpr int xn{n};
      |                        ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions