cpp:S6018 false-positive for `template`d `inline` `constexpr`s

  • What language is this for?
    C++

  • Which rule?
    cpp:S6018 (“Inline variables should be used to declare global variables in header files”)

  • Why do you believe it’s a false-positive/false-negative?
    Because my variable is inline already.

  • SonarQube for VS 2026, v10.1.0.16642 in connected mode with SonarQube Server

include.h:

template<class T = int>
inline constexpr auto one = static_cast<T>(1);

Hi (again :D),

We appreciate these reports. Can you make sure they’re (both) still replicable on the current version?

 
Thx,
Ann

Yes it is

Hi,

Thanks for confirming. I’ve flagged this for the language experts.

 
Ann

Hi @bers,

While well intended, this rule had many issues. For instance, it claims that a template variable is always used as a workaround for an inline variable, even when the template variable is used because it is what is needed, and even when it is inline…

We could have fixed this last part, but the rule would still trigger for many perfectly legit uses. So we decided to deprecate this rule, with the intent of removing it as soon as our deprecation policy allows it.

For now, I would advise you to remove it from your quality profile.