ParseInit.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. //===--- ParseInit.cpp - Initializer Parsing ------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file implements initializer parsing as specified by C99 6.7.8.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "clang/Basic/TokenKinds.h"
  13. #include "clang/Parse/ParseDiagnostic.h"
  14. #include "clang/Parse/Parser.h"
  15. #include "clang/Parse/RAIIObjectsForParser.h"
  16. #include "clang/Sema/Designator.h"
  17. #include "clang/Sema/Ownership.h"
  18. #include "clang/Sema/Scope.h"
  19. #include "llvm/ADT/STLExtras.h"
  20. #include "llvm/ADT/SmallString.h"
  21. using namespace clang;
  22. /// MayBeDesignationStart - Return true if the current token might be the start
  23. /// of a designator. If we can tell it is impossible that it is a designator,
  24. /// return false.
  25. bool Parser::MayBeDesignationStart() {
  26. switch (Tok.getKind()) {
  27. default:
  28. return false;
  29. case tok::period: // designator: '.' identifier
  30. return true;
  31. case tok::l_square: { // designator: array-designator
  32. if (!PP.getLangOpts().CPlusPlus11)
  33. return true;
  34. // C++11 lambda expressions and C99 designators can be ambiguous all the
  35. // way through the closing ']' and to the next character. Handle the easy
  36. // cases here, and fall back to tentative parsing if those fail.
  37. switch (PP.LookAhead(0).getKind()) {
  38. case tok::equal:
  39. case tok::ellipsis:
  40. case tok::r_square:
  41. // Definitely starts a lambda expression.
  42. return false;
  43. case tok::amp:
  44. case tok::kw_this:
  45. case tok::star:
  46. case tok::identifier:
  47. // We have to do additional analysis, because these could be the
  48. // start of a constant expression or a lambda capture list.
  49. break;
  50. default:
  51. // Anything not mentioned above cannot occur following a '[' in a
  52. // lambda expression.
  53. return true;
  54. }
  55. // Handle the complicated case below.
  56. break;
  57. }
  58. case tok::identifier: // designation: identifier ':'
  59. return PP.LookAhead(0).is(tok::colon);
  60. }
  61. // Parse up to (at most) the token after the closing ']' to determine
  62. // whether this is a C99 designator or a lambda.
  63. RevertingTentativeParsingAction Tentative(*this);
  64. LambdaIntroducer Intro;
  65. LambdaIntroducerTentativeParse ParseResult;
  66. if (ParseLambdaIntroducer(Intro, &ParseResult)) {
  67. // Hit and diagnosed an error in a lambda.
  68. // FIXME: Tell the caller this happened so they can recover.
  69. return true;
  70. }
  71. switch (ParseResult) {
  72. case LambdaIntroducerTentativeParse::Success:
  73. case LambdaIntroducerTentativeParse::Incomplete:
  74. // Might be a lambda-expression. Keep looking.
  75. // FIXME: If our tentative parse was not incomplete, parse the lambda from
  76. // here rather than throwing away then reparsing the LambdaIntroducer.
  77. break;
  78. case LambdaIntroducerTentativeParse::MessageSend:
  79. case LambdaIntroducerTentativeParse::Invalid:
  80. // Can't be a lambda-expression. Treat it as a designator.
  81. // FIXME: Should we disambiguate against a message-send?
  82. return true;
  83. }
  84. // Once we hit the closing square bracket, we look at the next
  85. // token. If it's an '=', this is a designator. Otherwise, it's a
  86. // lambda expression. This decision favors lambdas over the older
  87. // GNU designator syntax, which allows one to omit the '=', but is
  88. // consistent with GCC.
  89. return Tok.is(tok::equal);
  90. }
  91. static void CheckArrayDesignatorSyntax(Parser &P, SourceLocation Loc,
  92. Designation &Desig) {
  93. // If we have exactly one array designator, this used the GNU
  94. // 'designation: array-designator' extension, otherwise there should be no
  95. // designators at all!
  96. if (Desig.getNumDesignators() == 1 &&
  97. (Desig.getDesignator(0).isArrayDesignator() ||
  98. Desig.getDesignator(0).isArrayRangeDesignator()))
  99. P.Diag(Loc, diag::ext_gnu_missing_equal_designator);
  100. else if (Desig.getNumDesignators() > 0)
  101. P.Diag(Loc, diag::err_expected_equal_designator);
  102. }
  103. /// ParseInitializerWithPotentialDesignator - Parse the 'initializer' production
  104. /// checking to see if the token stream starts with a designator.
  105. ///
  106. /// C99:
  107. ///
  108. /// designation:
  109. /// designator-list '='
  110. /// [GNU] array-designator
  111. /// [GNU] identifier ':'
  112. ///
  113. /// designator-list:
  114. /// designator
  115. /// designator-list designator
  116. ///
  117. /// designator:
  118. /// array-designator
  119. /// '.' identifier
  120. ///
  121. /// array-designator:
  122. /// '[' constant-expression ']'
  123. /// [GNU] '[' constant-expression '...' constant-expression ']'
  124. ///
  125. /// C++20:
  126. ///
  127. /// designated-initializer-list:
  128. /// designated-initializer-clause
  129. /// designated-initializer-list ',' designated-initializer-clause
  130. ///
  131. /// designated-initializer-clause:
  132. /// designator brace-or-equal-initializer
  133. ///
  134. /// designator:
  135. /// '.' identifier
  136. ///
  137. /// We allow the C99 syntax extensions in C++20, but do not allow the C++20
  138. /// extension (a braced-init-list after the designator with no '=') in C99.
  139. ///
  140. /// NOTE: [OBC] allows '[ objc-receiver objc-message-args ]' as an
  141. /// initializer (because it is an expression). We need to consider this case
  142. /// when parsing array designators.
  143. ///
  144. /// \p CodeCompleteCB is called with Designation parsed so far.
  145. ExprResult Parser::ParseInitializerWithPotentialDesignator(
  146. DesignatorCompletionInfo DesignatorCompletion) {
  147. // If this is the old-style GNU extension:
  148. // designation ::= identifier ':'
  149. // Handle it as a field designator. Otherwise, this must be the start of a
  150. // normal expression.
  151. if (Tok.is(tok::identifier)) {
  152. const IdentifierInfo *FieldName = Tok.getIdentifierInfo();
  153. SmallString<256> NewSyntax;
  154. llvm::raw_svector_ostream(NewSyntax) << '.' << FieldName->getName()
  155. << " = ";
  156. SourceLocation NameLoc = ConsumeToken(); // Eat the identifier.
  157. assert(Tok.is(tok::colon) && "MayBeDesignationStart not working properly!");
  158. SourceLocation ColonLoc = ConsumeToken();
  159. Diag(NameLoc, diag::ext_gnu_old_style_field_designator)
  160. << FixItHint::CreateReplacement(SourceRange(NameLoc, ColonLoc),
  161. NewSyntax);
  162. Designation D;
  163. D.AddDesignator(Designator::getField(FieldName, SourceLocation(), NameLoc));
  164. PreferredType.enterDesignatedInitializer(
  165. Tok.getLocation(), DesignatorCompletion.PreferredBaseType, D);
  166. return Actions.ActOnDesignatedInitializer(D, ColonLoc, true,
  167. ParseInitializer());
  168. }
  169. // Desig - This is initialized when we see our first designator. We may have
  170. // an objc message send with no designator, so we don't want to create this
  171. // eagerly.
  172. Designation Desig;
  173. // Parse each designator in the designator list until we find an initializer.
  174. while (Tok.is(tok::period) || Tok.is(tok::l_square)) {
  175. if (Tok.is(tok::period)) {
  176. // designator: '.' identifier
  177. SourceLocation DotLoc = ConsumeToken();
  178. if (Tok.is(tok::code_completion)) {
  179. cutOffParsing();
  180. Actions.CodeCompleteDesignator(DesignatorCompletion.PreferredBaseType,
  181. DesignatorCompletion.InitExprs, Desig);
  182. return ExprError();
  183. }
  184. if (Tok.isNot(tok::identifier)) {
  185. Diag(Tok.getLocation(), diag::err_expected_field_designator);
  186. return ExprError();
  187. }
  188. Desig.AddDesignator(Designator::getField(Tok.getIdentifierInfo(), DotLoc,
  189. Tok.getLocation()));
  190. ConsumeToken(); // Eat the identifier.
  191. continue;
  192. }
  193. // We must have either an array designator now or an objc message send.
  194. assert(Tok.is(tok::l_square) && "Unexpected token!");
  195. // Handle the two forms of array designator:
  196. // array-designator: '[' constant-expression ']'
  197. // array-designator: '[' constant-expression '...' constant-expression ']'
  198. //
  199. // Also, we have to handle the case where the expression after the
  200. // designator an an objc message send: '[' objc-message-expr ']'.
  201. // Interesting cases are:
  202. // [foo bar] -> objc message send
  203. // [foo] -> array designator
  204. // [foo ... bar] -> array designator
  205. // [4][foo bar] -> obsolete GNU designation with objc message send.
  206. //
  207. // We do not need to check for an expression starting with [[ here. If it
  208. // contains an Objective-C message send, then it is not an ill-formed
  209. // attribute. If it is a lambda-expression within an array-designator, then
  210. // it will be rejected because a constant-expression cannot begin with a
  211. // lambda-expression.
  212. InMessageExpressionRAIIObject InMessage(*this, true);
  213. BalancedDelimiterTracker T(*this, tok::l_square);
  214. T.consumeOpen();
  215. SourceLocation StartLoc = T.getOpenLocation();
  216. ExprResult Idx;
  217. // If Objective-C is enabled and this is a typename (class message
  218. // send) or send to 'super', parse this as a message send
  219. // expression. We handle C++ and C separately, since C++ requires
  220. // much more complicated parsing.
  221. if (getLangOpts().ObjC && getLangOpts().CPlusPlus) {
  222. // Send to 'super'.
  223. if (Tok.is(tok::identifier) && Tok.getIdentifierInfo() == Ident_super &&
  224. NextToken().isNot(tok::period) &&
  225. getCurScope()->isInObjcMethodScope()) {
  226. CheckArrayDesignatorSyntax(*this, StartLoc, Desig);
  227. return ParseAssignmentExprWithObjCMessageExprStart(
  228. StartLoc, ConsumeToken(), nullptr, nullptr);
  229. }
  230. // Parse the receiver, which is either a type or an expression.
  231. bool IsExpr;
  232. void *TypeOrExpr;
  233. if (ParseObjCXXMessageReceiver(IsExpr, TypeOrExpr)) {
  234. SkipUntil(tok::r_square, StopAtSemi);
  235. return ExprError();
  236. }
  237. // If the receiver was a type, we have a class message; parse
  238. // the rest of it.
  239. if (!IsExpr) {
  240. CheckArrayDesignatorSyntax(*this, StartLoc, Desig);
  241. return ParseAssignmentExprWithObjCMessageExprStart(StartLoc,
  242. SourceLocation(),
  243. ParsedType::getFromOpaquePtr(TypeOrExpr),
  244. nullptr);
  245. }
  246. // If the receiver was an expression, we still don't know
  247. // whether we have a message send or an array designator; just
  248. // adopt the expression for further analysis below.
  249. // FIXME: potentially-potentially evaluated expression above?
  250. Idx = ExprResult(static_cast<Expr*>(TypeOrExpr));
  251. } else if (getLangOpts().ObjC && Tok.is(tok::identifier)) {
  252. IdentifierInfo *II = Tok.getIdentifierInfo();
  253. SourceLocation IILoc = Tok.getLocation();
  254. ParsedType ReceiverType;
  255. // Three cases. This is a message send to a type: [type foo]
  256. // This is a message send to super: [super foo]
  257. // This is a message sent to an expr: [super.bar foo]
  258. switch (Actions.getObjCMessageKind(
  259. getCurScope(), II, IILoc, II == Ident_super,
  260. NextToken().is(tok::period), ReceiverType)) {
  261. case Sema::ObjCSuperMessage:
  262. CheckArrayDesignatorSyntax(*this, StartLoc, Desig);
  263. return ParseAssignmentExprWithObjCMessageExprStart(
  264. StartLoc, ConsumeToken(), nullptr, nullptr);
  265. case Sema::ObjCClassMessage:
  266. CheckArrayDesignatorSyntax(*this, StartLoc, Desig);
  267. ConsumeToken(); // the identifier
  268. if (!ReceiverType) {
  269. SkipUntil(tok::r_square, StopAtSemi);
  270. return ExprError();
  271. }
  272. // Parse type arguments and protocol qualifiers.
  273. if (Tok.is(tok::less)) {
  274. SourceLocation NewEndLoc;
  275. TypeResult NewReceiverType
  276. = parseObjCTypeArgsAndProtocolQualifiers(IILoc, ReceiverType,
  277. /*consumeLastToken=*/true,
  278. NewEndLoc);
  279. if (!NewReceiverType.isUsable()) {
  280. SkipUntil(tok::r_square, StopAtSemi);
  281. return ExprError();
  282. }
  283. ReceiverType = NewReceiverType.get();
  284. }
  285. return ParseAssignmentExprWithObjCMessageExprStart(StartLoc,
  286. SourceLocation(),
  287. ReceiverType,
  288. nullptr);
  289. case Sema::ObjCInstanceMessage:
  290. // Fall through; we'll just parse the expression and
  291. // (possibly) treat this like an Objective-C message send
  292. // later.
  293. break;
  294. }
  295. }
  296. // Parse the index expression, if we haven't already gotten one
  297. // above (which can only happen in Objective-C++).
  298. // Note that we parse this as an assignment expression, not a constant
  299. // expression (allowing *=, =, etc) to handle the objc case. Sema needs
  300. // to validate that the expression is a constant.
  301. // FIXME: We also need to tell Sema that we're in a
  302. // potentially-potentially evaluated context.
  303. if (!Idx.get()) {
  304. Idx = ParseAssignmentExpression();
  305. if (Idx.isInvalid()) {
  306. SkipUntil(tok::r_square, StopAtSemi);
  307. return Idx;
  308. }
  309. }
  310. // Given an expression, we could either have a designator (if the next
  311. // tokens are '...' or ']' or an objc message send. If this is an objc
  312. // message send, handle it now. An objc-message send is the start of
  313. // an assignment-expression production.
  314. if (getLangOpts().ObjC && Tok.isNot(tok::ellipsis) &&
  315. Tok.isNot(tok::r_square)) {
  316. CheckArrayDesignatorSyntax(*this, Tok.getLocation(), Desig);
  317. return ParseAssignmentExprWithObjCMessageExprStart(
  318. StartLoc, SourceLocation(), nullptr, Idx.get());
  319. }
  320. // If this is a normal array designator, remember it.
  321. if (Tok.isNot(tok::ellipsis)) {
  322. Desig.AddDesignator(Designator::getArray(Idx.get(), StartLoc));
  323. } else {
  324. // Handle the gnu array range extension.
  325. Diag(Tok, diag::ext_gnu_array_range);
  326. SourceLocation EllipsisLoc = ConsumeToken();
  327. ExprResult RHS(ParseConstantExpression());
  328. if (RHS.isInvalid()) {
  329. SkipUntil(tok::r_square, StopAtSemi);
  330. return RHS;
  331. }
  332. Desig.AddDesignator(Designator::getArrayRange(Idx.get(),
  333. RHS.get(),
  334. StartLoc, EllipsisLoc));
  335. }
  336. T.consumeClose();
  337. Desig.getDesignator(Desig.getNumDesignators() - 1).setRBracketLoc(
  338. T.getCloseLocation());
  339. }
  340. // Okay, we're done with the designator sequence. We know that there must be
  341. // at least one designator, because the only case we can get into this method
  342. // without a designator is when we have an objc message send. That case is
  343. // handled and returned from above.
  344. assert(!Desig.empty() && "Designator is empty?");
  345. // Handle a normal designator sequence end, which is an equal.
  346. if (Tok.is(tok::equal)) {
  347. SourceLocation EqualLoc = ConsumeToken();
  348. PreferredType.enterDesignatedInitializer(
  349. Tok.getLocation(), DesignatorCompletion.PreferredBaseType, Desig);
  350. return Actions.ActOnDesignatedInitializer(Desig, EqualLoc, false,
  351. ParseInitializer());
  352. }
  353. // Handle a C++20 braced designated initialization, which results in
  354. // direct-list-initialization of the aggregate element. We allow this as an
  355. // extension from C++11 onwards (when direct-list-initialization was added).
  356. if (Tok.is(tok::l_brace) && getLangOpts().CPlusPlus11) {
  357. PreferredType.enterDesignatedInitializer(
  358. Tok.getLocation(), DesignatorCompletion.PreferredBaseType, Desig);
  359. return Actions.ActOnDesignatedInitializer(Desig, SourceLocation(), false,
  360. ParseBraceInitializer());
  361. }
  362. // We read some number of designators and found something that isn't an = or
  363. // an initializer. If we have exactly one array designator, this
  364. // is the GNU 'designation: array-designator' extension. Otherwise, it is a
  365. // parse error.
  366. if (Desig.getNumDesignators() == 1 &&
  367. (Desig.getDesignator(0).isArrayDesignator() ||
  368. Desig.getDesignator(0).isArrayRangeDesignator())) {
  369. Diag(Tok, diag::ext_gnu_missing_equal_designator)
  370. << FixItHint::CreateInsertion(Tok.getLocation(), "= ");
  371. return Actions.ActOnDesignatedInitializer(Desig, Tok.getLocation(),
  372. true, ParseInitializer());
  373. }
  374. Diag(Tok, diag::err_expected_equal_designator);
  375. return ExprError();
  376. }
  377. /// ParseBraceInitializer - Called when parsing an initializer that has a
  378. /// leading open brace.
  379. ///
  380. /// initializer: [C99 6.7.8]
  381. /// '{' initializer-list '}'
  382. /// '{' initializer-list ',' '}'
  383. /// [GNU] '{' '}'
  384. ///
  385. /// initializer-list:
  386. /// designation[opt] initializer ...[opt]
  387. /// initializer-list ',' designation[opt] initializer ...[opt]
  388. ///
  389. ExprResult Parser::ParseBraceInitializer() {
  390. InMessageExpressionRAIIObject InMessage(*this, false);
  391. BalancedDelimiterTracker T(*this, tok::l_brace);
  392. T.consumeOpen();
  393. SourceLocation LBraceLoc = T.getOpenLocation();
  394. /// InitExprs - This is the actual list of expressions contained in the
  395. /// initializer.
  396. ExprVector InitExprs;
  397. if (Tok.is(tok::r_brace)) {
  398. // Empty initializers are a C++ feature and a GNU extension to C.
  399. if (!getLangOpts().CPlusPlus)
  400. Diag(LBraceLoc, diag::ext_gnu_empty_initializer);
  401. // Match the '}'.
  402. return Actions.ActOnInitList(LBraceLoc, std::nullopt, ConsumeBrace());
  403. }
  404. // Enter an appropriate expression evaluation context for an initializer list.
  405. EnterExpressionEvaluationContext EnterContext(
  406. Actions, EnterExpressionEvaluationContext::InitList);
  407. bool InitExprsOk = true;
  408. QualType LikelyType = PreferredType.get(T.getOpenLocation());
  409. DesignatorCompletionInfo DesignatorCompletion{InitExprs, LikelyType};
  410. bool CalledSignatureHelp = false;
  411. auto RunSignatureHelp = [&] {
  412. QualType PreferredType;
  413. if (!LikelyType.isNull())
  414. PreferredType = Actions.ProduceConstructorSignatureHelp(
  415. LikelyType->getCanonicalTypeInternal(), T.getOpenLocation(),
  416. InitExprs, T.getOpenLocation(), /*Braced=*/true);
  417. CalledSignatureHelp = true;
  418. return PreferredType;
  419. };
  420. while (true) {
  421. PreferredType.enterFunctionArgument(Tok.getLocation(), RunSignatureHelp);
  422. // Handle Microsoft __if_exists/if_not_exists if necessary.
  423. if (getLangOpts().MicrosoftExt && (Tok.is(tok::kw___if_exists) ||
  424. Tok.is(tok::kw___if_not_exists))) {
  425. if (ParseMicrosoftIfExistsBraceInitializer(InitExprs, InitExprsOk)) {
  426. if (Tok.isNot(tok::comma)) break;
  427. ConsumeToken();
  428. }
  429. if (Tok.is(tok::r_brace)) break;
  430. continue;
  431. }
  432. // Parse: designation[opt] initializer
  433. // If we know that this cannot be a designation, just parse the nested
  434. // initializer directly.
  435. ExprResult SubElt;
  436. if (MayBeDesignationStart())
  437. SubElt = ParseInitializerWithPotentialDesignator(DesignatorCompletion);
  438. else
  439. SubElt = ParseInitializer();
  440. if (Tok.is(tok::ellipsis))
  441. SubElt = Actions.ActOnPackExpansion(SubElt.get(), ConsumeToken());
  442. SubElt = Actions.CorrectDelayedTyposInExpr(SubElt.get());
  443. // If we couldn't parse the subelement, bail out.
  444. if (SubElt.isUsable()) {
  445. InitExprs.push_back(SubElt.get());
  446. } else {
  447. InitExprsOk = false;
  448. // We have two ways to try to recover from this error: if the code looks
  449. // grammatically ok (i.e. we have a comma coming up) try to continue
  450. // parsing the rest of the initializer. This allows us to emit
  451. // diagnostics for later elements that we find. If we don't see a comma,
  452. // assume there is a parse error, and just skip to recover.
  453. // FIXME: This comment doesn't sound right. If there is a r_brace
  454. // immediately, it can't be an error, since there is no other way of
  455. // leaving this loop except through this if.
  456. if (Tok.isNot(tok::comma)) {
  457. SkipUntil(tok::r_brace, StopBeforeMatch);
  458. break;
  459. }
  460. }
  461. // If we don't have a comma continued list, we're done.
  462. if (Tok.isNot(tok::comma)) break;
  463. // TODO: save comma locations if some client cares.
  464. ConsumeToken();
  465. // Handle trailing comma.
  466. if (Tok.is(tok::r_brace)) break;
  467. }
  468. bool closed = !T.consumeClose();
  469. if (InitExprsOk && closed)
  470. return Actions.ActOnInitList(LBraceLoc, InitExprs,
  471. T.getCloseLocation());
  472. return ExprError(); // an error occurred.
  473. }
  474. // Return true if a comma (or closing brace) is necessary after the
  475. // __if_exists/if_not_exists statement.
  476. bool Parser::ParseMicrosoftIfExistsBraceInitializer(ExprVector &InitExprs,
  477. bool &InitExprsOk) {
  478. bool trailingComma = false;
  479. IfExistsCondition Result;
  480. if (ParseMicrosoftIfExistsCondition(Result))
  481. return false;
  482. BalancedDelimiterTracker Braces(*this, tok::l_brace);
  483. if (Braces.consumeOpen()) {
  484. Diag(Tok, diag::err_expected) << tok::l_brace;
  485. return false;
  486. }
  487. switch (Result.Behavior) {
  488. case IEB_Parse:
  489. // Parse the declarations below.
  490. break;
  491. case IEB_Dependent:
  492. Diag(Result.KeywordLoc, diag::warn_microsoft_dependent_exists)
  493. << Result.IsIfExists;
  494. // Fall through to skip.
  495. [[fallthrough]];
  496. case IEB_Skip:
  497. Braces.skipToEnd();
  498. return false;
  499. }
  500. DesignatorCompletionInfo DesignatorCompletion{
  501. InitExprs,
  502. PreferredType.get(Braces.getOpenLocation()),
  503. };
  504. while (!isEofOrEom()) {
  505. trailingComma = false;
  506. // If we know that this cannot be a designation, just parse the nested
  507. // initializer directly.
  508. ExprResult SubElt;
  509. if (MayBeDesignationStart())
  510. SubElt = ParseInitializerWithPotentialDesignator(DesignatorCompletion);
  511. else
  512. SubElt = ParseInitializer();
  513. if (Tok.is(tok::ellipsis))
  514. SubElt = Actions.ActOnPackExpansion(SubElt.get(), ConsumeToken());
  515. // If we couldn't parse the subelement, bail out.
  516. if (!SubElt.isInvalid())
  517. InitExprs.push_back(SubElt.get());
  518. else
  519. InitExprsOk = false;
  520. if (Tok.is(tok::comma)) {
  521. ConsumeToken();
  522. trailingComma = true;
  523. }
  524. if (Tok.is(tok::r_brace))
  525. break;
  526. }
  527. Braces.consumeClose();
  528. return !trailingComma;
  529. }