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
Paths
| Differential D59754
[Sema] Add c++2a designated initializer warnings ClosedPublic Authored by rsmith on Mar 24 2019, 4:48 PM.
Details Summary Basic designated initializers are allowed in c++2a, so only
Diff Detail
Event Timelinehintonda retitled this revision from [Sema] Add c++2a designator initializer warnings to [Sema] Add c++2a designated initializer warnings.Mar 24 2019, 4:53 PM
Comment Actions
Rakete1111 added inline comments.
Comment Actions Thanks for the review.
lebedev.ri added inline comments.
hintonda added inline comments.
hintonda added inline comments.
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.
hintonda added inline comments.
hintonda added inline comments.
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
Thanks Richard... Closed by commit rL370544: [c++20] Implement semantic restrictions for C++20 designated (authored by rsmith). · Explain Why This revision was automatically updated to reflect the committed changes. 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).
Revision Contents
Diff 218179 cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/test/Analysis/globals.cpp
cfe/trunk/test/CXX/expr/expr.const/p2-0x.cpp
cfe/trunk/test/CodeGenObjCXX/designated-initializers.mm
cfe/trunk/test/PCH/cxx1y-default-initializer.cpp
cfe/trunk/test/Parser/cxx0x-lambda-expressions.cpp
cfe/trunk/test/Parser/objc-init.m
cfe/trunk/test/Sema/designated-initializers.c
cfe/trunk/test/Sema/static-assert.c
cfe/trunk/test/SemaCXX/aggregate-initialization.cpp
cfe/trunk/test/SemaCXX/c99.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
cfe/trunk/test/SemaCXX/constexpr-printing.cpp
cfe/trunk/test/SemaCXX/cxx0x-initializer-constructor.cpp
cfe/trunk/test/SemaCXX/cxx2a-initializer-aggregates.cpp
cfe/trunk/test/SemaCXX/decltype.cpp
cfe/trunk/test/SemaCXX/designated-initializers-base-class.cpp
cfe/trunk/test/SemaCXX/designated-initializers.cpp
cfe/trunk/test/SemaCXX/eval-crashes.cpp
cfe/trunk/test/SemaCXX/member-init.cpp
cfe/trunk/test/SemaObjCXX/message.mm
cfe/trunk/test/SemaTemplate/instantiate-c99.cpp
cfe/trunk/test/SemaTemplate/instantiate-init.cpp
|
warning: variable ‘HasArrayDesignator’ set but not used [-Wunused-but-set-variable]