[clang] [clang][Diagnostic] Clarify error message for auto (PR #149781)
Emily Dror via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 15 03:19:56 PDT 2025
================
@@ -8229,24 +8229,37 @@ Sema::CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams) {
// C++ [temp.class.spec]p6: [P2096]
// A partial specialization may be declared in any scope in which the
// corresponding primary template may be defined.
+ auto FindTemplateParamsLoc = [](TemplateParameterList *TemplateParams,
+ SourceLocation Fallback) {
+ SourceLocation DiagLoc = TemplateParams->getTemplateLoc();
+ if (DiagLoc.isValid())
+ return DiagLoc;
+
+ for (const NamedDecl *Param : *TemplateParams)
+ if (Param && Param->getLocation().isValid())
+ return Param->getLocation();
+
+ return Fallback;
+ };
+
if (Ctx) {
if (Ctx->isFileContext())
return false;
if (CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(Ctx)) {
// C++ [temp.mem]p2:
// A local class shall not have member templates.
- if (RD->isLocalClass())
- return Diag(TemplateParams->getTemplateLoc(),
+ if (RD->isLocalClass()) {
----------------
emily-dror wrote:
Oops, thanks for pointing that out. I'll change it :)
https://github.com/llvm/llvm-project/pull/149781
More information about the cfe-commits
mailing list