llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Emily Dror (emily-dror)

<details>
<summary>Changes</summary>

Show line and file for auto template error in -std=c++20 or -std=c++23


---
Full diff: https://github.com/llvm/llvm-project/pull/149781.diff


1 Files Affected:

- (modified) clang/lib/Sema/SemaTemplate.cpp (+18-6) 


``````````diff
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index b76619fc50268..4505d5f7f2226 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -8238,12 +8238,24 @@ Sema::CheckTemplateDeclScope(Scope *S, 
TemplateParameterList *TemplateParams) {
     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(),
-                    diag::err_template_inside_local_class)
-          << TemplateParams->getSourceRange();
-      else
-        return false;
+      if (RD->isLocalClass()) {
+        SourceLocation DiagLoc = TemplateParams->getTemplateLoc();
+        if (DiagLoc.isInvalid()) {
+          for (const NamedDecl *Param : *TemplateParams) {
+            if (Param && Param->getLocation().isValid()) {
+              DiagLoc = Param->getLocation();
+              break;
+            }
+          }
+        }
+        if (DiagLoc.isInvalid()) {
+          // Still no good location? Fall back to the class declaration itself
+          DiagLoc = RD->getLocation();
+        }
+        return Diag(DiagLoc, diag::err_template_inside_local_class)
+               << TemplateParams->getSourceRange();
+      }
+      return false;
     }
   }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/149781
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to