Skip to content

Commit

Permalink
Brace elision
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Kamiński committed Jan 24, 2024
1 parent 2679968 commit 2004b57
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions rules/S6871/cfamily/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,12 @@ struct ArrayMember {
};
int a1[5] = {1, 2, 3}; // Noncompliant
Pod p1{1}; // Noncompliant
int c1[2][2] = {{1}, {2}}; // Noncompliant
Pod c2[3] = {{1, 2}, {2}}; // Noncompliant
PodPair c3 = {{1}}; // Noncompliant
ArrayMember c4 = {1, 2, 3}; // Noncompliant
int a1[5] = {1, 2, 3}; // Noncompliant
Pod p1{1}; // Noncompliant
int c1[2][2] = {{1}, {2}}; // Noncompliant
Pod c2[3] = {{1, 2}, {2}}; // Noncompliant
PodPair c3 = {{1}}; // Noncompliant
ArrayMember c4 = {1, {2, 3}}; // Noncompliant
----

==== Compliant solution
Expand Down Expand Up @@ -226,11 +226,12 @@ Pod p1{1, 0}; // Compliant
int c1[2][2] = {{1, 0}, {2, 0}}; // Compliant
Pod c2[3] = {{1, 2}, {2, 0}, {0, 0}}; // Compliant
PodPair c3 = {{1, 0}, {0, 0}}; // Compliant
ArrayMember c4 = {1, 2, 3, 0, 0, 0}; // Compliant
ArrayMember c4 = {1, {2, 3, 0, 0, 0}}; // Compliant
----

Or use zero-initialization syntax for `c2` and `c3`:
-----
[source,cpp]
----
Pod c2[3] = {{1, 2}, {2, 0}, {}}; // Compliant
PodPair c3{{1, 0}, {}}; // Compliant
----
Expand Down Expand Up @@ -315,6 +316,7 @@ Pod p1{1}; // Compliant
ArrayMember m1{11}; // Compliant
----

TODO: going extra mile with `int arr[2][2] = {1, 2, 3};`

== Resources

Expand Down

0 comments on commit 2004b57

Please sign in to comment.