[PATCH] D68722: Add an example showing the alternative to nested designators
Shafik Yaghmour via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 9 12:42:09 PDT 2019
shafik created this revision.
shafik added a reviewer: rsmith.
We have an example showing that a nested designators are a c99 extension but not an example showing how to achieve the same thing using a brace-init-list in a designated-initializer-clause.
https://reviews.llvm.org/D68722
Files:
clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
Index: clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
===================================================================
--- clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
+++ clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
@@ -37,7 +37,8 @@
.x = 2 // reorder-error {{ISO C++ requires field designators to be specified in declaration order; field 'y' will be initialized after field 'x'}}
};
int arr[3] = {[1] = 5}; // pedantic-error {{array designators are a C99 extension}}
-B b = {.a.x = 0}; // pedantic-error {{nested designators are a C99 extension}}
+B b1 = {.a.x = 0}; // pedantic-error {{nested designators are a C99 extension}}
+B b2 = {.a = {.x = 0, .y = 1}}; // ok, we don't need nested designators to initialize the members of A
A a2 = {
.x = 1, // pedantic-error {{mixture of designated and non-designated initializers in the same initializer list is a C99 extension}}
2 // pedantic-note {{first non-designated initializer is here}}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68722.224095.patch
Type: text/x-patch
Size: 973 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191009/3ae1aa02/attachment.bin>
More information about the cfe-commits
mailing list