Modify rule S6172: fix typo and add diff view

This commit is contained in:
Amelie Renard 2023-10-05 11:48:42 +02:00 committed by Amélie Renard
parent 2b7da997d2
commit da6cde9fd0

View File

@ -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; };