From da6cde9fd0f8df6e490bfe949b82ccee82d1572a Mon Sep 17 00:00:00 2001 From: Amelie Renard Date: Thu, 5 Oct 2023 11:48:42 +0200 Subject: [PATCH] Modify rule S6172: fix typo and add diff view --- rules/S6172/cfamily/rule.adoc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/rules/S6172/cfamily/rule.adoc b/rules/S6172/cfamily/rule.adoc index 1b8481babf..9f3c57bcf4 100644 --- a/rules/S6172/cfamily/rule.adoc +++ b/rules/S6172/cfamily/rule.adoc @@ -1,7 +1,8 @@ == Why is this an issue? -{cpp}20 introduced a restricted form of designated initializers for aggregates (i.e. arrays or classes which respect specific criterion). Designated initializers enable initialization of aggregates by naming their fields explicitly: +{cpp}20 introduced a restricted form of designated initializers for aggregates (i.e., arrays or classes that respect specific criteria). Designated initializers enable the initialization of aggregates by naming their fields explicitly: +[source,cpp] ---- struct Point { float x = 0.0; @@ -16,7 +17,7 @@ Point p = { }; ---- -This initialization style is similar to designated initializers in C and in many {cpp} compiler extensions predating {cpp}20. +This initialization style is similar to designated initializers in C and many {cpp} compiler extensions predating {cpp}20. However, it is more restricted because some forms are not supported by the {cpp}20 standard, namely: @@ -30,7 +31,7 @@ This rule reports non-{cpp}-compliant forms of designated initializers. === Noncompliant code example -[source,cpp] +[source,cpp,diff-id=1,diff-type=noncompliant] ---- struct A { int x, y; }; struct B { struct A a; }; @@ -44,7 +45,7 @@ struct A c = {.x = 1, 2}; // Noncompliant: valid C, invalid C++ (mixed) === Compliant solution -[source,cpp] +[source,cpp,diff-id=1,diff-type=compliant] ---- struct A { int x, y; }; struct B { struct A a; };