Skip to content

Commit a1a8216

Browse files
committed
Report explicit instantiations that are not yet supported.
1 parent 58c7a76 commit a1a8216

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

src/parser/cxx/parser.cc

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9717,27 +9717,24 @@ auto Parser::parse_explicit_instantiation(DeclarationAST*& yyast) -> bool {
97179717
if (!parse_declaration(ast->declaration, BindingContext::kTemplate))
97189718
parse_error("expected a declaration");
97199719

9720-
auto check_elaborated_type_specifier = [&] {
9721-
if (!config().checkTypes) return;
9722-
9720+
auto check_elaborated_type_specifier = [&]() -> bool {
97239721
auto simpleDecl = ast_cast<SimpleDeclarationAST>(ast->declaration);
9724-
if (!simpleDecl) return;
9722+
if (!simpleDecl) return false;
97259723

9726-
if (!simpleDecl->declSpecifierList) return;
9724+
if (!simpleDecl->declSpecifierList) return false;
97279725

97289726
auto elabSpec = ast_cast<ElaboratedTypeSpecifierAST>(
97299727
simpleDecl->declSpecifierList->value);
97309728
if (!elabSpec) {
9731-
type_error(currentLocation(), "expected an elaborated type specifier");
9732-
return;
9729+
return false;
97339730
}
97349731

97359732
if (elabSpec->nestedNameSpecifier) {
97369733
auto templateId = ast_cast<SimpleTemplateIdAST>(elabSpec->unqualifiedId);
97379734
if (!templateId) {
97389735
type_error(elabSpec->unqualifiedId->firstSourceLocation(),
97399736
"expected a template id");
9740-
return;
9737+
return true;
97419738
}
97429739

97439740
auto candidate = Lookup{scope()}.qualifiedLookup(
@@ -9746,7 +9743,7 @@ auto Parser::parse_explicit_instantiation(DeclarationAST*& yyast) -> bool {
97469743
if (!is_template(candidate)) {
97479744
type_error(elabSpec->unqualifiedId->firstSourceLocation(),
97489745
std::format("expected a template"));
9749-
return;
9746+
return true;
97509747
}
97519748

97529749
auto classSymbol = symbol_cast<ClassSymbol>(candidate);
@@ -9755,37 +9752,48 @@ auto Parser::parse_explicit_instantiation(DeclarationAST*& yyast) -> bool {
97559752
elabSpec->unqualifiedId->firstSourceLocation(),
97569753
std::format("expected a class template, got '{}'",
97579754
to_string(candidate->type(), candidate->name())));
9758-
return;
9755+
return true;
97599756
}
97609757

9761-
auto instance = ASTRewriter::instantiateClassTemplate(
9762-
unit, templateId->templateArgumentList, classSymbol);
9758+
if (config().checkTypes) {
9759+
auto instance = ASTRewriter::instantiateClassTemplate(
9760+
unit, templateId->templateArgumentList, classSymbol);
97639761

9764-
return;
9762+
(void)instance;
9763+
}
9764+
9765+
return true;
97659766
}
97669767

97679768
auto templateId = ast_cast<SimpleTemplateIdAST>(elabSpec->unqualifiedId);
97689769
if (!templateId) {
97699770
type_error(elabSpec->unqualifiedId->firstSourceLocation(),
97709771
"expected a template id");
9771-
return;
9772+
return true;
97729773
}
97739774

97749775
auto classSymbol = symbol_cast<ClassSymbol>(templateId->symbol);
97759776
if (!classSymbol) {
97769777
type_error(
97779778
templateId->identifierLoc,
97789779
"explicit instantiation of this template is not yet supported");
9779-
return;
9780+
return true;
97809781
}
97819782

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+
}
97849789

9785-
(void)instance;
9790+
return true;
97869791
};
97879792

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");
97899797

97909798
return true;
97919799
}

0 commit comments

Comments
 (0)