Marco Borgeaud c6a5a82aea Modify rule S3252: Remove compliant part from noncompliant example
It's trivial enough not to be referred explicitly
2023-10-18 16:04:55 +02:00

108 lines
1.8 KiB
Plaintext

== Why is this an issue?
include::../description.adoc[]
=== Exceptions
This rule doesn't raise an issue for constants. If the variable is `const`, there is no risk of confusion.
=== Noncompliant code example
[source,cpp,diff-id=1,diff-type=noncompliant]
----
class Parent {
public:
static int count;
};
class Child : public Parent {
public:
Child() {
Child::count++; // Noncompliant
}
};
----
=== Compliant solution
[source,cpp,diff-id=1,diff-type=compliant]
----
class Parent {
public:
static int count;
};
class Child : public Parent {
public:
Child() {
Parent::count++;
}
};
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Do not access "X" with derived type "Y".
'''
== Comments And Links
(visible only on this page)
=== on 21 Jan 2016, 09:57:11 Alban Auzeill wrote:
\[~ann.campbell.2] Given the following {cpp} example:
----
class Parent {
public:
static int count;
};
typedef Parent ParentAlias1;
typedef Parent ParentAlias2;
class Child : public ParentAlias2 {
public:
Child() {
Child::count++;
}
};
----
I'm able to identify:
* the static member name "count"
* the qualifier that prefix the member "Child"
But to be able to create the message:
{code}Replace "X" with "Y".{code}
It's sometime ambigus to propose the replacement, in the above example it can be "Parent", "ParentAlias1" or "ParentAlias2".
That's why I propose a message with only the member name and the qualifier name:
{code} Do not access "Z" with derived type "X".{code}
In this case it would be:
{code} Do not access "count" with derived type "Child".{code}
=== on 23 Jan 2016, 14:53:05 Ann Campbell wrote:
That's fine [~alban.auzeill].
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]