[PATCH] D59754: [Sema] Add c++2a designated initializer warnings
Nicolas Lesser via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 25 14:17:36 PDT 2019
Rakete1111 added inline comments.
================
Comment at: clang/lib/Sema/SemaInit.cpp:2017
+ auto LastIdx = Field != FieldEnd
+ ? Field->getFieldIndex()
----------------
Can `Field` ever be `FieldEnd` at this point?
================
Comment at: clang/lib/Sema/SemaInit.cpp:2044
+ : std::distance(RD->field_begin(), RD->field_end());
+ if (VerifyOnly && (LastIdx >= NextIdx || HasNonDesignatedInit) &&
+ SemaRef.getLangOpts().CPlusPlus2a)
----------------
`!VerifyOnly` and braces please.
================
Comment at: clang/lib/Sema/SemaInit.cpp:2065
+ // Warn on mixed designators in C++20
+ if (VerifyOnly && HasDesignatedInit && SemaRef.getLangOpts().CPlusPlus2a)
+ SemaRef.Diag(Init->getBeginLoc(), diag::ext_designated_init)
----------------
Same here. It should be `!VerifyOnly`. Also braces for the if statement.
================
Comment at: clang/lib/Sema/SemaInit.cpp:3087
if (!getLangOpts().C99)
- Diag(DIE->getBeginLoc(), diag::ext_designated_init)
- << DIE->getSourceRange();
+ // Warn on nested and array designators in C++20
+ if (!getLangOpts().CPlusPlus2a || Desig.getNumDesignators() > 1 ||
----------------
Missing dot.
================
Comment at: clang/lib/Sema/SemaInit.cpp:3089
+ if (!getLangOpts().CPlusPlus2a || Desig.getNumDesignators() > 1 ||
+ HasArrayDesignator)
+ Diag(DIE->getBeginLoc(), diag::ext_designated_init)
----------------
Braces.
================
Comment at: clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp:30
+// out of order designators
+A a1 = {.y = 1, .x = 2}; // expected-warning {{designated initializers are a C99 feature}}
+
----------------
Those warnings are misleading, since C++20 does have designated initializers; they just don't support some stuff that C99 does. It would be better IMO if you could separate them. As in, the above should give you: `out-of-order designated initializers are a C99 feature` or something like that.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D59754/new/
https://reviews.llvm.org/D59754
More information about the cfe-commits
mailing list