[PATCH] D118743: [clang-tidy] Add `modernize-use-inline-const-variables-in-headers` check

Evgeny Shulgin via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 1 18:50:46 PST 2023


Izaron added a comment.

In D118743#3965423 <https://reviews.llvm.org/D118743#3965423>, @Lounarok wrote:

> I tried this patch and it's really helpful!

You're welcome!

> According to this <https://en.cppreference.com/w/cpp/language/constexpr>,  "A `constexpr` specifier used in a function or `static` data member (since C++17) declaration implies `inline`."

That's correct, for //functions// and //static data members//.

> However I found that it warns when it comes to `constexpr static` variable.
>
> Snippet: `constexpr static int UNDEFINED_ERROR{0};`
> Warning msg: `warning: global constant 'UNDEFINED_ERROR' should be marked as 'inline' [modernize-use-inline-const-variables-in-headers]`
> According to this <https://en.cppreference.com/w/cpp/language/constexpr>,  "A `constexpr` specifier used in a function or `static` data member (since C++17) declaration implies `inline`." 
> It seems it should not warn on `constexpr static` variable.

`UNDEFINED_ERROR` is neither a //function// nor a //static data member//. Therefore a warning is meaningful. There is no `inline` implication in your case.

(//data member// is a variable inside a struct/class, but not a "freestanding" one)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118743/new/

https://reviews.llvm.org/D118743



More information about the cfe-commits mailing list