S5408 Remove constexpr static data members from rspec (CPP-5809)

This commit is contained in:
tomasz-kaminski-sonarsource 2024-11-15 10:51:09 +01:00 committed by GitHub
parent 953f1f0315
commit c83d7bff84
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,7 +1,6 @@
== Why is this an issue? == 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. 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.
@ -11,22 +10,14 @@ In that situation, explicitly using the ``++inline++`` keyword would be redundan
[source,cpp] [source,cpp]
---- ----
inline constexpr int addOne(int n) { return n+1; } // Noncompliant inline constexpr int addOne(int n) { return n+1; } // Noncompliant
struct A {
inline constexpr static int secretNumber = 0; // Noncompliant
};
---- ----
=== Compliant solution === Compliant solution
[source,cpp] [source,cpp]
---- ----
constexpr int addOne(int n) { return n+1; } constexpr int addOne(int n) { return n+1; }
struct A {
constexpr static int secretNumber = 0;
};
---- ----
 
ifdef::env-github,rspecator-view[] ifdef::env-github,rspecator-view[]