Skip to content

Commit

Permalink
S5408 Remove constexpr static data members from rspec (CPP-5809)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasz-kaminski-sonarsource committed Nov 14, 2024
1 parent 19f97f6 commit 9bf6db9
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions rules/S5408/cfamily/rule.adoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
== Why is this an issue?

Declaring a function or a static member variable ``++constexpr++`` makes it implicitly inline.

Declaring a function ``++constexpr++`` makes it implicitly inline.

In that situation, explicitly using the ``++inline++`` keyword would be redundant, and might lead to confusion if it's used in some cases but not others. It's better to simply omit it.

Expand All @@ -11,22 +10,14 @@ In that situation, explicitly using the ``++inline++`` keyword would be redundan
[source,cpp]
----
inline constexpr int addOne(int n) { return n+1; } // Noncompliant
struct A {
inline constexpr static int secretNumber = 0; // Noncompliant
};
----


=== Compliant solution

[source,cpp]
----
constexpr int addOne(int n) { return n+1; }
struct A {
constexpr static int secretNumber = 0;
};
----



ifdef::env-github,rspecator-view[]
Expand Down

0 comments on commit 9bf6db9

Please sign in to comment.