Basic designated initializers are allowed in c++2a, so only
issue warnings for the extended ones that aren't allowed:
- out of order
- nested
- arrays
- mixed
Differential D59754
[Sema] Add c++2a designated initializer warnings rsmith on Mar 24 2019, 4:48 PM. Authored by
Details Basic designated initializers are allowed in c++2a, so only
Diff Detail
Event Timeline
Comment Actions
Comment Actions Thanks for the review.
Comment Actions I think you're missing the enforcement of the rule that the same field name cannot be designated multiple times in a single designated-initializer-list. I'm fine with that being done separately (not as part of this patch), though.
Comment Actions This looks like exactly what we need for my project. We're using Clang and Designated Initializers but would like to make sure that we use those in C++20 compatible manner. Is this blocked on something? Any way I can help? Comment Actions The basic logic is here modulo @rsmith's comments. I just haven't had time to address them, and unfortunately, it might be another few weeks before I can get back to it. If you'd like to work on it and finish it up, that would be great.
Comment Actions Hi! We've noticed that for our arm bots, we're getting some flaky builds that sometimes fail with error: array designators are a C99 extension [-Werror,-Wc99-designator] and sometimes don't fail. 2 questions:
Thanks. Comment Actions @rsmith ping? We're still hitting this issue in our build. Should this warning be diagnosed even when using -std=c++17? Comment Actions That is strange; can you provide me with buildbot links for a pass and a failure?
C-style designated initializers are invalid in all C++ standards before C++20, and some of the features are still invalid in C++20. We allow those features as an extension, but as of this change we produce a warning by default when that extension is used. We really should have been doing that for years, but it matters a lot more now, because people are going to look at Clang's diagnostics to understand which parts of C designator syntax are valid in C++ and which parts are not. Comment Actions Another question about this, sorry. Do you know _why_ C++20 is more restrictive than C99 wrt "mixture of designated and non-designated initializers in the same initializer list is a C99 extension"? Is there some interaction with other C++ features that makes the C99 behavior difficult in C++20? Comment Actions The design paper P0329R0 describes this behavior but doesn't give much rationale. According to the minutes and my recollections, this was part of the design as presented and didn't really receive any pushback at any stage of the feature design and discussion. I think generally the feeling was that there was insufficient motivation for adding that level of complexity (much like with the restriction to single-level designators and lack of support for array designators). |
typo