Skip to content

Commit

Permalink
Modify rule S1006: add diff view
Browse files Browse the repository at this point in the history
  • Loading branch information
amelie-renard-sonarsource committed Sep 28, 2023
1 parent 821b1c0 commit 73c2266
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions rules/S1006/cfamily/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,27 @@ Overriding the default parameter value inherited from a parent class will lead t

=== Noncompliant code example

[source,cpp]
[source,cpp,diff-id=1,diff-type=noncompliant]
----
enum E_ShapeColor {E_RED, E_GREEN, E_BLUE};
enum E_ShapeColor {E_RED, E_GREEN, E_BLUE};
class Shape
{
{
public:
virtual void draw(E_ShapeColor color = E_RED) const
virtual void draw(E_ShapeColor color = E_RED) const
{
...
}
};
class Rectangle : public Shape
class Rectangle : public Shape
{
public:
virtual void draw(E_ShapeColor color = E_BLUE) const override // Non-compliant
virtual void draw(E_ShapeColor color = E_BLUE) const override // Noncompliant
{
...
...
}
};
};
int main() {
Shape *shape = new Rectangle{};
Expand All @@ -33,28 +34,28 @@ int main() {

=== Compliant solution

[source,cpp]
[source,cpp,diff-id=1,diff-type=compliant]
----
enum E_ShapeColor {E_RED, E_GREEN, E_BLUE};
enum E_ShapeColor {E_RED, E_GREEN, E_BLUE};
class Shape
{
{
public:
virtual void draw(E_ShapeColor color = E_RED) const
virtual void draw(E_ShapeColor color = E_RED) const
{
...
}
};
class Rectangle : public Shape
class Rectangle : public Shape
{
public:
virtual void draw(E_ShapeColor color) const override
// OR: virtual void draw(E_ShapeColor color = E_RED) const override
{
...
...
}
};
};
int main() {
Shape *shape = new Rectangle{};
Expand Down

0 comments on commit 73c2266

Please sign in to comment.