@@ -9717,27 +9717,24 @@ auto Parser::parse_explicit_instantiation(DeclarationAST*& yyast) -> bool {
9717
9717
if (!parse_declaration (ast->declaration , BindingContext::kTemplate ))
9718
9718
parse_error (" expected a declaration" );
9719
9719
9720
- auto check_elaborated_type_specifier = [&] {
9721
- if (!config ().checkTypes ) return ;
9722
-
9720
+ auto check_elaborated_type_specifier = [&]() -> bool {
9723
9721
auto simpleDecl = ast_cast<SimpleDeclarationAST>(ast->declaration );
9724
- if (!simpleDecl) return ;
9722
+ if (!simpleDecl) return false ;
9725
9723
9726
- if (!simpleDecl->declSpecifierList ) return ;
9724
+ if (!simpleDecl->declSpecifierList ) return false ;
9727
9725
9728
9726
auto elabSpec = ast_cast<ElaboratedTypeSpecifierAST>(
9729
9727
simpleDecl->declSpecifierList ->value );
9730
9728
if (!elabSpec) {
9731
- type_error (currentLocation (), " expected an elaborated type specifier" );
9732
- return ;
9729
+ return false ;
9733
9730
}
9734
9731
9735
9732
if (elabSpec->nestedNameSpecifier ) {
9736
9733
auto templateId = ast_cast<SimpleTemplateIdAST>(elabSpec->unqualifiedId );
9737
9734
if (!templateId) {
9738
9735
type_error (elabSpec->unqualifiedId ->firstSourceLocation (),
9739
9736
" expected a template id" );
9740
- return ;
9737
+ return true ;
9741
9738
}
9742
9739
9743
9740
auto candidate = Lookup{scope ()}.qualifiedLookup (
@@ -9746,7 +9743,7 @@ auto Parser::parse_explicit_instantiation(DeclarationAST*& yyast) -> bool {
9746
9743
if (!is_template (candidate)) {
9747
9744
type_error (elabSpec->unqualifiedId ->firstSourceLocation (),
9748
9745
std::format (" expected a template" ));
9749
- return ;
9746
+ return true ;
9750
9747
}
9751
9748
9752
9749
auto classSymbol = symbol_cast<ClassSymbol>(candidate);
@@ -9755,37 +9752,48 @@ auto Parser::parse_explicit_instantiation(DeclarationAST*& yyast) -> bool {
9755
9752
elabSpec->unqualifiedId ->firstSourceLocation (),
9756
9753
std::format (" expected a class template, got '{}'" ,
9757
9754
to_string (candidate->type (), candidate->name ())));
9758
- return ;
9755
+ return true ;
9759
9756
}
9760
9757
9761
- auto instance = ASTRewriter::instantiateClassTemplate (
9762
- unit, templateId->templateArgumentList , classSymbol);
9758
+ if (config ().checkTypes ) {
9759
+ auto instance = ASTRewriter::instantiateClassTemplate (
9760
+ unit, templateId->templateArgumentList , classSymbol);
9763
9761
9764
- return ;
9762
+ (void )instance;
9763
+ }
9764
+
9765
+ return true ;
9765
9766
}
9766
9767
9767
9768
auto templateId = ast_cast<SimpleTemplateIdAST>(elabSpec->unqualifiedId );
9768
9769
if (!templateId) {
9769
9770
type_error (elabSpec->unqualifiedId ->firstSourceLocation (),
9770
9771
" expected a template id" );
9771
- return ;
9772
+ return true ;
9772
9773
}
9773
9774
9774
9775
auto classSymbol = symbol_cast<ClassSymbol>(templateId->symbol );
9775
9776
if (!classSymbol) {
9776
9777
type_error (
9777
9778
templateId->identifierLoc ,
9778
9779
" explicit instantiation of this template is not yet supported" );
9779
- return ;
9780
+ return true ;
9780
9781
}
9781
9782
9782
- auto instance = ASTRewriter::instantiateClassTemplate (
9783
- unit, templateId->templateArgumentList , classSymbol);
9783
+ if (config ().checkTypes ) {
9784
+ auto instance = ASTRewriter::instantiateClassTemplate (
9785
+ unit, templateId->templateArgumentList , classSymbol);
9786
+
9787
+ (void )instance;
9788
+ }
9784
9789
9785
- ( void )instance ;
9790
+ return true ;
9786
9791
};
9787
9792
9788
- check_elaborated_type_specifier ();
9793
+ if (check_elaborated_type_specifier ()) return true ;
9794
+
9795
+ // todo: handle other template kinds
9796
+ type_error (ast->firstSourceLocation (), " failed to instantiate template" );
9789
9797
9790
9798
return true ;
9791
9799
}
0 commit comments