Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/Parse/ParseTentative.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- ParseTentative.cpp - Ambiguity Resolution 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 the tentative parsing portions of the Parser
10
//  interfaces, for ambiguity resolution.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "clang/Parse/Parser.h"
15
#include "clang/Parse/ParseDiagnostic.h"
16
#include "clang/Sema/ParsedTemplate.h"
17
using namespace clang;
18
19
/// isCXXDeclarationStatement - C++-specialized function that disambiguates
20
/// between a declaration or an expression statement, when parsing function
21
/// bodies. Returns true for declaration, false for expression.
22
///
23
///         declaration-statement:
24
///           block-declaration
25
///
26
///         block-declaration:
27
///           simple-declaration
28
///           asm-definition
29
///           namespace-alias-definition
30
///           using-declaration
31
///           using-directive
32
/// [C++0x]   static_assert-declaration
33
///
34
///         asm-definition:
35
///           'asm' '(' string-literal ')' ';'
36
///
37
///         namespace-alias-definition:
38
///           'namespace' identifier = qualified-namespace-specifier ';'
39
///
40
///         using-declaration:
41
///           'using' typename[opt] '::'[opt] nested-name-specifier
42
///                 unqualified-id ';'
43
///           'using' '::' unqualified-id ;
44
///
45
///         using-directive:
46
///           'using' 'namespace' '::'[opt] nested-name-specifier[opt]
47
///                 namespace-name ';'
48
///
49
3.42M
bool Parser::isCXXDeclarationStatement() {
50
3.42M
  switch (Tok.getKind()) {
51
3.42M
    // asm-definition
52
3.42M
  case tok::kw_asm:
53
28.8k
    // namespace-alias-definition
54
28.8k
  case tok::kw_namespace:
55
28.8k
    // using-declaration
56
28.8k
    // using-directive
57
28.8k
  case tok::kw_using:
58
28.8k
    // static_assert-declaration
59
28.8k
  case tok::kw_static_assert:
60
28.8k
  case tok::kw__Static_assert:
61
28.8k
    return true;
62
28.8k
    // simple-declaration
63
3.39M
  default:
64
3.39M
    return isCXXSimpleDeclaration(/*AllowForRangeDecl=*/false);
65
3.42M
  }
66
3.42M
}
67
68
/// isCXXSimpleDeclaration - C++-specialized function that disambiguates
69
/// between a simple-declaration or an expression-statement.
70
/// If during the disambiguation process a parsing error is encountered,
71
/// the function returns true to let the declaration parsing code handle it.
72
/// Returns false if the statement is disambiguated as expression.
73
///
74
/// simple-declaration:
75
///   decl-specifier-seq init-declarator-list[opt] ';'
76
///   decl-specifier-seq ref-qualifier[opt] '[' identifier-list ']'
77
///                      brace-or-equal-initializer ';'    [C++17]
78
///
79
/// (if AllowForRangeDecl specified)
80
/// for ( for-range-declaration : for-range-initializer ) statement
81
///
82
/// for-range-declaration:
83
///    decl-specifier-seq declarator
84
///    decl-specifier-seq ref-qualifier[opt] '[' identifier-list ']'
85
///
86
/// In any of the above cases there can be a preceding attribute-specifier-seq,
87
/// but the caller is expected to handle that.
88
3.54M
bool Parser::isCXXSimpleDeclaration(bool AllowForRangeDecl) {
89
3.54M
  // C++ 6.8p1:
90
3.54M
  // There is an ambiguity in the grammar involving expression-statements and
91
3.54M
  // declarations: An expression-statement with a function-style explicit type
92
3.54M
  // conversion (5.2.3) as its leftmost subexpression can be indistinguishable
93
3.54M
  // from a declaration where the first declarator starts with a '('. In those
94
3.54M
  // cases the statement is a declaration. [Note: To disambiguate, the whole
95
3.54M
  // statement might have to be examined to determine if it is an
96
3.54M
  // expression-statement or a declaration].
97
3.54M
98
3.54M
  // C++ 6.8p3:
99
3.54M
  // The disambiguation is purely syntactic; that is, the meaning of the names
100
3.54M
  // occurring in such a statement, beyond whether they are type-names or not,
101
3.54M
  // is not generally used in or changed by the disambiguation. Class
102
3.54M
  // templates are instantiated as necessary to determine if a qualified name
103
3.54M
  // is a type-name. Disambiguation precedes parsing, and a statement
104
3.54M
  // disambiguated as a declaration may be an ill-formed declaration.
105
3.54M
106
3.54M
  // We don't have to parse all of the decl-specifier-seq part. There's only
107
3.54M
  // an ambiguity if the first decl-specifier is
108
3.54M
  // simple-type-specifier/typename-specifier followed by a '(', which may
109
3.54M
  // indicate a function-style cast expression.
110
3.54M
  // isCXXDeclarationSpecifier will return TPResult::Ambiguous only in such
111
3.54M
  // a case.
112
3.54M
113
3.54M
  bool InvalidAsDeclaration = false;
114
3.54M
  TPResult TPR = isCXXDeclarationSpecifier(TPResult::False,
115
3.54M
                                           &InvalidAsDeclaration);
116
3.54M
  if (TPR != TPResult::Ambiguous)
117
3.47M
    return TPR != TPResult::False; // Returns true for TPResult::True or
118
63.0k
                                   // TPResult::Error.
119
63.0k
120
63.0k
  // FIXME: TryParseSimpleDeclaration doesn't look past the first initializer,
121
63.0k
  // and so gets some cases wrong. We can't carry on if we've already seen
122
63.0k
  // something which makes this statement invalid as a declaration in this case,
123
63.0k
  // since it can cause us to misparse valid code. Revisit this once
124
63.0k
  // TryParseInitDeclaratorList is fixed.
125
63.0k
  if (InvalidAsDeclaration)
126
44.2k
    return false;
127
18.7k
128
18.7k
  // FIXME: Add statistics about the number of ambiguous statements encountered
129
18.7k
  // and how they were resolved (number of declarations+number of expressions).
130
18.7k
131
18.7k
  // Ok, we have a simple-type-specifier/typename-specifier followed by a '(',
132
18.7k
  // or an identifier which doesn't resolve as anything. We need tentative
133
18.7k
  // parsing...
134
18.7k
135
18.7k
  {
136
18.7k
    RevertingTentativeParsingAction PA(*this);
137
18.7k
    TPR = TryParseSimpleDeclaration(AllowForRangeDecl);
138
18.7k
  }
139
18.7k
140
18.7k
  // In case of an error, let the declaration parsing code handle it.
141
18.7k
  if (TPR == TPResult::Error)
142
0
    return true;
143
18.7k
144
18.7k
  // Declarations take precedence over expressions.
145
18.7k
  if (TPR == TPResult::Ambiguous)
146
356
    TPR = TPResult::True;
147
18.7k
148
18.7k
  assert(TPR == TPResult::True || TPR == TPResult::False);
149
18.7k
  return TPR == TPResult::True;
150
18.7k
}
151
152
/// Try to consume a token sequence that we've already identified as
153
/// (potentially) starting a decl-specifier.
154
97.5k
Parser::TPResult Parser::TryConsumeDeclarationSpecifier() {
155
97.5k
  switch (Tok.getKind()) {
156
97.5k
  case tok::kw__Atomic:
157
0
    if (NextToken().isNot(tok::l_paren)) {
158
0
      ConsumeToken();
159
0
      break;
160
0
    }
161
0
    LLVM_FALLTHROUGH;
162
14
  case tok::kw_typeof:
163
14
  case tok::kw___attribute:
164
14
  case tok::kw___underlying_type: {
165
14
    ConsumeToken();
166
14
    if (Tok.isNot(tok::l_paren))
167
0
      return TPResult::Error;
168
14
    ConsumeParen();
169
14
    if (!SkipUntil(tok::r_paren))
170
0
      return TPResult::Error;
171
14
    break;
172
14
  }
173
14
174
14
  case tok::kw_class:
175
5
  case tok::kw_struct:
176
5
  case tok::kw_union:
177
5
  case tok::kw___interface:
178
5
  case tok::kw_enum:
179
5
    // elaborated-type-specifier:
180
5
    //     class-key attribute-specifier-seq[opt]
181
5
    //         nested-name-specifier[opt] identifier
182
5
    //     class-key nested-name-specifier[opt] template[opt] simple-template-id
183
5
    //     enum nested-name-specifier[opt] identifier
184
5
    //
185
5
    // FIXME: We don't support class-specifiers nor enum-specifiers here.
186
5
    ConsumeToken();
187
5
188
5
    // Skip attributes.
189
6
    while (Tok.isOneOf(tok::l_square, tok::kw___attribute, tok::kw___declspec,
190
6
                       tok::kw_alignas)) {
191
1
      if (Tok.is(tok::l_square)) {
192
0
        ConsumeBracket();
193
0
        if (!SkipUntil(tok::r_square))
194
0
          return TPResult::Error;
195
1
      } else {
196
1
        ConsumeToken();
197
1
        if (Tok.isNot(tok::l_paren))
198
0
          return TPResult::Error;
199
1
        ConsumeParen();
200
1
        if (!SkipUntil(tok::r_paren))
201
0
          return TPResult::Error;
202
1
      }
203
1
    }
204
5
205
5
    if (Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw_decltype,
206
5
                    tok::annot_template_id) &&
207
5
        
TryAnnotateCXXScopeToken()4
)
208
1
      return TPResult::Error;
209
4
    if (Tok.is(tok::annot_cxxscope))
210
0
      ConsumeAnnotationToken();
211
4
    if (Tok.is(tok::identifier))
212
3
      ConsumeToken();
213
1
    else if (Tok.is(tok::annot_template_id))
214
0
      ConsumeAnnotationToken();
215
1
    else
216
1
      return TPResult::Error;
217
3
    break;
218
3
219
689
  case tok::annot_cxxscope:
220
689
    ConsumeAnnotationToken();
221
689
    LLVM_FALLTHROUGH;
222
97.5k
  default:
223
97.5k
    ConsumeAnyToken();
224
97.5k
225
97.5k
    if (getLangOpts().ObjC && 
Tok.is(tok::less)494
)
226
0
      return TryParseProtocolQualifiers();
227
97.5k
    break;
228
97.5k
  }
229
97.5k
230
97.5k
  return TPResult::Ambiguous;
231
97.5k
}
232
233
/// simple-declaration:
234
///   decl-specifier-seq init-declarator-list[opt] ';'
235
///
236
/// (if AllowForRangeDecl specified)
237
/// for ( for-range-declaration : for-range-initializer ) statement
238
/// for-range-declaration:
239
///    attribute-specifier-seqopt type-specifier-seq declarator
240
///
241
18.7k
Parser::TPResult Parser::TryParseSimpleDeclaration(bool AllowForRangeDecl) {
242
18.7k
  if (TryConsumeDeclarationSpecifier() == TPResult::Error)
243
0
    return TPResult::Error;
244
18.7k
245
18.7k
  // Two decl-specifiers in a row conclusively disambiguate this as being a
246
18.7k
  // simple-declaration. Don't bother calling isCXXDeclarationSpecifier in the
247
18.7k
  // overwhelmingly common case that the next token is a '('.
248
18.7k
  if (Tok.isNot(tok::l_paren)) {
249
176
    TPResult TPR = isCXXDeclarationSpecifier();
250
176
    if (TPR == TPResult::Ambiguous)
251
0
      return TPResult::True;
252
176
    if (TPR == TPResult::True || TPR == TPResult::Error)
253
0
      return TPR;
254
176
    assert(TPR == TPResult::False);
255
176
  }
256
18.7k
257
18.7k
  TPResult TPR = TryParseInitDeclaratorList();
258
18.7k
  if (TPR != TPResult::Ambiguous)
259
16.2k
    return TPR;
260
2.46k
261
2.46k
  if (Tok.isNot(tok::semi) && 
(2.11k
!AllowForRangeDecl2.11k
||
Tok.isNot(tok::colon)8
))
262
2.11k
    return TPResult::False;
263
356
264
356
  return TPResult::Ambiguous;
265
356
}
266
267
/// Tentatively parse an init-declarator-list in order to disambiguate it from
268
/// an expression.
269
///
270
///       init-declarator-list:
271
///         init-declarator
272
///         init-declarator-list ',' init-declarator
273
///
274
///       init-declarator:
275
///         declarator initializer[opt]
276
/// [GNU]   declarator simple-asm-expr[opt] attributes[opt] initializer[opt]
277
///
278
///       initializer:
279
///         brace-or-equal-initializer
280
///         '(' expression-list ')'
281
///
282
///       brace-or-equal-initializer:
283
///         '=' initializer-clause
284
/// [C++11] braced-init-list
285
///
286
///       initializer-clause:
287
///         assignment-expression
288
///         braced-init-list
289
///
290
///       braced-init-list:
291
///         '{' initializer-list ','[opt] '}'
292
///         '{' '}'
293
///
294
18.7k
Parser::TPResult Parser::TryParseInitDeclaratorList() {
295
18.8k
  while (1) {
296
18.8k
    // declarator
297
18.8k
    TPResult TPR = TryParseDeclarator(false/*mayBeAbstract*/);
298
18.8k
    if (TPR != TPResult::Ambiguous)
299
15.0k
      return TPR;
300
3.74k
301
3.74k
    // [GNU] simple-asm-expr[opt] attributes[opt]
302
3.74k
    if (Tok.isOneOf(tok::kw_asm, tok::kw___attribute))
303
8
      return TPResult::True;
304
3.73k
305
3.73k
    // initializer[opt]
306
3.73k
    if (Tok.is(tok::l_paren)) {
307
11
      // Parse through the parens.
308
11
      ConsumeParen();
309
11
      if (!SkipUntil(tok::r_paren, StopAtSemi))
310
0
        return TPResult::Error;
311
3.72k
    } else if (Tok.is(tok::l_brace)) {
312
2
      // A left-brace here is sufficient to disambiguate the parse; an
313
2
      // expression can never be followed directly by a braced-init-list.
314
2
      return TPResult::True;
315
3.72k
    } else if (Tok.is(tok::equal) || 
isTokIdentifier_in()2.49k
) {
316
1.23k
      // MSVC and g++ won't examine the rest of declarators if '=' is
317
1.23k
      // encountered; they just conclude that we have a declaration.
318
1.23k
      // EDG parses the initializer completely, which is the proper behavior
319
1.23k
      // for this case.
320
1.23k
      //
321
1.23k
      // At present, Clang follows MSVC and g++, since the parser does not have
322
1.23k
      // the ability to parse an expression fully without recording the
323
1.23k
      // results of that parse.
324
1.23k
      // FIXME: Handle this case correctly.
325
1.23k
      //
326
1.23k
      // Also allow 'in' after an Objective-C declaration as in:
327
1.23k
      // for (int (^b)(void) in array). Ideally this should be done in the
328
1.23k
      // context of parsing for-init-statement of a foreach statement only. But,
329
1.23k
      // in any other context 'in' is invalid after a declaration and parser
330
1.23k
      // issues the error regardless of outcome of this decision.
331
1.23k
      // FIXME: Change if above assumption does not hold.
332
1.23k
      return TPResult::True;
333
1.23k
    }
334
2.50k
335
2.50k
    if (!TryConsumeToken(tok::comma))
336
2.48k
      break;
337
2.50k
  }
338
18.7k
339
18.7k
  
return TPResult::Ambiguous2.48k
;
340
18.7k
}
341
342
struct Parser::ConditionDeclarationOrInitStatementState {
343
  Parser &P;
344
  bool CanBeExpression = true;
345
  bool CanBeCondition = true;
346
  bool CanBeInitStatement;
347
  bool CanBeForRangeDecl;
348
349
  ConditionDeclarationOrInitStatementState(Parser &P, bool CanBeInitStatement,
350
                                           bool CanBeForRangeDecl)
351
      : P(P), CanBeInitStatement(CanBeInitStatement),
352
1.07M
        CanBeForRangeDecl(CanBeForRangeDecl) {}
353
354
1.07M
  bool resolved() {
355
1.07M
    return CanBeExpression + CanBeCondition + CanBeInitStatement +
356
1.07M
               CanBeForRangeDecl < 2;
357
1.07M
  }
358
359
3.53k
  void markNotExpression() {
360
3.53k
    CanBeExpression = false;
361
3.53k
362
3.53k
    if (!resolved()) {
363
3.11k
      // FIXME: Unify the parsing codepaths for condition variables and
364
3.11k
      // simple-declarations so that we don't need to eagerly figure out which
365
3.11k
      // kind we have here. (Just parse init-declarators until we reach a
366
3.11k
      // semicolon or right paren.)
367
3.11k
      RevertingTentativeParsingAction PA(P);
368
3.11k
      if (CanBeForRangeDecl) {
369
114
        // Skip until we hit a ')', ';', or a ':' with no matching '?'.
370
114
        // The final case is a for range declaration, the rest are not.
371
115
        while (true) {
372
115
          unsigned QuestionColonDepth = 0;
373
115
          P.SkipUntil({tok::r_paren, tok::semi, tok::question, tok::colon},
374
115
                      StopBeforeMatch);
375
115
          if (P.Tok.is(tok::question))
376
1
            ++QuestionColonDepth;
377
114
          else if (P.Tok.is(tok::colon)) {
378
34
            if (QuestionColonDepth)
379
0
              --QuestionColonDepth;
380
34
            else {
381
34
              CanBeCondition = CanBeInitStatement = false;
382
34
              return;
383
34
            }
384
80
          } else {
385
80
            CanBeForRangeDecl = false;
386
80
            break;
387
80
          }
388
1
          P.ConsumeToken();
389
1
        }
390
3.00k
      } else {
391
3.00k
        // Just skip until we hit a ')' or ';'.
392
3.00k
        P.SkipUntil(tok::r_paren, tok::semi, StopBeforeMatch);
393
3.00k
      }
394
3.11k
      
if (3.08k
P.Tok.isNot(tok::r_paren)3.08k
)
395
150
        CanBeCondition = CanBeForRangeDecl = false;
396
3.08k
      if (P.Tok.isNot(tok::semi))
397
2.93k
        CanBeInitStatement = false;
398
3.08k
    }
399
3.53k
  }
400
401
30
  bool markNotCondition() {
402
30
    CanBeCondition = false;
403
30
    return resolved();
404
30
  }
405
406
30
  bool markNotForRangeDecl() {
407
30
    CanBeForRangeDecl = false;
408
30
    return resolved();
409
30
  }
410
411
1.07M
  bool update(TPResult IsDecl) {
412
1.07M
    switch (IsDecl) {
413
1.07M
    case TPResult::True:
414
3.52k
      markNotExpression();
415
3.52k
      assert(resolved() && "can't continue after tentative parsing bails out");
416
3.52k
      break;
417
1.07M
    case TPResult::False:
418
1.06M
      CanBeCondition = CanBeInitStatement = CanBeForRangeDecl = false;
419
1.06M
      break;
420
1.07M
    case TPResult::Ambiguous:
421
1.43k
      break;
422
1.07M
    case TPResult::Error:
423
0
      CanBeExpression = CanBeCondition = CanBeInitStatement =
424
0
          CanBeForRangeDecl = false;
425
0
      break;
426
1.07M
    }
427
1.07M
    return resolved();
428
1.07M
  }
429
430
1.07M
  ConditionOrInitStatement result() const {
431
1.07M
    assert(CanBeExpression + CanBeCondition + CanBeInitStatement +
432
1.07M
                   CanBeForRangeDecl < 2 &&
433
1.07M
           "result called but not yet resolved");
434
1.07M
    if (CanBeExpression)
435
1.06M
      return ConditionOrInitStatement::Expression;
436
3.53k
    if (CanBeCondition)
437
3.35k
      return ConditionOrInitStatement::ConditionDecl;
438
184
    if (CanBeInitStatement)
439
69
      return ConditionOrInitStatement::InitStmtDecl;
440
115
    if (CanBeForRangeDecl)
441
34
      return ConditionOrInitStatement::ForRangeDecl;
442
81
    return ConditionOrInitStatement::Error;
443
81
  }
444
};
445
446
/// Disambiguates between a declaration in a condition, a
447
/// simple-declaration in an init-statement, and an expression for
448
/// a condition of a if/switch statement.
449
///
450
///       condition:
451
///         expression
452
///         type-specifier-seq declarator '=' assignment-expression
453
/// [C++11] type-specifier-seq declarator '=' initializer-clause
454
/// [C++11] type-specifier-seq declarator braced-init-list
455
/// [GNU]   type-specifier-seq declarator simple-asm-expr[opt] attributes[opt]
456
///             '=' assignment-expression
457
///       simple-declaration:
458
///         decl-specifier-seq init-declarator-list[opt] ';'
459
///
460
/// Note that, unlike isCXXSimpleDeclaration, we must disambiguate all the way
461
/// to the ';' to disambiguate cases like 'int(x))' (an expression) from
462
/// 'int(x);' (a simple-declaration in an init-statement).
463
Parser::ConditionOrInitStatement
464
Parser::isCXXConditionDeclarationOrInitStatement(bool CanBeInitStatement,
465
1.07M
                                                 bool CanBeForRangeDecl) {
466
1.07M
  ConditionDeclarationOrInitStatementState State(*this, CanBeInitStatement,
467
1.07M
                                                 CanBeForRangeDecl);
468
1.07M
469
1.07M
  if (State.update(isCXXDeclarationSpecifier()))
470
1.06M
    return State.result();
471
696
472
696
  // It might be a declaration; we need tentative parsing.
473
696
  RevertingTentativeParsingAction PA(*this);
474
696
475
696
  // FIXME: A tag definition unambiguously tells us this is an init-statement.
476
696
  if (State.update(TryConsumeDeclarationSpecifier()))
477
0
    return State.result();
478
696
  assert(Tok.is(tok::l_paren) && "Expected '('");
479
696
480
702
  while (true) {
481
702
    // Consume a declarator.
482
702
    if (State.update(TryParseDeclarator(false/*mayBeAbstract*/)))
483
659
      return State.result();
484
43
485
43
    // Attributes, asm label, or an initializer imply this is not an expression.
486
43
    // FIXME: Disambiguate properly after an = instead of assuming that it's a
487
43
    // valid declaration.
488
43
    if (Tok.isOneOf(tok::equal, tok::kw_asm, tok::kw___attribute) ||
489
43
        
(34
getLangOpts().CPlusPlus1134
&&
Tok.is(tok::l_brace)33
)) {
490
11
      State.markNotExpression();
491
11
      return State.result();
492
11
    }
493
32
494
32
    // A colon here identifies a for-range declaration.
495
32
    if (State.CanBeForRangeDecl && 
Tok.is(tok::colon)3
)
496
2
      return ConditionOrInitStatement::ForRangeDecl;
497
30
498
30
    // At this point, it can't be a condition any more, because a condition
499
30
    // must have a brace-or-equal-initializer.
500
30
    if (State.markNotCondition())
501
0
      return State.result();
502
30
503
30
    // Likewise, it can't be a for-range declaration any more.
504
30
    if (State.markNotForRangeDecl())
505
1
      return State.result();
506
29
507
29
    // A parenthesized initializer could be part of an expression or a
508
29
    // simple-declaration.
509
29
    if (Tok.is(tok::l_paren)) {
510
1
      ConsumeParen();
511
1
      SkipUntil(tok::r_paren, StopAtSemi);
512
1
    }
513
29
514
29
    if (!TryConsumeToken(tok::comma))
515
23
      break;
516
29
  }
517
696
518
696
  // We reached the end. If it can now be some kind of decl, then it is.
519
696
  
if (23
State.CanBeCondition23
&&
Tok.is(tok::r_paren)0
)
520
0
    return ConditionOrInitStatement::ConditionDecl;
521
23
  else if (State.CanBeInitStatement && Tok.is(tok::semi))
522
2
    return ConditionOrInitStatement::InitStmtDecl;
523
21
  else
524
21
    return ConditionOrInitStatement::Expression;
525
23
}
526
527
  /// Determine whether the next set of tokens contains a type-id.
528
  ///
529
  /// The context parameter states what context we're parsing right
530
  /// now, which affects how this routine copes with the token
531
  /// following the type-id. If the context is TypeIdInParens, we have
532
  /// already parsed the '(' and we will cease lookahead when we hit
533
  /// the corresponding ')'. If the context is
534
  /// TypeIdAsTemplateArgument, we've already parsed the '<' or ','
535
  /// before this template argument, and will cease lookahead when we
536
  /// hit a '>', '>>' (in C++0x), or ','; or, in C++0x, an ellipsis immediately
537
  /// preceding such. Returns true for a type-id and false for an expression.
538
  /// If during the disambiguation process a parsing error is encountered,
539
  /// the function returns true to let the declaration parsing code handle it.
540
  ///
541
  /// type-id:
542
  ///   type-specifier-seq abstract-declarator[opt]
543
  ///
544
7.36M
bool Parser::isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous) {
545
7.36M
546
7.36M
  isAmbiguous = false;
547
7.36M
548
7.36M
  // C++ 8.2p2:
549
7.36M
  // The ambiguity arising from the similarity between a function-style cast and
550
7.36M
  // a type-id can occur in different contexts. The ambiguity appears as a
551
7.36M
  // choice between a function-style cast expression and a declaration of a
552
7.36M
  // type. The resolution is that any construct that could possibly be a type-id
553
7.36M
  // in its syntactic context shall be considered a type-id.
554
7.36M
555
7.36M
  TPResult TPR = isCXXDeclarationSpecifier();
556
7.36M
  if (TPR != TPResult::Ambiguous)
557
7.30M
    return TPR != TPResult::False; // Returns true for TPResult::True or
558
58.6k
                                     // TPResult::Error.
559
58.6k
560
58.6k
  // FIXME: Add statistics about the number of ambiguous statements encountered
561
58.6k
  // and how they were resolved (number of declarations+number of expressions).
562
58.6k
563
58.6k
  // Ok, we have a simple-type-specifier/typename-specifier followed by a '('.
564
58.6k
  // We need tentative parsing...
565
58.6k
566
58.6k
  RevertingTentativeParsingAction PA(*this);
567
58.6k
568
58.6k
  // type-specifier-seq
569
58.6k
  TryConsumeDeclarationSpecifier();
570
58.6k
  assert(Tok.is(tok::l_paren) && "Expected '('");
571
58.6k
572
58.6k
  // declarator
573
58.6k
  TPR = TryParseDeclarator(true/*mayBeAbstract*/, false/*mayHaveIdentifier*/);
574
58.6k
575
58.6k
  // In case of an error, let the declaration parsing code handle it.
576
58.6k
  if (TPR == TPResult::Error)
577
0
    TPR = TPResult::True;
578
58.6k
579
58.6k
  if (TPR == TPResult::Ambiguous) {
580
51.2k
    // We are supposed to be inside parens, so if after the abstract declarator
581
51.2k
    // we encounter a ')' this is a type-id, otherwise it's an expression.
582
51.2k
    if (Context == TypeIdInParens && 
Tok.is(tok::r_paren)1.30k
) {
583
1.11k
      TPR = TPResult::True;
584
1.11k
      isAmbiguous = true;
585
1.11k
586
1.11k
    // We are supposed to be inside a template argument, so if after
587
1.11k
    // the abstract declarator we encounter a '>', '>>' (in C++0x), or
588
1.11k
    // ','; or, in C++0x, an ellipsis immediately preceding such, this
589
1.11k
    // is a type-id. Otherwise, it's an expression.
590
50.1k
    } else if (Context == TypeIdAsTemplateArgument &&
591
50.1k
               
(49.9k
Tok.isOneOf(tok::greater, tok::comma)49.9k
||
592
49.9k
                
(13
getLangOpts().CPlusPlus1113
&&
593
13
                 (Tok.isOneOf(tok::greatergreater,
594
13
                              tok::greatergreatergreater) ||
595
13
                  
(12
Tok.is(tok::ellipsis)12
&&
596
12
                   NextToken().isOneOf(tok::greater, tok::greatergreater,
597
4
                                       tok::greatergreatergreater,
598
49.9k
                                       tok::comma)))))) {
599
49.9k
      TPR = TPResult::True;
600
49.9k
      isAmbiguous = true;
601
49.9k
602
49.9k
    } else
603
198
      TPR = TPResult::False;
604
51.2k
  }
605
58.6k
606
58.6k
  assert(TPR == TPResult::True || TPR == TPResult::False);
607
58.6k
  return TPR == TPResult::True;
608
58.6k
}
609
610
/// Returns true if this is a C++11 attribute-specifier. Per
611
/// C++11 [dcl.attr.grammar]p6, two consecutive left square bracket tokens
612
/// always introduce an attribute. In Objective-C++11, this rule does not
613
/// apply if either '[' begins a message-send.
614
///
615
/// If Disambiguate is true, we try harder to determine whether a '[[' starts
616
/// an attribute-specifier, and return CAK_InvalidAttributeSpecifier if not.
617
///
618
/// If OuterMightBeMessageSend is true, we assume the outer '[' is either an
619
/// Obj-C message send or the start of an attribute. Otherwise, we assume it
620
/// is not an Obj-C message send.
621
///
622
/// C++11 [dcl.attr.grammar]:
623
///
624
///     attribute-specifier:
625
///         '[' '[' attribute-list ']' ']'
626
///         alignment-specifier
627
///
628
///     attribute-list:
629
///         attribute[opt]
630
///         attribute-list ',' attribute[opt]
631
///         attribute '...'
632
///         attribute-list ',' attribute '...'
633
///
634
///     attribute:
635
///         attribute-token attribute-argument-clause[opt]
636
///
637
///     attribute-token:
638
///         identifier
639
///         identifier '::' identifier
640
///
641
///     attribute-argument-clause:
642
///         '(' balanced-token-seq ')'
643
Parser::CXX11AttributeKind
644
Parser::isCXX11AttributeSpecifier(bool Disambiguate,
645
49.0M
                                  bool OuterMightBeMessageSend) {
646
49.0M
  if (Tok.is(tok::kw_alignas))
647
10.8k
    return CAK_AttributeSpecifier;
648
49.0M
649
49.0M
  if (Tok.isNot(tok::l_square) || 
NextToken().isNot(tok::l_square)195k
)
650
48.9M
    return CAK_NotAttributeSpecifier;
651
10.1k
652
10.1k
  // No tentative parsing if we don't need to look for ']]' or a lambda.
653
10.1k
  if (!Disambiguate && 
!getLangOpts().ObjC10.1k
)
654
10.0k
    return CAK_AttributeSpecifier;
655
128
656
128
  // '[[using ns: ...]]' is an attribute.
657
128
  if (GetLookAheadToken(2).is(tok::kw_using))
658
0
    return CAK_AttributeSpecifier;
659
128
660
128
  RevertingTentativeParsingAction PA(*this);
661
128
662
128
  // Opening brackets were checked for above.
663
128
  ConsumeBracket();
664
128
665
128
  if (!getLangOpts().ObjC) {
666
8
    ConsumeBracket();
667
8
668
8
    bool IsAttribute = SkipUntil(tok::r_square);
669
8
    IsAttribute &= Tok.is(tok::r_square);
670
8
671
8
    return IsAttribute ? 
CAK_AttributeSpecifier4
:
CAK_InvalidAttributeSpecifier4
;
672
8
  }
673
120
674
120
  // In Obj-C++11, we need to distinguish four situations:
675
120
  //  1a) int x[[attr]];                     C++11 attribute.
676
120
  //  1b) [[attr]];                          C++11 statement attribute.
677
120
  //   2) int x[[obj](){ return 1; }()];     Lambda in array size/index.
678
120
  //  3a) int x[[obj get]];                  Message send in array size/index.
679
120
  //  3b) [[Class alloc] init];              Message send in message send.
680
120
  //   4) [[obj]{ return self; }() doStuff]; Lambda in message send.
681
120
  // (1) is an attribute, (2) is ill-formed, and (3) and (4) are accepted.
682
120
683
120
  // Check to see if this is a lambda-expression.
684
120
  // FIXME: If this disambiguation is too slow, fold the tentative lambda parse
685
120
  // into the tentative attribute parse below.
686
120
  {
687
120
    RevertingTentativeParsingAction LambdaTPA(*this);
688
120
    LambdaIntroducer Intro;
689
120
    LambdaIntroducerTentativeParse Tentative;
690
120
    if (ParseLambdaIntroducer(Intro, &Tentative)) {
691
0
      // We hit a hard error after deciding this was not an attribute.
692
0
      // FIXME: Don't parse and annotate expressions when disambiguating
693
0
      // against an attribute.
694
0
      return CAK_NotAttributeSpecifier;
695
0
    }
696
120
697
120
    switch (Tentative) {
698
120
    case LambdaIntroducerTentativeParse::MessageSend:
699
32
      // Case 3: The inner construct is definitely a message send, so the
700
32
      // outer construct is definitely not an attribute.
701
32
      return CAK_NotAttributeSpecifier;
702
120
703
120
    case LambdaIntroducerTentativeParse::Success:
704
32
    case LambdaIntroducerTentativeParse::Incomplete:
705
32
      // This is a lambda-introducer or attribute-specifier.
706
32
      if (Tok.is(tok::r_square))
707
26
        // Case 1: C++11 attribute.
708
26
        return CAK_AttributeSpecifier;
709
6
710
6
      if (OuterMightBeMessageSend)
711
5
        // Case 4: Lambda in message send.
712
5
        return CAK_NotAttributeSpecifier;
713
1
714
1
      // Case 2: Lambda in array size / index.
715
1
      return CAK_InvalidAttributeSpecifier;
716
1
717
56
    case LambdaIntroducerTentativeParse::Invalid:
718
56
      // No idea what this is; we couldn't parse it as a lambda-introducer.
719
56
      // Might still be an attribute-specifier or a message send.
720
56
      break;
721
56
    }
722
56
  }
723
56
724
56
  ConsumeBracket();
725
56
726
56
  // If we don't have a lambda-introducer, then we have an attribute or a
727
56
  // message-send.
728
56
  bool IsAttribute = true;
729
60
  while (Tok.isNot(tok::r_square)) {
730
60
    if (Tok.is(tok::comma)) {
731
1
      // Case 1: Stray commas can only occur in attributes.
732
1
      return CAK_AttributeSpecifier;
733
1
    }
734
59
735
59
    // Parse the attribute-token, if present.
736
59
    // C++11 [dcl.attr.grammar]:
737
59
    //   If a keyword or an alternative token that satisfies the syntactic
738
59
    //   requirements of an identifier is contained in an attribute-token,
739
59
    //   it is considered an identifier.
740
59
    SourceLocation Loc;
741
59
    if (!TryParseCXX11AttributeIdentifier(Loc)) {
742
11
      IsAttribute = false;
743
11
      break;
744
11
    }
745
48
    if (Tok.is(tok::coloncolon)) {
746
36
      ConsumeToken();
747
36
      if (!TryParseCXX11AttributeIdentifier(Loc)) {
748
0
        IsAttribute = false;
749
0
        break;
750
0
      }
751
48
    }
752
48
753
48
    // Parse the attribute-argument-clause, if present.
754
48
    if (Tok.is(tok::l_paren)) {
755
10
      ConsumeParen();
756
10
      if (!SkipUntil(tok::r_paren)) {
757
0
        IsAttribute = false;
758
0
        break;
759
0
      }
760
48
    }
761
48
762
48
    TryConsumeToken(tok::ellipsis);
763
48
764
48
    if (!TryConsumeToken(tok::comma))
765
44
      break;
766
48
  }
767
56
768
56
  // An attribute must end ']]'.
769
56
  
if (55
IsAttribute55
) {
770
44
    if (Tok.is(tok::r_square)) {
771
37
      ConsumeBracket();
772
37
      IsAttribute = Tok.is(tok::r_square);
773
37
    } else {
774
7
      IsAttribute = false;
775
7
    }
776
44
  }
777
55
778
55
  if (IsAttribute)
779
37
    // Case 1: C++11 statement attribute.
780
37
    return CAK_AttributeSpecifier;
781
18
782
18
  // Case 3: Message send.
783
18
  return CAK_NotAttributeSpecifier;
784
18
}
785
786
173k
Parser::TPResult Parser::TryParsePtrOperatorSeq() {
787
246k
  while (true) {
788
246k
    if (Tok.isOneOf(tok::coloncolon, tok::identifier))
789
23.6k
      if (TryAnnotateCXXScopeToken(true))
790
1
        return TPResult::Error;
791
246k
792
246k
    if (Tok.isOneOf(tok::star, tok::amp, tok::caret, tok::ampamp) ||
793
246k
        
(196k
Tok.is(tok::annot_cxxscope)196k
&&
NextToken().is(tok::star)25.4k
)) {
794
73.0k
      // ptr-operator
795
73.0k
      ConsumeAnyToken();
796
76.2k
      while (Tok.isOneOf(tok::kw_const, tok::kw_volatile, tok::kw_restrict,
797
76.2k
                         tok::kw__Nonnull, tok::kw__Nullable,
798
76.2k
                         tok::kw__Null_unspecified))
799
3.10k
        ConsumeToken();
800
173k
    } else {
801
173k
      return TPResult::True;
802
173k
    }
803
246k
  }
804
173k
}
805
806
///         operator-function-id:
807
///           'operator' operator
808
///
809
///         operator: one of
810
///           new  delete  new[]  delete[]  +  -  *  /  %  ^  [...]
811
///
812
///         conversion-function-id:
813
///           'operator' conversion-type-id
814
///
815
///         conversion-type-id:
816
///           type-specifier-seq conversion-declarator[opt]
817
///
818
///         conversion-declarator:
819
///           ptr-operator conversion-declarator[opt]
820
///
821
///         literal-operator-id:
822
///           'operator' string-literal identifier
823
///           'operator' user-defined-string-literal
824
16
Parser::TPResult Parser::TryParseOperatorId() {
825
16
  assert(Tok.is(tok::kw_operator));
826
16
  ConsumeToken();
827
16
828
16
  // Maybe this is an operator-function-id.
829
16
  switch (Tok.getKind()) {
830
16
  
case tok::kw_new: 0
case tok::kw_delete:
831
0
    ConsumeToken();
832
0
    if (Tok.is(tok::l_square) && NextToken().is(tok::r_square)) {
833
0
      ConsumeBracket();
834
0
      ConsumeBracket();
835
0
    }
836
0
    return TPResult::True;
837
0
838
0
#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemOnly) \
839
608
  case tok::Token:
840
0
#define OVERLOADED_OPERATOR_MULTI(Name, Spelling, Unary, Binary, MemOnly)
841
16
#include 
"clang/Basic/OperatorKinds.def"0
842
16
    ConsumeToken();
843
16
    return TPResult::True;
844
592
845
592
  case tok::l_square:
846
0
    if (NextToken().is(tok::r_square)) {
847
0
      ConsumeBracket();
848
0
      ConsumeBracket();
849
0
      return TPResult::True;
850
0
    }
851
0
    break;
852
0
853
0
  case tok::l_paren:
854
0
    if (NextToken().is(tok::r_paren)) {
855
0
      ConsumeParen();
856
0
      ConsumeParen();
857
0
      return TPResult::True;
858
0
    }
859
0
    break;
860
0
861
0
  default:
862
0
    break;
863
0
  }
864
0
865
0
  // Maybe this is a literal-operator-id.
866
0
  if (getLangOpts().CPlusPlus11 && isTokenStringLiteral()) {
867
0
    bool FoundUDSuffix = false;
868
0
    do {
869
0
      FoundUDSuffix |= Tok.hasUDSuffix();
870
0
      ConsumeStringToken();
871
0
    } while (isTokenStringLiteral());
872
0
873
0
    if (!FoundUDSuffix) {
874
0
      if (Tok.is(tok::identifier))
875
0
        ConsumeToken();
876
0
      else
877
0
        return TPResult::Error;
878
0
    }
879
0
    return TPResult::True;
880
0
  }
881
0
882
0
  // Maybe this is a conversion-function-id.
883
0
  bool AnyDeclSpecifiers = false;
884
0
  while (true) {
885
0
    TPResult TPR = isCXXDeclarationSpecifier();
886
0
    if (TPR == TPResult::Error)
887
0
      return TPR;
888
0
    if (TPR == TPResult::False) {
889
0
      if (!AnyDeclSpecifiers)
890
0
        return TPResult::Error;
891
0
      break;
892
0
    }
893
0
    if (TryConsumeDeclarationSpecifier() == TPResult::Error)
894
0
      return TPResult::Error;
895
0
    AnyDeclSpecifiers = true;
896
0
  }
897
0
  return TryParsePtrOperatorSeq();
898
0
}
899
900
///         declarator:
901
///           direct-declarator
902
///           ptr-operator declarator
903
///
904
///         direct-declarator:
905
///           declarator-id
906
///           direct-declarator '(' parameter-declaration-clause ')'
907
///                 cv-qualifier-seq[opt] exception-specification[opt]
908
///           direct-declarator '[' constant-expression[opt] ']'
909
///           '(' declarator ')'
910
/// [GNU]     '(' attributes declarator ')'
911
///
912
///         abstract-declarator:
913
///           ptr-operator abstract-declarator[opt]
914
///           direct-abstract-declarator
915
///
916
///         direct-abstract-declarator:
917
///           direct-abstract-declarator[opt]
918
///                 '(' parameter-declaration-clause ')' cv-qualifier-seq[opt]
919
///                 exception-specification[opt]
920
///           direct-abstract-declarator[opt] '[' constant-expression[opt] ']'
921
///           '(' abstract-declarator ')'
922
/// [C++0x]   ...
923
///
924
///         ptr-operator:
925
///           '*' cv-qualifier-seq[opt]
926
///           '&'
927
/// [C++0x]   '&&'                                                        [TODO]
928
///           '::'[opt] nested-name-specifier '*' cv-qualifier-seq[opt]
929
///
930
///         cv-qualifier-seq:
931
///           cv-qualifier cv-qualifier-seq[opt]
932
///
933
///         cv-qualifier:
934
///           'const'
935
///           'volatile'
936
///
937
///         declarator-id:
938
///           '...'[opt] id-expression
939
///
940
///         id-expression:
941
///           unqualified-id
942
///           qualified-id                                                [TODO]
943
///
944
///         unqualified-id:
945
///           identifier
946
///           operator-function-id
947
///           conversion-function-id
948
///           literal-operator-id
949
///           '~' class-name                                              [TODO]
950
///           '~' decltype-specifier                                      [TODO]
951
///           template-id                                                 [TODO]
952
///
953
Parser::TPResult Parser::TryParseDeclarator(bool mayBeAbstract,
954
                                            bool mayHaveIdentifier,
955
173k
                                            bool mayHaveDirectInit) {
956
173k
  // declarator:
957
173k
  //   direct-declarator
958
173k
  //   ptr-operator declarator
959
173k
  if (TryParsePtrOperatorSeq() == TPResult::Error)
960
1
    return TPResult::Error;
961
173k
962
173k
  // direct-declarator:
963
173k
  // direct-abstract-declarator:
964
173k
  if (Tok.is(tok::ellipsis))
965
12
    ConsumeToken();
966
173k
967
173k
  if ((Tok.isOneOf(tok::identifier, tok::kw_operator) ||
968
173k
       
(152k
Tok.is(tok::annot_cxxscope)152k
&&
(2.12k
NextToken().is(tok::identifier)2.12k
||
969
2.12k
                                        
NextToken().is(tok::kw_operator)296
))) &&
970
173k
      
mayHaveIdentifier23.1k
) {
971
22.0k
    // declarator-id
972
22.0k
    if (Tok.is(tok::annot_cxxscope))
973
1.81k
      ConsumeAnnotationToken();
974
20.2k
    else if (Tok.is(tok::identifier))
975
20.2k
      TentativelyDeclaredIdentifiers.push_back(Tok.getIdentifierInfo());
976
22.0k
    if (Tok.is(tok::kw_operator)) {
977
16
      if (TryParseOperatorId() == TPResult::Error)
978
0
        return TPResult::Error;
979
22.0k
    } else
980
22.0k
      ConsumeToken();
981
151k
  } else if (Tok.is(tok::l_paren)) {
982
97.4k
    ConsumeParen();
983
97.4k
    if (mayBeAbstract &&
984
97.4k
        
(78.0k
Tok.is(tok::r_paren)78.0k
|| // 'int()' is a function.
985
78.0k
         // 'int(...)' is a function.
986
78.0k
         
(76.8k
Tok.is(tok::ellipsis)76.8k
&&
NextToken().is(tok::r_paren)1
) ||
987
78.0k
         
isDeclarationSpecifier()76.8k
)) { // 'int(int)' is a function.
988
21.7k
      // '(' parameter-declaration-clause ')' cv-qualifier-seq[opt]
989
21.7k
      //        exception-specification[opt]
990
21.7k
      TPResult TPR = TryParseFunctionDeclarator();
991
21.7k
      if (TPR != TPResult::Ambiguous)
992
2
        return TPR;
993
75.7k
    } else {
994
75.7k
      // '(' declarator ')'
995
75.7k
      // '(' attributes declarator ')'
996
75.7k
      // '(' abstract-declarator ')'
997
75.7k
      if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec, tok::kw___cdecl,
998
75.7k
                      tok::kw___stdcall, tok::kw___fastcall, tok::kw___thiscall,
999
75.7k
                      tok::kw___regcall, tok::kw___vectorcall))
1000
1
        return TPResult::True; // attributes indicate declaration
1001
75.7k
      TPResult TPR = TryParseDeclarator(mayBeAbstract, mayHaveIdentifier);
1002
75.7k
      if (TPR != TPResult::Ambiguous)
1003
12.5k
        return TPR;
1004
63.2k
      if (Tok.isNot(tok::r_paren))
1005
11.4k
        return TPResult::False;
1006
51.7k
      ConsumeParen();
1007
51.7k
    }
1008
97.4k
  } else 
if (53.9k
!mayBeAbstract53.9k
) {
1009
12.5k
    return TPResult::False;
1010
12.5k
  }
1011
136k
1012
136k
  if (mayHaveDirectInit)
1013
42
    return TPResult::Ambiguous;
1014
136k
1015
186k
  
while (136k
1) {
1016
186k
    TPResult TPR(TPResult::Ambiguous);
1017
186k
1018
186k
    if (Tok.is(tok::l_paren)) {
1019
45.7k
      // Check whether we have a function declarator or a possible ctor-style
1020
45.7k
      // initializer that follows the declarator. Note that ctor-style
1021
45.7k
      // initializers are not possible in contexts where abstract declarators
1022
45.7k
      // are allowed.
1023
45.7k
      if (!mayBeAbstract && 
!isCXXFunctionDeclarator()2.85k
)
1024
1.80k
        break;
1025
43.9k
1026
43.9k
      // direct-declarator '(' parameter-declaration-clause ')'
1027
43.9k
      //        cv-qualifier-seq[opt] exception-specification[opt]
1028
43.9k
      ConsumeParen();
1029
43.9k
      TPR = TryParseFunctionDeclarator();
1030
140k
    } else if (Tok.is(tok::l_square)) {
1031
5.55k
      // direct-declarator '[' constant-expression[opt] ']'
1032
5.55k
      // direct-abstract-declarator[opt] '[' constant-expression[opt] ']'
1033
5.55k
      TPR = TryParseBracketDeclarator();
1034
135k
    } else {
1035
135k
      break;
1036
135k
    }
1037
49.5k
1038
49.5k
    if (TPR != TPResult::Ambiguous)
1039
1
      return TPR;
1040
49.5k
  }
1041
136k
1042
136k
  
return TPResult::Ambiguous136k
;
1043
136k
}
1044
1045
Parser::TPResult
1046
360
Parser::isExpressionOrTypeSpecifierSimple(tok::TokenKind Kind) {
1047
360
  switch (Kind) {
1048
360
  // Obviously starts an expression.
1049
360
  case tok::numeric_constant:
1050
3
  case tok::char_constant:
1051
3
  case tok::wide_char_constant:
1052
3
  case tok::utf8_char_constant:
1053
3
  case tok::utf16_char_constant:
1054
3
  case tok::utf32_char_constant:
1055
3
  case tok::string_literal:
1056
3
  case tok::wide_string_literal:
1057
3
  case tok::utf8_string_literal:
1058
3
  case tok::utf16_string_literal:
1059
3
  case tok::utf32_string_literal:
1060
3
  case tok::l_square:
1061
3
  case tok::l_paren:
1062
3
  case tok::amp:
1063
3
  case tok::ampamp:
1064
3
  case tok::star:
1065
3
  case tok::plus:
1066
3
  case tok::plusplus:
1067
3
  case tok::minus:
1068
3
  case tok::minusminus:
1069
3
  case tok::tilde:
1070
3
  case tok::exclaim:
1071
3
  case tok::kw_sizeof:
1072
3
  case tok::kw___func__:
1073
3
  case tok::kw_const_cast:
1074
3
  case tok::kw_delete:
1075
3
  case tok::kw_dynamic_cast:
1076
3
  case tok::kw_false:
1077
3
  case tok::kw_new:
1078
3
  case tok::kw_operator:
1079
3
  case tok::kw_reinterpret_cast:
1080
3
  case tok::kw_static_cast:
1081
3
  case tok::kw_this:
1082
3
  case tok::kw_throw:
1083
3
  case tok::kw_true:
1084
3
  case tok::kw_typeid:
1085
3
  case tok::kw_alignof:
1086
3
  case tok::kw_noexcept:
1087
3
  case tok::kw_nullptr:
1088
3
  case tok::kw__Alignof:
1089
3
  case tok::kw___null:
1090
3
  case tok::kw___alignof:
1091
3
  case tok::kw___builtin_choose_expr:
1092
3
  case tok::kw___builtin_offsetof:
1093
3
  case tok::kw___builtin_va_arg:
1094
3
  case tok::kw___imag:
1095
3
  case tok::kw___real:
1096
3
  case tok::kw___FUNCTION__:
1097
3
  case tok::kw___FUNCDNAME__:
1098
3
  case tok::kw___FUNCSIG__:
1099
3
  case tok::kw_L__FUNCTION__:
1100
3
  case tok::kw_L__FUNCSIG__:
1101
3
  case tok::kw___PRETTY_FUNCTION__:
1102
3
  case tok::kw___uuidof:
1103
3
#define TYPE_TRAIT(N,Spelling,K) \
1104
192
  case tok::kw_##Spelling:
1105
3
#include "clang/Basic/TokenKinds.def"
1106
3
    return TPResult::True;
1107
189
1108
189
  // Obviously starts a type-specifier-seq:
1109
239
  case tok::kw_char:
1110
239
  case tok::kw_const:
1111
239
  case tok::kw_double:
1112
239
  case tok::kw__Float16:
1113
239
  case tok::kw___float128:
1114
239
  case tok::kw_enum:
1115
239
  case tok::kw_half:
1116
239
  case tok::kw_float:
1117
239
  case tok::kw_int:
1118
239
  case tok::kw_long:
1119
239
  case tok::kw___int64:
1120
239
  case tok::kw___int128:
1121
239
  case tok::kw_restrict:
1122
239
  case tok::kw_short:
1123
239
  case tok::kw_signed:
1124
239
  case tok::kw_struct:
1125
239
  case tok::kw_union:
1126
239
  case tok::kw_unsigned:
1127
239
  case tok::kw_void:
1128
239
  case tok::kw_volatile:
1129
239
  case tok::kw__Bool:
1130
239
  case tok::kw__Complex:
1131
239
  case tok::kw_class:
1132
239
  case tok::kw_typename:
1133
239
  case tok::kw_wchar_t:
1134
239
  case tok::kw_char8_t:
1135
239
  case tok::kw_char16_t:
1136
239
  case tok::kw_char32_t:
1137
239
  case tok::kw__Decimal32:
1138
239
  case tok::kw__Decimal64:
1139
239
  case tok::kw__Decimal128:
1140
239
  case tok::kw___interface:
1141
239
  case tok::kw___thread:
1142
239
  case tok::kw_thread_local:
1143
239
  case tok::kw__Thread_local:
1144
239
  case tok::kw_typeof:
1145
239
  case tok::kw___underlying_type:
1146
239
  case tok::kw___cdecl:
1147
239
  case tok::kw___stdcall:
1148
239
  case tok::kw___fastcall:
1149
239
  case tok::kw___thiscall:
1150
239
  case tok::kw___regcall:
1151
239
  case tok::kw___vectorcall:
1152
239
  case tok::kw___unaligned:
1153
239
  case tok::kw___vector:
1154
239
  case tok::kw___pixel:
1155
239
  case tok::kw___bool:
1156
239
  case tok::kw__Atomic:
1157
2.86k
#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
1158
2.86k
#include 
"clang/Basic/OpenCLImageTypes.def"239
1159
2.86k
  case tok::kw___unknown_anytype:
1160
239
    return TPResult::False;
1161
2.86k
1162
2.86k
  default:
1163
118
    break;
1164
118
  }
1165
118
1166
118
  return TPResult::Ambiguous;
1167
118
}
1168
1169
9.10M
bool Parser::isTentativelyDeclared(IdentifierInfo *II) {
1170
9.10M
  return std::find(TentativelyDeclaredIdentifiers.begin(),
1171
9.10M
                   TentativelyDeclaredIdentifiers.end(), II)
1172
9.10M
      != TentativelyDeclaredIdentifiers.end();
1173
9.10M
}
1174
1175
namespace {
1176
class TentativeParseCCC final : public CorrectionCandidateCallback {
1177
public:
1178
5.70M
  TentativeParseCCC(const Token &Next) {
1179
5.70M
    WantRemainingKeywords = false;
1180
5.70M
    WantTypeSpecifiers = Next.isOneOf(tok::l_paren, tok::r_paren, tok::greater,
1181
5.70M
                                      tok::l_brace, tok::identifier);
1182
5.70M
  }
1183
1184
152
  bool ValidateCandidate(const TypoCorrection &Candidate) override {
1185
152
    // Reject any candidate that only resolves to instance members since they
1186
152
    // aren't viable as standalone identifiers instead of member references.
1187
152
    if (Candidate.isResolved() && !Candidate.isKeyword() &&
1188
152
        llvm::all_of(Candidate,
1189
132
                     [](NamedDecl *ND) { return ND->isCXXInstanceMember(); }))
1190
2
      return false;
1191
150
1192
150
    return CorrectionCandidateCallback::ValidateCandidate(Candidate);
1193
150
  }
1194
1195
180
  std::unique_ptr<CorrectionCandidateCallback> clone() override {
1196
180
    return llvm::make_unique<TentativeParseCCC>(*this);
1197
180
  }
1198
};
1199
}
1200
/// isCXXDeclarationSpecifier - Returns TPResult::True if it is a declaration
1201
/// specifier, TPResult::False if it is not, TPResult::Ambiguous if it could
1202
/// be either a decl-specifier or a function-style cast, and TPResult::Error
1203
/// if a parsing error was found and reported.
1204
///
1205
/// If InvalidAsDeclSpec is not null, some cases that would be ill-formed as
1206
/// declaration specifiers but possibly valid as some other kind of construct
1207
/// return TPResult::Ambiguous instead of TPResult::False. When this happens,
1208
/// the intent is to keep trying to disambiguate, on the basis that we might
1209
/// find a better reason to treat this construct as a declaration later on.
1210
/// When this happens and the name could possibly be valid in some other
1211
/// syntactic context, *InvalidAsDeclSpec is set to 'true'. The current cases
1212
/// that trigger this are:
1213
///
1214
///   * When parsing X::Y (with no 'typename') where X is dependent
1215
///   * When parsing X<Y> where X is undeclared
1216
///
1217
///         decl-specifier:
1218
///           storage-class-specifier
1219
///           type-specifier
1220
///           function-specifier
1221
///           'friend'
1222
///           'typedef'
1223
/// [C++11]   'constexpr'
1224
/// [C++20]   'consteval'
1225
/// [GNU]     attributes declaration-specifiers[opt]
1226
///
1227
///         storage-class-specifier:
1228
///           'register'
1229
///           'static'
1230
///           'extern'
1231
///           'mutable'
1232
///           'auto'
1233
/// [GNU]     '__thread'
1234
/// [C++11]   'thread_local'
1235
/// [C11]     '_Thread_local'
1236
///
1237
///         function-specifier:
1238
///           'inline'
1239
///           'virtual'
1240
///           'explicit'
1241
///
1242
///         typedef-name:
1243
///           identifier
1244
///
1245
///         type-specifier:
1246
///           simple-type-specifier
1247
///           class-specifier
1248
///           enum-specifier
1249
///           elaborated-type-specifier
1250
///           typename-specifier
1251
///           cv-qualifier
1252
///
1253
///         simple-type-specifier:
1254
///           '::'[opt] nested-name-specifier[opt] type-name
1255
///           '::'[opt] nested-name-specifier 'template'
1256
///                 simple-template-id                              [TODO]
1257
///           'char'
1258
///           'wchar_t'
1259
///           'bool'
1260
///           'short'
1261
///           'int'
1262
///           'long'
1263
///           'signed'
1264
///           'unsigned'
1265
///           'float'
1266
///           'double'
1267
///           'void'
1268
/// [GNU]     typeof-specifier
1269
/// [GNU]     '_Complex'
1270
/// [C++11]   'auto'
1271
/// [GNU]     '__auto_type'
1272
/// [C++11]   'decltype' ( expression )
1273
/// [C++1y]   'decltype' ( 'auto' )
1274
///
1275
///         type-name:
1276
///           class-name
1277
///           enum-name
1278
///           typedef-name
1279
///
1280
///         elaborated-type-specifier:
1281
///           class-key '::'[opt] nested-name-specifier[opt] identifier
1282
///           class-key '::'[opt] nested-name-specifier[opt] 'template'[opt]
1283
///               simple-template-id
1284
///           'enum' '::'[opt] nested-name-specifier[opt] identifier
1285
///
1286
///         enum-name:
1287
///           identifier
1288
///
1289
///         enum-specifier:
1290
///           'enum' identifier[opt] '{' enumerator-list[opt] '}'
1291
///           'enum' identifier[opt] '{' enumerator-list ',' '}'
1292
///
1293
///         class-specifier:
1294
///           class-head '{' member-specification[opt] '}'
1295
///
1296
///         class-head:
1297
///           class-key identifier[opt] base-clause[opt]
1298
///           class-key nested-name-specifier identifier base-clause[opt]
1299
///           class-key nested-name-specifier[opt] simple-template-id
1300
///               base-clause[opt]
1301
///
1302
///         class-key:
1303
///           'class'
1304
///           'struct'
1305
///           'union'
1306
///
1307
///         cv-qualifier:
1308
///           'const'
1309
///           'volatile'
1310
/// [GNU]     restrict
1311
///
1312
Parser::TPResult
1313
Parser::isCXXDeclarationSpecifier(Parser::TPResult BracedCastResult,
1314
21.5M
                                  bool *InvalidAsDeclSpec) {
1315
21.5M
  switch (Tok.getKind()) {
1316
21.5M
  case tok::identifier: {
1317
7.65M
    // Check for need to substitute AltiVec __vector keyword
1318
7.65M
    // for "vector" identifier.
1319
7.65M
    if (TryAltiVecVectorToken())
1320
14.1k
      return TPResult::True;
1321
7.64M
1322
7.64M
    const Token &Next = NextToken();
1323
7.64M
    // In 'foo bar', 'foo' is always a type name outside of Objective-C.
1324
7.64M
    if (!getLangOpts().ObjC && 
Next.is(tok::identifier)7.62M
)
1325
525k
      return TPResult::True;
1326
7.11M
1327
7.11M
    if (Next.isNot(tok::coloncolon) && 
Next.isNot(tok::less)6.26M
) {
1328
5.70M
      // Determine whether this is a valid expression. If not, we will hit
1329
5.70M
      // a parse error one way or another. In that case, tell the caller that
1330
5.70M
      // this is ambiguous. Typo-correct to type and expression keywords and
1331
5.70M
      // to types and identifiers, in order to try to recover from errors.
1332
5.70M
      TentativeParseCCC CCC(Next);
1333
5.70M
      switch (TryAnnotateName(false /* no nested name specifier */, &CCC)) {
1334
5.70M
      case ANK_Error:
1335
0
        return TPResult::Error;
1336
5.70M
      case ANK_TentativeDecl:
1337
24
        return TPResult::False;
1338
5.70M
      case ANK_TemplateName:
1339
3.01k
        // In C++17, this could be a type template for class template argument
1340
3.01k
        // deduction. Try to form a type annotation for it. If we're in a
1341
3.01k
        // template template argument, we'll undo this when checking the
1342
3.01k
        // validity of the argument.
1343
3.01k
        if (getLangOpts().CPlusPlus17) {
1344
148
          if (TryAnnotateTypeOrScopeToken())
1345
0
            return TPResult::Error;
1346
148
          if (Tok.isNot(tok::identifier))
1347
148
            break;
1348
2.86k
        }
1349
2.86k
1350
2.86k
        // A bare type template-name which can't be a template template
1351
2.86k
        // argument is an error, and was probably intended to be a type.
1352
2.86k
        return GreaterThanIsOperator ? 
TPResult::True6
:
TPResult::False2.86k
;
1353
2.86k
      case ANK_Unresolved:
1354
359
        return InvalidAsDeclSpec ? 
TPResult::Ambiguous182
:
TPResult::False177
;
1355
5.70M
      case ANK_Success:
1356
5.70M
        break;
1357
5.70M
      }
1358
5.70M
      assert(Tok.isNot(tok::identifier) &&
1359
5.70M
             "TryAnnotateName succeeded without producing an annotation");
1360
5.70M
    } else {
1361
1.41M
      // This might possibly be a type with a dependent scope specifier and
1362
1.41M
      // a missing 'typename' keyword. Don't use TryAnnotateName in this case,
1363
1.41M
      // since it will annotate as a primary expression, and we want to use the
1364
1.41M
      // "missing 'typename'" logic.
1365
1.41M
      if (TryAnnotateTypeOrScopeToken())
1366
52
        return TPResult::Error;
1367
1.41M
      // If annotation failed, assume it's a non-type.
1368
1.41M
      // FIXME: If this happens due to an undeclared identifier, treat it as
1369
1.41M
      // ambiguous.
1370
1.41M
      if (Tok.is(tok::identifier))
1371
193k
        return TPResult::False;
1372
6.91M
    }
1373
6.91M
1374
6.91M
    // We annotated this token as something. Recurse to handle whatever we got.
1375
6.91M
    return isCXXDeclarationSpecifier(BracedCastResult, InvalidAsDeclSpec);
1376
6.91M
  }
1377
6.91M
1378
6.91M
  case tok::kw_typename:  // typename T::type
1379
174k
    // Annotate typenames and C++ scope specifiers.  If we get one, just
1380
174k
    // recurse to handle whatever we get.
1381
174k
    if (TryAnnotateTypeOrScopeToken())
1382
44
      return TPResult::Error;
1383
174k
    return isCXXDeclarationSpecifier(BracedCastResult, InvalidAsDeclSpec);
1384
174k
1385
174k
  case tok::coloncolon: {    // ::foo::bar
1386
12.4k
    const Token &Next = NextToken();
1387
12.4k
    if (Next.isOneOf(tok::kw_new,       // ::new
1388
12.4k
                     tok::kw_delete))   // ::delete
1389
10.8k
      return TPResult::False;
1390
1.58k
    LLVM_FALLTHROUGH;
1391
1.58k
  }
1392
12.2k
  case tok::kw___super:
1393
12.2k
  case tok::kw_decltype:
1394
12.2k
    // Annotate typenames and C++ scope specifiers.  If we get one, just
1395
12.2k
    // recurse to handle whatever we get.
1396
12.2k
    if (TryAnnotateTypeOrScopeToken())
1397
2
      return TPResult::Error;
1398
12.2k
    return isCXXDeclarationSpecifier(BracedCastResult, InvalidAsDeclSpec);
1399
12.2k
1400
12.2k
    // decl-specifier:
1401
12.2k
    //   storage-class-specifier
1402
12.2k
    //   type-specifier
1403
12.2k
    //   function-specifier
1404
12.2k
    //   'friend'
1405
12.2k
    //   'typedef'
1406
12.2k
    //   'constexpr'
1407
712k
  case tok::kw_friend:
1408
712k
  case tok::kw_typedef:
1409
712k
  case tok::kw_constexpr:
1410
712k
  case tok::kw_consteval:
1411
712k
    // storage-class-specifier
1412
712k
  case tok::kw_register:
1413
712k
  case tok::kw_static:
1414
712k
  case tok::kw_extern:
1415
712k
  case tok::kw_mutable:
1416
712k
  case tok::kw_auto:
1417
712k
  case tok::kw___thread:
1418
712k
  case tok::kw_thread_local:
1419
712k
  case tok::kw__Thread_local:
1420
712k
    // function-specifier
1421
712k
  case tok::kw_inline:
1422
712k
  case tok::kw_virtual:
1423
712k
  case tok::kw_explicit:
1424
712k
1425
712k
    // Modules
1426
712k
  case tok::kw___module_private__:
1427
712k
1428
712k
    // Debugger support
1429
712k
  case tok::kw___unknown_anytype:
1430
712k
1431
712k
    // type-specifier:
1432
712k
    //   simple-type-specifier
1433
712k
    //   class-specifier
1434
712k
    //   enum-specifier
1435
712k
    //   elaborated-type-specifier
1436
712k
    //   typename-specifier
1437
712k
    //   cv-qualifier
1438
712k
1439
712k
    // class-specifier
1440
712k
    // elaborated-type-specifier
1441
712k
  case tok::kw_class:
1442
712k
  case tok::kw_struct:
1443
712k
  case tok::kw_union:
1444
712k
  case tok::kw___interface:
1445
712k
    // enum-specifier
1446
712k
  case tok::kw_enum:
1447
712k
    // cv-qualifier
1448
712k
  case tok::kw_const:
1449
712k
  case tok::kw_volatile:
1450
712k
    return TPResult::True;
1451
712k
1452
712k
    // OpenCL address space qualifiers
1453
712k
  case tok::kw_private:
1454
4
    if (!getLangOpts().OpenCL)
1455
1
      return TPResult::False;
1456
3
    LLVM_FALLTHROUGH;
1457
3.00k
  case tok::kw___private:
1458
3.00k
  case tok::kw___local:
1459
3.00k
  case tok::kw___global:
1460
3.00k
  case tok::kw___constant:
1461
3.00k
  case tok::kw___generic:
1462
3.00k
    // OpenCL access qualifiers
1463
3.00k
  case tok::kw___read_only:
1464
3.00k
  case tok::kw___write_only:
1465
3.00k
  case tok::kw___read_write:
1466
3.00k
    // OpenCL pipe
1467
3.00k
  case tok::kw_pipe:
1468
3.00k
1469
3.00k
    // GNU
1470
3.00k
  case tok::kw_restrict:
1471
3.00k
  case tok::kw__Complex:
1472
3.00k
  case tok::kw___attribute:
1473
3.00k
  case tok::kw___auto_type:
1474
3.00k
    return TPResult::True;
1475
3.00k
1476
3.00k
    // Microsoft
1477
3.00k
  case tok::kw___declspec:
1478
109
  case tok::kw___cdecl:
1479
109
  case tok::kw___stdcall:
1480
109
  case tok::kw___fastcall:
1481
109
  case tok::kw___thiscall:
1482
109
  case tok::kw___regcall:
1483
109
  case tok::kw___vectorcall:
1484
109
  case tok::kw___w64:
1485
109
  case tok::kw___sptr:
1486
109
  case tok::kw___uptr:
1487
109
  case tok::kw___ptr64:
1488
109
  case tok::kw___ptr32:
1489
109
  case tok::kw___forceinline:
1490
109
  case tok::kw___unaligned:
1491
109
  case tok::kw__Nonnull:
1492
109
  case tok::kw__Nullable:
1493
109
  case tok::kw__Null_unspecified:
1494
109
  case tok::kw___kindof:
1495
109
    return TPResult::True;
1496
109
1497
109
    // Borland
1498
109
  case tok::kw___pascal:
1499
4
    return TPResult::True;
1500
109
1501
109
    // AltiVec
1502
109
  case tok::kw___vector:
1503
30
    return TPResult::True;
1504
109
1505
21.5k
  case tok::annot_template_id: {
1506
21.5k
    TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
1507
21.5k
    // If lookup for the template-name found nothing, don't assume we have a
1508
21.5k
    // definitive disambiguation result yet.
1509
21.5k
    if (TemplateId->Kind == TNK_Undeclared_template && 
InvalidAsDeclSpec38
) {
1510
35
      // 'template-id(' can be a valid expression but not a valid decl spec if
1511
35
      // the template-name is not declared, but we don't consider this to be a
1512
35
      // definitive disambiguation. In any other context, it's an error either
1513
35
      // way.
1514
35
      *InvalidAsDeclSpec = NextToken().is(tok::l_paren);
1515
35
      return TPResult::Ambiguous;
1516
35
    }
1517
21.4k
    if (TemplateId->Kind != TNK_Type_template)
1518
21.4k
      return TPResult::False;
1519
3
    CXXScopeSpec SS;
1520
3
    AnnotateTemplateIdTokenAsType();
1521
3
    assert(Tok.is(tok::annot_typename));
1522
3
    goto case_typename;
1523
3
  }
1524
3
1525
497k
  case tok::annot_cxxscope: // foo::bar or ::foo::bar, but already parsed
1526
497k
    // We've already annotated a scope; try to annotate a type.
1527
497k
    if (TryAnnotateTypeOrScopeToken())
1528
0
      return TPResult::Error;
1529
497k
    if (!Tok.is(tok::annot_typename)) {
1530
497k
      // If the next token is an identifier or a type qualifier, then this
1531
497k
      // can't possibly be a valid expression either.
1532
497k
      if (Tok.is(tok::annot_cxxscope) && NextToken().is(tok::identifier)) {
1533
477k
        CXXScopeSpec SS;
1534
477k
        Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(),
1535
477k
                                                     Tok.getAnnotationRange(),
1536
477k
                                                     SS);
1537
477k
        if (SS.getScopeRep() && 
SS.getScopeRep()->isDependent()477k
) {
1538
296k
          RevertingTentativeParsingAction PA(*this);
1539
296k
          ConsumeAnnotationToken();
1540
296k
          ConsumeToken();
1541
296k
          bool isIdentifier = Tok.is(tok::identifier);
1542
296k
          TPResult TPR = TPResult::False;
1543
296k
          if (!isIdentifier)
1544
296k
            TPR = isCXXDeclarationSpecifier(BracedCastResult,
1545
296k
                                            InvalidAsDeclSpec);
1546
296k
1547
296k
          if (isIdentifier ||
1548
296k
              
TPR == TPResult::True296k
||
TPR == TPResult::Error296k
)
1549
20
            return TPResult::Error;
1550
296k
1551
296k
          if (InvalidAsDeclSpec) {
1552
44.8k
            // We can't tell whether this is a missing 'typename' or a valid
1553
44.8k
            // expression.
1554
44.8k
            *InvalidAsDeclSpec = true;
1555
44.8k
            return TPResult::Ambiguous;
1556
252k
          } else {
1557
252k
            // In MS mode, if InvalidAsDeclSpec is not provided, and the tokens
1558
252k
            // are or the form *) or &) *> or &> &&>, this can't be an expression.
1559
252k
            // The typename must be missing.
1560
252k
            if (getLangOpts().MSVCCompat) {
1561
40
              if (((Tok.is(tok::amp) || 
Tok.is(tok::star)36
) &&
1562
40
                   
(6
NextToken().is(tok::r_paren)6
||
1563
6
                    
NextToken().is(tok::greater)5
)) ||
1564
40
                  
(38
Tok.is(tok::ampamp)38
&&
NextToken().is(tok::greater)0
))
1565
2
                return TPResult::True;
1566
180k
            }
1567
252k
          }
1568
180k
        } else {
1569
180k
          // Try to resolve the name. If it doesn't exist, assume it was
1570
180k
          // intended to name a type and keep disambiguating.
1571
180k
          switch (TryAnnotateName(false /* SS is not dependent */)) {
1572
180k
          case ANK_Error:
1573
4
            return TPResult::Error;
1574
180k
          case ANK_TentativeDecl:
1575
0
            return TPResult::False;
1576
180k
          case ANK_TemplateName:
1577
47
            // In C++17, this could be a type template for class template
1578
47
            // argument deduction.
1579
47
            if (getLangOpts().CPlusPlus17) {
1580
0
              if (TryAnnotateTypeOrScopeToken())
1581
0
                return TPResult::Error;
1582
0
              if (Tok.isNot(tok::identifier))
1583
0
                break;
1584
47
            }
1585
47
1586
47
            // A bare type template-name which can't be a template template
1587
47
            // argument is an error, and was probably intended to be a type.
1588
47
            // In C++17, this could be class template argument deduction.
1589
47
            return (getLangOpts().CPlusPlus17 || GreaterThanIsOperator)
1590
47
                       ? 
TPResult::True9
1591
47
                       : 
TPResult::False38
;
1592
160
          case ANK_Unresolved:
1593
160
            return InvalidAsDeclSpec ? 
TPResult::Ambiguous112
:
TPResult::False48
;
1594
179k
          case ANK_Success:
1595
179k
            break;
1596
179k
          }
1597
179k
1598
179k
          // Annotated it, check again.
1599
179k
          assert(Tok.isNot(tok::annot_cxxscope) ||
1600
179k
                 NextToken().isNot(tok::identifier));
1601
179k
          return isCXXDeclarationSpecifier(BracedCastResult, InvalidAsDeclSpec);
1602
179k
        }
1603
477k
      }
1604
272k
      return TPResult::False;
1605
272k
    }
1606
14
    // If that succeeded, fallthrough into the generic simple-type-id case.
1607
14
    LLVM_FALLTHROUGH;
1608
14
1609
14
    // The ambiguity resides in a simple-type-specifier/typename-specifier
1610
14
    // followed by a '('. The '(' could either be the start of:
1611
14
    //
1612
14
    //   direct-declarator:
1613
14
    //     '(' declarator ')'
1614
14
    //
1615
14
    //   direct-abstract-declarator:
1616
14
    //     '(' parameter-declaration-clause ')' cv-qualifier-seq[opt]
1617
14
    //              exception-specification[opt]
1618
14
    //     '(' abstract-declarator ')'
1619
14
    //
1620
14
    // or part of a function-style cast expression:
1621
14
    //
1622
14
    //     simple-type-specifier '(' expression-list[opt] ')'
1623
14
    //
1624
14
1625
14
    // simple-type-specifier:
1626
14
1627
5.44M
  case tok::annot_typename:
1628
5.44M
  case_typename:
1629
5.44M
    // In Objective-C, we might have a protocol-qualified type.
1630
5.44M
    if (getLangOpts().ObjC && 
NextToken().is(tok::less)19.2k
) {
1631
0
      // Tentatively parse the protocol qualifiers.
1632
0
      RevertingTentativeParsingAction PA(*this);
1633
0
      ConsumeAnyToken(); // The type token
1634
0
1635
0
      TPResult TPR = TryParseProtocolQualifiers();
1636
0
      bool isFollowedByParen = Tok.is(tok::l_paren);
1637
0
      bool isFollowedByBrace = Tok.is(tok::l_brace);
1638
0
1639
0
      if (TPR == TPResult::Error)
1640
0
        return TPResult::Error;
1641
0
1642
0
      if (isFollowedByParen)
1643
0
        return TPResult::Ambiguous;
1644
0
1645
0
      if (getLangOpts().CPlusPlus11 && isFollowedByBrace)
1646
0
        return BracedCastResult;
1647
0
1648
0
      return TPResult::True;
1649
0
    }
1650
5.44M
    LLVM_FALLTHROUGH;
1651
5.44M
1652
6.89M
  case tok::kw_char:
1653
6.89M
  case tok::kw_wchar_t:
1654
6.89M
  case tok::kw_char8_t:
1655
6.89M
  case tok::kw_char16_t:
1656
6.89M
  case tok::kw_char32_t:
1657
6.89M
  case tok::kw_bool:
1658
6.89M
  case tok::kw_short:
1659
6.89M
  case tok::kw_int:
1660
6.89M
  case tok::kw_long:
1661
6.89M
  case tok::kw___int64:
1662
6.89M
  case tok::kw___int128:
1663
6.89M
  case tok::kw_signed:
1664
6.89M
  case tok::kw_unsigned:
1665
6.89M
  case tok::kw_half:
1666
6.89M
  case tok::kw_float:
1667
6.89M
  case tok::kw_double:
1668
6.89M
  case tok::kw__Float16:
1669
6.89M
  case tok::kw___float128:
1670
6.89M
  case tok::kw_void:
1671
6.89M
  case tok::annot_decltype:
1672
82.7M
#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
1673
82.7M
#include 
"clang/Basic/OpenCLImageTypes.def"6.89M
1674
82.7M
    if (
NextToken().is(tok::l_paren)6.89M
)
1675
98.5k
      return TPResult::Ambiguous;
1676
6.79M
1677
6.79M
    // This is a function-style cast in all cases we disambiguate other than
1678
6.79M
    // one:
1679
6.79M
    //   struct S {
1680
6.79M
    //     enum E : int { a = 4 }; // enum
1681
6.79M
    //     enum E : int { 4 };     // bit-field
1682
6.79M
    //   };
1683
6.79M
    if (getLangOpts().CPlusPlus11 && 
NextToken().is(tok::l_brace)6.52M
)
1684
743
      return BracedCastResult;
1685
6.79M
1686
6.79M
    if (isStartOfObjCClassMessageMissingOpenBracket())
1687
3
      return TPResult::False;
1688
6.79M
1689
6.79M
    return TPResult::True;
1690
6.79M
1691
6.79M
  // GNU typeof support.
1692
6.79M
  case tok::kw_typeof: {
1693
739
    if (NextToken().isNot(tok::l_paren))
1694
3
      return TPResult::True;
1695
736
1696
736
    RevertingTentativeParsingAction PA(*this);
1697
736
1698
736
    TPResult TPR = TryParseTypeofSpecifier();
1699
736
    bool isFollowedByParen = Tok.is(tok::l_paren);
1700
736
    bool isFollowedByBrace = Tok.is(tok::l_brace);
1701
736
1702
736
    if (TPR == TPResult::Error)
1703
0
      return TPResult::Error;
1704
736
1705
736
    if (isFollowedByParen)
1706
14
      return TPResult::Ambiguous;
1707
722
1708
722
    if (getLangOpts().CPlusPlus11 && 
isFollowedByBrace686
)
1709
0
      return BracedCastResult;
1710
722
1711
722
    return TPResult::True;
1712
722
  }
1713
722
1714
722
  // C++0x type traits support
1715
722
  case tok::kw___underlying_type:
1716
7
    return TPResult::True;
1717
722
1718
722
  // C11 _Atomic
1719
722
  case tok::kw__Atomic:
1720
22
    return TPResult::True;
1721
722
1722
5.60M
  default:
1723
5.60M
    return TPResult::False;
1724
21.5M
  }
1725
21.5M
}
1726
1727
19.4k
bool Parser::isCXXDeclarationSpecifierAType() {
1728
19.4k
  switch (Tok.getKind()) {
1729
19.4k
    // typename-specifier
1730
19.4k
  case tok::annot_decltype:
1731
6.79k
  case tok::annot_template_id:
1732
6.79k
  case tok::annot_typename:
1733
6.79k
  case tok::kw_typeof:
1734
6.79k
  case tok::kw___underlying_type:
1735
6.79k
    return true;
1736
6.79k
1737
6.79k
    // elaborated-type-specifier
1738
6.79k
  case tok::kw_class:
1739
5
  case tok::kw_struct:
1740
5
  case tok::kw_union:
1741
5
  case tok::kw___interface:
1742
5
  case tok::kw_enum:
1743
5
    return true;
1744
5
1745
5
    // simple-type-specifier
1746
12.0k
  case tok::kw_char:
1747
12.0k
  case tok::kw_wchar_t:
1748
12.0k
  case tok::kw_char8_t:
1749
12.0k
  case tok::kw_char16_t:
1750
12.0k
  case tok::kw_char32_t:
1751
12.0k
  case tok::kw_bool:
1752
12.0k
  case tok::kw_short:
1753
12.0k
  case tok::kw_int:
1754
12.0k
  case tok::kw_long:
1755
12.0k
  case tok::kw___int64:
1756
12.0k
  case tok::kw___int128:
1757
12.0k
  case tok::kw_signed:
1758
12.0k
  case tok::kw_unsigned:
1759
12.0k
  case tok::kw_half:
1760
12.0k
  case tok::kw_float:
1761
12.0k
  case tok::kw_double:
1762
12.0k
  case tok::kw__Float16:
1763
12.0k
  case tok::kw___float128:
1764
12.0k
  case tok::kw_void:
1765
12.0k
  case tok::kw___unknown_anytype:
1766
12.0k
  case tok::kw___auto_type:
1767
144k
#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
1768
12.0k
#include "clang/Basic/OpenCLImageTypes.def"
1769
12.0k
    return true;
1770
132k
1771
132k
  case tok::kw_auto:
1772
0
    return getLangOpts().CPlusPlus11;
1773
132k
1774
132k
  case tok::kw__Atomic:
1775
0
    // "_Atomic foo"
1776
0
    return NextToken().is(tok::l_paren);
1777
132k
1778
132k
  default:
1779
631
    return false;
1780
19.4k
  }
1781
19.4k
}
1782
1783
/// [GNU] typeof-specifier:
1784
///         'typeof' '(' expressions ')'
1785
///         'typeof' '(' type-name ')'
1786
///
1787
736
Parser::TPResult Parser::TryParseTypeofSpecifier() {
1788
736
  assert(Tok.is(tok::kw_typeof) && "Expected 'typeof'!");
1789
736
  ConsumeToken();
1790
736
1791
736
  assert(Tok.is(tok::l_paren) && "Expected '('");
1792
736
  // Parse through the parens after 'typeof'.
1793
736
  ConsumeParen();
1794
736
  if (!SkipUntil(tok::r_paren, StopAtSemi))
1795
0
    return TPResult::Error;
1796
736
1797
736
  return TPResult::Ambiguous;
1798
736
}
1799
1800
/// [ObjC] protocol-qualifiers:
1801
////         '<' identifier-list '>'
1802
0
Parser::TPResult Parser::TryParseProtocolQualifiers() {
1803
0
  assert(Tok.is(tok::less) && "Expected '<' for qualifier list");
1804
0
  ConsumeToken();
1805
0
  do {
1806
0
    if (Tok.isNot(tok::identifier))
1807
0
      return TPResult::Error;
1808
0
    ConsumeToken();
1809
0
1810
0
    if (Tok.is(tok::comma)) {
1811
0
      ConsumeToken();
1812
0
      continue;
1813
0
    }
1814
0
1815
0
    if (Tok.is(tok::greater)) {
1816
0
      ConsumeToken();
1817
0
      return TPResult::Ambiguous;
1818
0
    }
1819
0
  } while (false);
1820
0
1821
0
  return TPResult::Error;
1822
0
}
1823
1824
/// isCXXFunctionDeclarator - Disambiguates between a function declarator or
1825
/// a constructor-style initializer, when parsing declaration statements.
1826
/// Returns true for function declarator and false for constructor-style
1827
/// initializer.
1828
/// If during the disambiguation process a parsing error is encountered,
1829
/// the function returns true to let the declaration parsing code handle it.
1830
///
1831
/// '(' parameter-declaration-clause ')' cv-qualifier-seq[opt]
1832
///         exception-specification[opt]
1833
///
1834
2.12M
bool Parser::isCXXFunctionDeclarator(bool *IsAmbiguous) {
1835
2.12M
1836
2.12M
  // C++ 8.2p1:
1837
2.12M
  // The ambiguity arising from the similarity between a function-style cast and
1838
2.12M
  // a declaration mentioned in 6.8 can also occur in the context of a
1839
2.12M
  // declaration. In that context, the choice is between a function declaration
1840
2.12M
  // with a redundant set of parentheses around a parameter name and an object
1841
2.12M
  // declaration with a function-style cast as the initializer. Just as for the
1842
2.12M
  // ambiguities mentioned in 6.8, the resolution is to consider any construct
1843
2.12M
  // that could possibly be a declaration a declaration.
1844
2.12M
1845
2.12M
  RevertingTentativeParsingAction PA(*this);
1846
2.12M
1847
2.12M
  ConsumeParen();
1848
2.12M
  bool InvalidAsDeclaration = false;
1849
2.12M
  TPResult TPR = TryParseParameterDeclarationClause(&InvalidAsDeclaration);
1850
2.12M
  if (TPR == TPResult::Ambiguous) {
1851
231k
    if (Tok.isNot(tok::r_paren))
1852
5
      TPR = TPResult::False;
1853
231k
    else {
1854
231k
      const Token &Next = NextToken();
1855
231k
      if (Next.isOneOf(tok::amp, tok::ampamp, tok::kw_const, tok::kw_volatile,
1856
231k
                       tok::kw_throw, tok::kw_noexcept, tok::l_square,
1857
231k
                       tok::l_brace, tok::kw_try, tok::equal, tok::arrow) ||
1858
231k
          
isCXX11VirtSpecifier(Next)128k
)
1859
102k
        // The next token cannot appear after a constructor-style initializer,
1860
102k
        // and can appear next in a function definition. This must be a function
1861
102k
        // declarator.
1862
102k
        TPR = TPResult::True;
1863
128k
      else if (InvalidAsDeclaration)
1864
97
        // Use the absence of 'typename' as a tie-breaker.
1865
97
        TPR = TPResult::False;
1866
231k
    }
1867
231k
  }
1868
2.12M
1869
2.12M
  if (IsAmbiguous && 
TPR == TPResult::Ambiguous2.12M
)
1870
128k
    *IsAmbiguous = true;
1871
2.12M
1872
2.12M
  // In case of an error, let the declaration parsing code handle it.
1873
2.12M
  return TPR != TPResult::False;
1874
2.12M
}
1875
1876
/// parameter-declaration-clause:
1877
///   parameter-declaration-list[opt] '...'[opt]
1878
///   parameter-declaration-list ',' '...'
1879
///
1880
/// parameter-declaration-list:
1881
///   parameter-declaration
1882
///   parameter-declaration-list ',' parameter-declaration
1883
///
1884
/// parameter-declaration:
1885
///   attribute-specifier-seq[opt] decl-specifier-seq declarator attributes[opt]
1886
///   attribute-specifier-seq[opt] decl-specifier-seq declarator attributes[opt]
1887
///     '=' assignment-expression
1888
///   attribute-specifier-seq[opt] decl-specifier-seq abstract-declarator[opt]
1889
///     attributes[opt]
1890
///   attribute-specifier-seq[opt] decl-specifier-seq abstract-declarator[opt]
1891
///     attributes[opt] '=' assignment-expression
1892
///
1893
Parser::TPResult
1894
Parser::TryParseParameterDeclarationClause(bool *InvalidAsDeclaration,
1895
2.19M
                                           bool VersusTemplateArgument) {
1896
2.19M
1897
2.19M
  if (Tok.is(tok::r_paren))
1898
223k
    return TPResult::Ambiguous;
1899
1.96M
1900
1.96M
  //   parameter-declaration-list[opt] '...'[opt]
1901
1.96M
  //   parameter-declaration-list ',' '...'
1902
1.96M
  //
1903
1.96M
  // parameter-declaration-list:
1904
1.96M
  //   parameter-declaration
1905
1.96M
  //   parameter-declaration-list ',' parameter-declaration
1906
1.96M
  //
1907
1.97M
  
while (1.96M
1) {
1908
1.97M
    // '...'[opt]
1909
1.97M
    if (Tok.is(tok::ellipsis)) {
1910
3.40k
      ConsumeToken();
1911
3.40k
      if (Tok.is(tok::r_paren))
1912
3.40k
        return TPResult::True; // '...)' is a sign of a function declarator.
1913
0
      else
1914
0
        return TPResult::False;
1915
1.97M
    }
1916
1.97M
1917
1.97M
    // An attribute-specifier-seq here is a sign of a function declarator.
1918
1.97M
    if (isCXX11AttributeSpecifier(/*Disambiguate*/false,
1919
1.97M
                                  /*OuterMightBeMessageSend*/true))
1920
8
      return TPResult::True;
1921
1.97M
1922
1.97M
    ParsedAttributes attrs(AttrFactory);
1923
1.97M
    MaybeParseMicrosoftAttributes(attrs);
1924
1.97M
1925
1.97M
    // decl-specifier-seq
1926
1.97M
    // A parameter-declaration's initializer must be preceded by an '=', so
1927
1.97M
    // decl-specifier-seq '{' is not a parameter in C++11.
1928
1.97M
    TPResult TPR = isCXXDeclarationSpecifier(TPResult::False,
1929
1.97M
                                             InvalidAsDeclaration);
1930
1.97M
    // A declaration-specifier (not followed by '(' or '{') means this can't be
1931
1.97M
    // an expression, but it could still be a template argument.
1932
1.97M
    if (TPR != TPResult::Ambiguous &&
1933
1.97M
        
!(1.95M
VersusTemplateArgument1.95M
&&
TPR == TPResult::True41
))
1934
1.95M
      return TPR;
1935
19.4k
1936
19.4k
    bool SeenType = false;
1937
19.4k
    do {
1938
19.4k
      SeenType |= isCXXDeclarationSpecifierAType();
1939
19.4k
      if (TryConsumeDeclarationSpecifier() == TPResult::Error)
1940
2
        return TPResult::Error;
1941
19.4k
1942
19.4k
      // If we see a parameter name, this can't be a template argument.
1943
19.4k
      if (SeenType && 
Tok.is(tok::identifier)18.8k
)
1944
11
        return TPResult::True;
1945
19.4k
1946
19.4k
      TPR = isCXXDeclarationSpecifier(TPResult::False,
1947
19.4k
                                      InvalidAsDeclaration);
1948
19.4k
      if (TPR == TPResult::Error)
1949
0
        return TPR;
1950
19.4k
1951
19.4k
      // Two declaration-specifiers means this can't be an expression.
1952
19.4k
      if (TPR == TPResult::True && 
!VersusTemplateArgument1
)
1953
1
        return TPR;
1954
19.4k
    } while (TPR != TPResult::False);
1955
19.4k
1956
19.4k
    // declarator
1957
19.4k
    // abstract-declarator[opt]
1958
19.4k
    TPR = TryParseDeclarator(true/*mayBeAbstract*/);
1959
19.4k
    if (TPR != TPResult::Ambiguous)
1960
829
      return TPR;
1961
18.6k
1962
18.6k
    // [GNU] attributes[opt]
1963
18.6k
    if (Tok.is(tok::kw___attribute))
1964
1
      return TPResult::True;
1965
18.6k
1966
18.6k
    // If we're disambiguating a template argument in a default argument in
1967
18.6k
    // a class definition versus a parameter declaration, an '=' here
1968
18.6k
    // disambiguates the parse one way or the other.
1969
18.6k
    // If this is a parameter, it must have a default argument because
1970
18.6k
    //   (a) the previous parameter did, and
1971
18.6k
    //   (b) this must be the first declaration of the function, so we can't
1972
18.6k
    //       inherit any default arguments from elsewhere.
1973
18.6k
    // If we see an ')', then we've reached the end of a
1974
18.6k
    // parameter-declaration-clause, and the last param is missing its default
1975
18.6k
    // argument.
1976
18.6k
    if (VersusTemplateArgument)
1977
25
      return Tok.isOneOf(tok::equal, tok::r_paren) ? 
TPResult::True4
1978
25
                                                   : 
TPResult::False21
;
1979
18.5k
1980
18.5k
    if (Tok.is(tok::equal)) {
1981
9
      // '=' assignment-expression
1982
9
      // Parse through assignment-expression.
1983
9
      // FIXME: assignment-expression may contain an unparenthesized comma.
1984
9
      if (!SkipUntil(tok::comma, tok::r_paren, StopAtSemi | StopBeforeMatch))
1985
0
        return TPResult::Error;
1986
18.5k
    }
1987
18.5k
1988
18.5k
    if (Tok.is(tok::ellipsis)) {
1989
2
      ConsumeToken();
1990
2
      if (Tok.is(tok::r_paren))
1991
1
        return TPResult::True; // '...)' is a sign of a function declarator.
1992
1
      else
1993
1
        return TPResult::False;
1994
18.5k
    }
1995
18.5k
1996
18.5k
    if (!TryConsumeToken(tok::comma))
1997
14.2k
      break;
1998
18.5k
  }
1999
1.96M
2000
1.96M
  
return TPResult::Ambiguous14.2k
;
2001
1.96M
}
2002
2003
/// TryParseFunctionDeclarator - We parsed a '(' and we want to try to continue
2004
/// parsing as a function declarator.
2005
/// If TryParseFunctionDeclarator fully parsed the function declarator, it will
2006
/// return TPResult::Ambiguous, otherwise it will return either False() or
2007
/// Error().
2008
///
2009
/// '(' parameter-declaration-clause ')' cv-qualifier-seq[opt]
2010
///         exception-specification[opt]
2011
///
2012
/// exception-specification:
2013
///   'throw' '(' type-id-list[opt] ')'
2014
///
2015
65.7k
Parser::TPResult Parser::TryParseFunctionDeclarator() {
2016
65.7k
2017
65.7k
  // The '(' is already parsed.
2018
65.7k
2019
65.7k
  TPResult TPR = TryParseParameterDeclarationClause();
2020
65.7k
  if (TPR == TPResult::Ambiguous && 
Tok.isNot(tok::r_paren)6.57k
)
2021
0
    TPR = TPResult::False;
2022
65.7k
2023
65.7k
  if (TPR == TPResult::False || 
TPR == TPResult::Error65.7k
)
2024
2
    return TPR;
2025
65.7k
2026
65.7k
  // Parse through the parens.
2027
65.7k
  if (!SkipUntil(tok::r_paren, StopAtSemi))
2028
1
    return TPResult::Error;
2029
65.7k
2030
65.7k
  // cv-qualifier-seq
2031
87.4k
  
while (65.7k
Tok.isOneOf(tok::kw_const, tok::kw_volatile, tok::kw___unaligned,
2032
87.4k
                     tok::kw_restrict))
2033
21.7k
    ConsumeToken();
2034
65.7k
2035
65.7k
  // ref-qualifier[opt]
2036
65.7k
  if (Tok.isOneOf(tok::amp, tok::ampamp))
2037
10.5k
    ConsumeToken();
2038
65.7k
2039
65.7k
  // exception-specification
2040
65.7k
  if (Tok.is(tok::kw_throw)) {
2041
75
    ConsumeToken();
2042
75
    if (Tok.isNot(tok::l_paren))
2043
0
      return TPResult::Error;
2044
75
2045
75
    // Parse through the parens after 'throw'.
2046
75
    ConsumeParen();
2047
75
    if (!SkipUntil(tok::r_paren, StopAtSemi))
2048
0
      return TPResult::Error;
2049
65.7k
  }
2050
65.7k
  if (Tok.is(tok::kw_noexcept)) {
2051
69
    ConsumeToken();
2052
69
    // Possibly an expression as well.
2053
69
    if (Tok.is(tok::l_paren)) {
2054
27
      // Find the matching rparen.
2055
27
      ConsumeParen();
2056
27
      if (!SkipUntil(tok::r_paren, StopAtSemi))
2057
0
        return TPResult::Error;
2058
65.7k
    }
2059
69
  }
2060
65.7k
2061
65.7k
  return TPResult::Ambiguous;
2062
65.7k
}
2063
2064
/// '[' constant-expression[opt] ']'
2065
///
2066
5.55k
Parser::TPResult Parser::TryParseBracketDeclarator() {
2067
5.55k
  ConsumeBracket();
2068
5.55k
  if (!SkipUntil(tok::r_square, StopAtSemi))
2069
0
    return TPResult::Error;
2070
5.55k
2071
5.55k
  return TPResult::Ambiguous;
2072
5.55k
}
2073
2074
/// Determine whether we might be looking at the '<' template-argument-list '>'
2075
/// of a template-id or simple-template-id, rather than a less-than comparison.
2076
/// This will often fail and produce an ambiguity, but should never be wrong
2077
/// if it returns True or False.
2078
8.70k
Parser::TPResult Parser::isTemplateArgumentList(unsigned TokensToSkip) {
2079
8.70k
  if (!TokensToSkip) {
2080
4.15k
    if (Tok.isNot(tok::less))
2081
0
      return TPResult::False;
2082
4.15k
    if (NextToken().is(tok::greater))
2083
0
      return TPResult::True;
2084
8.70k
  }
2085
8.70k
2086
8.70k
  RevertingTentativeParsingAction PA(*this);
2087
8.70k
2088
13.2k
  while (TokensToSkip) {
2089
4.55k
    ConsumeAnyToken();
2090
4.55k
    --TokensToSkip;
2091
4.55k
  }
2092
8.70k
2093
8.70k
  if (!TryConsumeToken(tok::less))
2094
0
    return TPResult::False;
2095
8.70k
2096
8.70k
  // We can't do much to tell an expression apart from a template-argument,
2097
8.70k
  // but one good distinguishing factor is that a "decl-specifier" not
2098
8.70k
  // followed by '(' or '{' can't appear in an expression.
2099
8.70k
  bool InvalidAsTemplateArgumentList = false;
2100
8.70k
  if (isCXXDeclarationSpecifier(TPResult::False,
2101
8.70k
                                       &InvalidAsTemplateArgumentList) ==
2102
8.70k
             TPResult::True)
2103
282
    return TPResult::True;
2104
8.42k
  if (InvalidAsTemplateArgumentList)
2105
39
    return TPResult::False;
2106
8.38k
2107
8.38k
  // FIXME: In many contexts, X<thing1, Type> can only be a
2108
8.38k
  // template-argument-list. But that's not true in general:
2109
8.38k
  //
2110
8.38k
  // using b = int;
2111
8.38k
  // void f() {
2112
8.38k
  //   int a = A<B, b, c = C>D; // OK, declares b, not a template-id.
2113
8.38k
  //
2114
8.38k
  // X<Y<0, int> // ', int>' might be end of X's template argument list
2115
8.38k
  //
2116
8.38k
  // We might be able to disambiguate a few more cases if we're careful.
2117
8.38k
2118
8.38k
  // A template-argument-list must be terminated by a '>'.
2119
8.38k
  if (SkipUntil({tok::greater, tok::greatergreater, tok::greatergreatergreater},
2120
8.38k
                StopAtSemi | StopBeforeMatch))
2121
120
    return TPResult::Ambiguous;
2122
8.26k
  return TPResult::False;
2123
8.26k
}