@@ -168,10 +168,10 @@ Decl *Parser::ParseTemplateDeclarationOrSpecialization(
168
168
LastParamListWasEmpty),
169
169
DeclEnd);
170
170
171
+ ParsedTemplateInfo TemplateInfo (&ParamLists, isSpecialization,
172
+ LastParamListWasEmpty);
171
173
return ParseSingleDeclarationAfterTemplate (
172
- Context,
173
- ParsedTemplateInfo (&ParamLists, isSpecialization, LastParamListWasEmpty),
174
- ParsingTemplateParams, DeclEnd, AccessAttrs, AS);
174
+ Context, TemplateInfo, ParsingTemplateParams, DeclEnd, AccessAttrs, AS);
175
175
}
176
176
177
177
// / Parse a single declaration that declares a template,
@@ -185,7 +185,7 @@ Decl *Parser::ParseTemplateDeclarationOrSpecialization(
185
185
// /
186
186
// / \returns the new declaration.
187
187
Decl *Parser::ParseSingleDeclarationAfterTemplate (
188
- DeclaratorContext Context, const ParsedTemplateInfo &TemplateInfo,
188
+ DeclaratorContext Context, ParsedTemplateInfo &TemplateInfo,
189
189
ParsingDeclRAIIObject &DiagsFromTParams, SourceLocation &DeclEnd,
190
190
ParsedAttributes &AccessAttrs, AccessSpecifier AS) {
191
191
assert (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate &&
@@ -262,123 +262,12 @@ Decl *Parser::ParseSingleDeclarationAfterTemplate(
262
262
if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation)
263
263
ProhibitAttributes (prefixAttrs);
264
264
265
- // Parse the declarator.
266
- ParsingDeclarator DeclaratorInfo (*this , DS, prefixAttrs,
267
- (DeclaratorContext)Context);
268
- if (TemplateInfo.TemplateParams )
269
- DeclaratorInfo.setTemplateParameterLists (*TemplateInfo.TemplateParams );
270
-
271
- // Turn off usual access checking for template specializations and
272
- // instantiations.
273
- // C++20 [temp.spec] 13.9/6.
274
- // This disables the access checking rules for function template explicit
275
- // instantiation and explicit specialization:
276
- // - parameter-list;
277
- // - template-argument-list;
278
- // - noexcept-specifier;
279
- // - dynamic-exception-specifications (deprecated in C++11, removed since
280
- // C++17).
281
- bool IsTemplateSpecOrInst =
282
- (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation ||
283
- TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization);
284
- SuppressAccessChecks SAC (*this , IsTemplateSpecOrInst);
285
-
286
- ParseDeclarator (DeclaratorInfo);
287
-
288
- if (IsTemplateSpecOrInst)
289
- SAC.done ();
290
-
291
- // Error parsing the declarator?
292
- if (!DeclaratorInfo.hasName ()) {
293
- SkipMalformedDecl ();
265
+ auto DeclGroupPtr =
266
+ ParseDeclGroup (DS, Context, prefixAttrs, TemplateInfo, &DeclEnd,
267
+ /* FRI=*/ nullptr );
268
+ if (!DeclGroupPtr || !DeclGroupPtr.get ().isSingleDecl ())
294
269
return nullptr ;
295
- }
296
-
297
- LateParsedAttrList LateParsedAttrs (true );
298
- if (DeclaratorInfo.isFunctionDeclarator ()) {
299
- if (Tok.is (tok::kw_requires)) {
300
- CXXScopeSpec &ScopeSpec = DeclaratorInfo.getCXXScopeSpec ();
301
- DeclaratorScopeObj DeclScopeObj (*this , ScopeSpec);
302
- if (ScopeSpec.isValid () &&
303
- Actions.ShouldEnterDeclaratorScope (getCurScope (), ScopeSpec))
304
- DeclScopeObj.EnterDeclaratorScope ();
305
- ParseTrailingRequiresClause (DeclaratorInfo);
306
- }
307
-
308
- MaybeParseGNUAttributes (DeclaratorInfo, &LateParsedAttrs);
309
- }
310
-
311
- if (DeclaratorInfo.isFunctionDeclarator () &&
312
- isStartOfFunctionDefinition (DeclaratorInfo)) {
313
-
314
- // Function definitions are only allowed at file scope and in C++ classes.
315
- // The C++ inline method definition case is handled elsewhere, so we only
316
- // need to handle the file scope definition case.
317
- if (Context != DeclaratorContext::File) {
318
- Diag (Tok, diag::err_function_definition_not_allowed);
319
- SkipMalformedDecl ();
320
- return nullptr ;
321
- }
322
-
323
- if (DS.getStorageClassSpec () == DeclSpec::SCS_typedef) {
324
- // Recover by ignoring the 'typedef'. This was probably supposed to be
325
- // the 'typename' keyword, which we should have already suggested adding
326
- // if it's appropriate.
327
- Diag (DS.getStorageClassSpecLoc (), diag::err_function_declared_typedef)
328
- << FixItHint::CreateRemoval (DS.getStorageClassSpecLoc ());
329
- DS.ClearStorageClassSpecs ();
330
- }
331
-
332
- if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
333
- if (DeclaratorInfo.getName ().getKind () !=
334
- UnqualifiedIdKind::IK_TemplateId) {
335
- // If the declarator-id is not a template-id, issue a diagnostic and
336
- // recover by ignoring the 'template' keyword.
337
- Diag (Tok, diag::err_template_defn_explicit_instantiation) << 0 ;
338
- return ParseFunctionDefinition (DeclaratorInfo, ParsedTemplateInfo (),
339
- &LateParsedAttrs);
340
- } else {
341
- SourceLocation LAngleLoc
342
- = PP.getLocForEndOfToken (TemplateInfo.TemplateLoc );
343
- Diag (DeclaratorInfo.getIdentifierLoc (),
344
- diag::err_explicit_instantiation_with_definition)
345
- << SourceRange (TemplateInfo.TemplateLoc )
346
- << FixItHint::CreateInsertion (LAngleLoc, " <>" );
347
-
348
- // Recover as if it were an explicit specialization.
349
- TemplateParameterLists FakedParamLists;
350
- FakedParamLists.push_back (Actions.ActOnTemplateParameterList (
351
- 0 , SourceLocation (), TemplateInfo.TemplateLoc , LAngleLoc,
352
- std::nullopt, LAngleLoc, nullptr ));
353
-
354
- return ParseFunctionDefinition (
355
- DeclaratorInfo, ParsedTemplateInfo (&FakedParamLists,
356
- /* isSpecialization=*/ true ,
357
- /* lastParameterListWasEmpty=*/ true ),
358
- &LateParsedAttrs);
359
- }
360
- }
361
- return ParseFunctionDefinition (DeclaratorInfo, TemplateInfo,
362
- &LateParsedAttrs);
363
- }
364
-
365
- // Parse this declaration.
366
- Decl *ThisDecl = ParseDeclarationAfterDeclarator (DeclaratorInfo,
367
- TemplateInfo);
368
-
369
- if (Tok.is (tok::comma)) {
370
- Diag (Tok, diag::err_multiple_template_declarators)
371
- << (int )TemplateInfo.Kind ;
372
- SkipUntil (tok::semi);
373
- return ThisDecl;
374
- }
375
-
376
- // Eat the semi colon after the declaration.
377
- ExpectAndConsumeSemi (diag::err_expected_semi_declaration);
378
- if (LateParsedAttrs.size () > 0 )
379
- ParseLexedAttributeList (LateParsedAttrs, ThisDecl, true , false );
380
- DeclaratorInfo.complete (ThisDecl);
381
- return ThisDecl;
270
+ return DeclGroupPtr.get ().getSingleDecl ();
382
271
}
383
272
384
273
// / \brief Parse a single declaration that declares a concept.
@@ -1696,9 +1585,9 @@ Decl *Parser::ParseExplicitInstantiation(DeclaratorContext Context,
1696
1585
ParsingDeclRAIIObject
1697
1586
ParsingTemplateParams (*this , ParsingDeclRAIIObject::NoParent);
1698
1587
1588
+ ParsedTemplateInfo TemplateInfo (ExternLoc, TemplateLoc);
1699
1589
return ParseSingleDeclarationAfterTemplate (
1700
- Context, ParsedTemplateInfo (ExternLoc, TemplateLoc),
1701
- ParsingTemplateParams, DeclEnd, AccessAttrs, AS);
1590
+ Context, TemplateInfo, ParsingTemplateParams, DeclEnd, AccessAttrs, AS);
1702
1591
}
1703
1592
1704
1593
SourceRange Parser::ParsedTemplateInfo::getSourceRange () const {
0 commit comments