llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
26.84k stars 11.01k forks source link

False positive of google-readability-casting for out-of-line declaration of static constexpr member of template when building C++14 #92925

Open igkper opened 1 month ago

igkper commented 1 month ago

Given an out-of-line declaration of static constexpr member of template taking an enum template parameter when building C++14, clang-tidy produces a google-readability-casting in the absence of any C-style cast.

enum class Enum
{
    e,
};

template <Enum e>
struct S final
{
    static constexpr int k{};
};

template <Enum e>
constexpr int S<e>::k;   // suggests using static_cast<>( ) here

template struct S<Enum::e>;

In action: https://godbolt.org/z/bEq855dnr

llvmbot commented 1 month ago

@llvm/issue-subscribers-clang-tidy

Author: None (igkper)

Given an out-of-line declaration of static constexpr member of template taking an enum template parameter when building C++14, clang-tidy produces a google-readability-casting in the absence of any C-style cast. ```cpp enum class Enum { e, }; template <Enum e> struct S final { static constexpr int k{}; }; template <Enum e> constexpr int S<e>::k; // suggests using static_cast<>( ) here template struct S<Enum::e>; ``` In action: https://godbolt.org/z/bEq855dnr