From b5220d59212385b9374e75b1e1abd5ada4bc964b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kami=C5=84ski?= Date: Wed, 24 Jan 2024 15:57:20 +0100 Subject: [PATCH] Brace elision --- rules/S6871/cfamily/rule.adoc | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/rules/S6871/cfamily/rule.adoc b/rules/S6871/cfamily/rule.adoc index 0c451e57acc..1d0b35bb782 100644 --- a/rules/S6871/cfamily/rule.adoc +++ b/rules/S6871/cfamily/rule.adoc @@ -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 @@ -221,16 +221,17 @@ struct ArrayMember { }; -int a1[5] = {1, 2, 3, 0, 0}; // Compliant -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 +int a1[5] = {1, 2, 3, 0, 0}; // Compliant +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 ---- Or use zero-initialization syntax for `c2` and `c3`: ------ +[source,cpp] +---- Pod c2[3] = {{1, 2}, {2, 0}, {}}; // Compliant PodPair c3{{1, 0}, {}}; // Compliant ---- @@ -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