[clang] [Clang] use parameter location for abbreviated function templates (PR #129139)

via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 5 07:16:53 PST 2025


================
@@ -7991,8 +7991,12 @@ Sema::CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams) {
   //   have C linkage.
   DeclContext *Ctx = S->getEntity();
   if (Ctx && Ctx->isExternCContext()) {
-    Diag(TemplateParams->getTemplateLoc(), diag::err_template_linkage)
-        << TemplateParams->getSourceRange();
+    SourceRange Range =
+        TemplateParams->getTemplateLoc().isInvalid() && TemplateParams->size()
+            ? TemplateParams->getParam(TemplateParams->size() - 1)
+                  ->getSourceRange()
----------------
cor3ntin wrote:

I think using the first param would be better, yes

(in the general case, you can have

```cpp
template <typename>
void f(auto);
```

so to establish if there are abbreviated parameters, you need to look at the first one, 
(and getTemplateLoc is always valid)

but in the 
```cpp
void f(auto)
```

case, there are only abbreviated parameters, and you can point to the first one (and getTemplateLoc is never valid).

Does that make sense?


https://github.com/llvm/llvm-project/pull/129139


More information about the cfe-commits mailing list