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

**URL:** <https://community.sonarsource.com/t/cpp-s6018-false-positive-for-template-d-inline-constexpr-s/182288>\
**Category:** Report False-positive / False-negative...\
**Tags:** cfamily, sonarqube\
**Created:** [May 12, 2026, 9:05pm UTC](https://community.sonarsource.com/t/cpp-s6018-false-positive-for-template-d-inline-constexpr-s/182288 "2026-05-12T21:05:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bers](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@bers](https://community.sonarsource.com/u/bers)\
**Post date:** [May 12, 2026, 9:05pm UTC](https://community.sonarsource.com/t/cpp-s6018-false-positive-for-template-d-inline-constexpr-s/182288/1 "2026-05-12T21:05:39Z")

</div>

- 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`:

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

```

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/a/b/abbc3153d5f50fcb15f40bf212d728dca4424521.png)

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [May 13, 2026, 11:56am UTC](https://community.sonarsource.com/t/cpp-s6018-false-positive-for-template-d-inline-constexpr-s/182288/2 "2026-05-13T11:56:02Z")

</div>

Hi (again :D),

We appreciate these reports. Can you make sure they’re ([both](https://community.sonarsource.com/t/cpp-s1121-false-positive-with-assignment-explicitly-enclosed-in-parentheses/182287)) still replicable on the current version?

&nbsp;  
Thx,  
Ann

---

<div class="post-metadata">

**Author:** ![bers](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@bers](https://community.sonarsource.com/u/bers)\
**Post date:** [May 14, 2026, 5:37am UTC](https://community.sonarsource.com/t/cpp-s6018-false-positive-for-template-d-inline-constexpr-s/182288/3 "2026-05-14T05:37:10Z")

</div>

> [@ganncamp](#):
>
> replicable on the current version

Yes it is

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [May 14, 2026, 11:25am UTC](https://community.sonarsource.com/t/cpp-s6018-false-positive-for-template-d-inline-constexpr-s/182288/5 "2026-05-14T11:25:33Z")

</div>

Hi,

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

&nbsp;  
Ann

---

<div class="post-metadata">

**Author:** ![JolyLoic](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/jolyloic/32/199_2.png) [@JolyLoic](https://community.sonarsource.com/u/JolyLoic)\
**Post date:** [May 18, 2026, 3:36pm UTC](https://community.sonarsource.com/t/cpp-s6018-false-positive-for-template-d-inline-constexpr-s/182288/6 "2026-05-18T15:36:52Z")

</div>

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.
