1111//
1212// ===----------------------------------------------------------------------===//
1313
14- #include " clang/Parse/Parser.h"
1514#include " clang/Parse/ParseDiagnostic.h"
15+ #include " clang/Parse/Parser.h"
1616#include " clang/Parse/RAIIObjectsForParser.h"
1717#include " clang/Sema/ParsedTemplate.h"
1818using namespace clang ;
@@ -1016,8 +1016,7 @@ Parser::TPResult Parser::TryParseNonConversionOperatorId() {
10161016 return TPResult::False;
10171017}
10181018Parser::TPResult Parser::TryParseOperatorId () {
1019- if (TPResult TPR = TryParseNonConversionOperatorId ();
1020- TPR != TPResult::False)
1019+ if (TPResult TPR = TryParseNonConversionOperatorId (); TPR != TPResult::False)
10211020 return TPR;
10221021
10231022 // Maybe this is a conversion-function-id.
@@ -2314,7 +2313,8 @@ Parser::TPResult Parser::TryParseBracketDeclarator() {
23142313// / of a template-id or simple-template-id, rather than a less-than comparison.
23152314// / This will often fail and produce an ambiguity, but should never be wrong
23162315// / if it returns True or False.
2317- Parser::TPResult Parser::isTemplateArgumentList (unsigned TokensToSkip, TemplateNameKind TNK) {
2316+ Parser::TPResult Parser::isTemplateArgumentList (unsigned TokensToSkip,
2317+ TemplateNameKind TNK) {
23182318 if (!TokensToSkip) {
23192319 if (Tok.isNot (tok::less))
23202320 return TPResult::False;
@@ -2340,50 +2340,50 @@ Parser::TPResult Parser::isTemplateArgumentList(unsigned TokensToSkip, TemplateN
23402340 unsigned TemplateDepth = 0 ;
23412341 while (true ) {
23422342 switch (Tok.getKind ()) {
2343- case tok::eof:
2344- case tok::annot_module_begin:
2345- case tok::annot_module_end:
2346- case tok::annot_module_include:
2347- case tok::annot_repl_input_end:
2348- case tok::semi:
2349- return TPResult::False;
2350-
2351- case tok::comma:
2352- case tok::greater:
2353- case tok::greatergreater:
2354- case tok::greatergreatergreater:
2355- return TPResult::True;
2343+ case tok::eof:
2344+ case tok::annot_module_begin:
2345+ case tok::annot_module_end:
2346+ case tok::annot_module_include:
2347+ case tok::annot_repl_input_end:
2348+ case tok::semi:
2349+ return TPResult::False;
23562350
2357- case tok::l_paren:
2358- ConsumeParen ();
2359- if (!SkipUntil (tok::r_paren, StopAtSemi))
2360- return TPResult::Error;
2361- break ;
2362- case tok::l_brace:
2363- ConsumeBrace ();
2364- if (!SkipUntil (tok::r_brace, StopAtSemi))
2365- return TPResult::Error;
2366- break ;
2367- case tok::l_square:
2368- ConsumeBracket ();
2369- if (!SkipUntil (tok::r_square, StopAtSemi))
2370- return TPResult::Error;
2371- break ;
2372- case tok::question:
2351+ case tok::comma:
2352+ case tok::greater:
2353+ case tok::greatergreater:
2354+ case tok::greatergreatergreater:
2355+ return TPResult::True;
2356+
2357+ case tok::l_paren:
2358+ ConsumeParen ();
2359+ if (!SkipUntil (tok::r_paren, StopAtSemi))
2360+ return TPResult::Error;
2361+ break ;
2362+ case tok::l_brace:
2363+ ConsumeBrace ();
2364+ if (!SkipUntil (tok::r_brace, StopAtSemi))
2365+ return TPResult::Error;
2366+ break ;
2367+ case tok::l_square:
2368+ ConsumeBracket ();
2369+ if (!SkipUntil (tok::r_square, StopAtSemi))
2370+ return TPResult::Error;
2371+ break ;
2372+ case tok::question:
23732373 ConsumeToken ();
23742374 if (!SkipUntil (tok::colon, StopAtSemi))
2375- return TPResult::Error;
2375+ return TPResult::Error;
23762376 break ;
23772377
2378- #if 0
2378+ #if 0
23792379 case tok::kw_template:
23802380 ConsumeToken();
23812381 NextIsTemplateId = true;
23822382 continue;
2383- #endif
2384- case tok::identifier:
2385- ConsumeToken ();
2386- #if 0
2383+ #endif
2384+ case tok::identifier:
2385+ ConsumeToken ();
2386+ #if 0
23872387 if (Tok.is(tok::less)) {
23882388 if (!NextIsTemplateId)
23892389 return TPResult::Ambiguous;
@@ -2392,23 +2392,23 @@ Parser::TPResult Parser::isTemplateArgumentList(unsigned TokensToSkip, TemplateN
23922392 return TPResult::Error;
23932393 break;
23942394 }
2395- #else
2395+ #else
2396+ if (Tok.is (tok::less))
2397+ return TPResult::Ambiguous;
2398+ break ;
2399+ #endif
2400+
2401+ case tok::kw_operator:
2402+ if (TPResult TPR = TryParseNonConversionOperatorId ();
2403+ TPR == TPResult::Error) {
2404+ return TPResult::Error;
2405+ } else if (TPR == TPResult::True) {
23962406 if (Tok.is (tok::less))
23972407 return TPResult::Ambiguous;
2398- break ;
2399- #endif
2400-
2401- case tok::kw_operator:
2402- if (TPResult TPR = TryParseNonConversionOperatorId ();
2403- TPR == TPResult::Error) {
2404- return TPResult::Error;
2405- } else if (TPR == TPResult::True) {
2406- if (Tok.is (tok::less))
2407- return TPResult::Ambiguous;
2408- }
2409- break ;
2408+ }
2409+ break ;
24102410
2411- #if 0
2411+ #if 0
24122412 if (Tok.is(tok::less)) {
24132413 if (!NextIsTemplateId)
24142414 return TPResult::Ambiguous;
@@ -2417,40 +2417,42 @@ Parser::TPResult Parser::isTemplateArgumentList(unsigned TokensToSkip, TemplateN
24172417 return TPResult::Error;
24182418 }
24192419 break;
2420- #endif
2420+ #endif
24212421
2422- case tok::kw_const_cast:
2423- case tok::kw_dynamic_cast:
2424- case tok::kw_reinterpret_cast:
2425- case tok::kw_static_cast: {
2426- ConsumeToken ();
2427- if (!TryConsumeToken (tok::less))
2428- return TPResult::Error;
2429- bool MayHaveTrailingReturnType = Tok.is (tok::kw_auto);
2430-
2431- while (true ) {
2432- TPResult TPR = isCXXDeclarationSpecifier (ImplicitTypenameContext::Yes);
2433- if (TPR == TPResult::False)
2434- break ;
2435- if (TPR == TPResult::Error ||
2436- TryConsumeDeclarationSpecifier () == TPResult::Error)
2437- return TPResult::Error;
2438- }
2439-
2440- if (TryParseDeclarator (
2441- /* mayBeAbstract=*/ true ,
2442- /* mayHaveIdentifier=*/ false ,
2443- /* mayHaveDirectInit=*/ false ,
2444- /* mayHaveTrailingReturnType=*/ MayHaveTrailingReturnType) == TPResult::Error)
2445- return TPResult::Error;
2422+ case tok::kw_const_cast:
2423+ case tok::kw_dynamic_cast:
2424+ case tok::kw_reinterpret_cast:
2425+ case tok::kw_static_cast: {
2426+ ConsumeToken ();
2427+ if (!TryConsumeToken (tok::less))
2428+ return TPResult::Error;
2429+ bool MayHaveTrailingReturnType = Tok.is (tok::kw_auto);
24462430
2447- if (!TryConsumeToken (tok::greater))
2431+ while (true ) {
2432+ TPResult TPR =
2433+ isCXXDeclarationSpecifier (ImplicitTypenameContext::Yes);
2434+ if (TPR == TPResult::False)
2435+ break ;
2436+ if (TPR == TPResult::Error ||
2437+ TryConsumeDeclarationSpecifier () == TPResult::Error)
24482438 return TPResult::Error;
2449- break ;
24502439 }
2451- default :
2452- ConsumeAnyToken ();
2453- break ;
2440+
2441+ if (TryParseDeclarator (
2442+ /* mayBeAbstract=*/ true ,
2443+ /* mayHaveIdentifier=*/ false ,
2444+ /* mayHaveDirectInit=*/ false ,
2445+ /* mayHaveTrailingReturnType=*/ MayHaveTrailingReturnType) ==
2446+ TPResult::Error)
2447+ return TPResult::Error;
2448+
2449+ if (!TryConsumeToken (tok::greater))
2450+ return TPResult::Error;
2451+ break ;
2452+ }
2453+ default :
2454+ ConsumeAnyToken ();
2455+ break ;
24542456 }
24552457 NextIsTemplateId = false ;
24562458 }
@@ -2466,9 +2468,10 @@ Parser::TPResult Parser::isTemplateArgumentList(unsigned TokensToSkip, TemplateN
24662468 return TPResult::Error;
24672469
24682470 bool InvalidAsTemplateArgumentList = false ;
2469- TPResult TPR = isCXXDeclarationSpecifier (ImplicitTypenameContext::No,
2470- /* BracedCastResult=*/ TPResult::Ambiguous,
2471- &InvalidAsTemplateArgumentList);
2471+ TPResult TPR =
2472+ isCXXDeclarationSpecifier (ImplicitTypenameContext::No,
2473+ /* BracedCastResult=*/ TPResult::Ambiguous,
2474+ &InvalidAsTemplateArgumentList);
24722475 if (InvalidAsTemplateArgumentList)
24732476 return TPResult::False;
24742477
@@ -2505,7 +2508,7 @@ Parser::TPResult Parser::isTemplateArgumentList(unsigned TokensToSkip, TemplateN
25052508 }
25062509 }
25072510
2508- #if 0
2511+ #if 0
25092512 // We can't do much to tell an expression apart from a template-argument,
25102513 // but one good distinguishing factor is that a "decl-specifier" not
25112514 // followed by '(' or '{' can't appear in an expression.
@@ -2516,7 +2519,7 @@ Parser::TPResult Parser::isTemplateArgumentList(unsigned TokensToSkip, TemplateN
25162519 return TPResult::True;
25172520 if (InvalidAsTemplateArgumentList)
25182521 return TPResult::False;
2519- #endif
2522+ #endif
25202523
25212524 // FIXME: In many contexts, X<thing1, Type> can only be a
25222525 // template-argument-list. But that's not true in general:
0 commit comments