[flang-commits] [clang-tools-extra] [llvm] [libunwind] [mlir] [lld] [libc] [clang] [flang] [libcxx] [libcxxabi] [lldb] [openmp] [Clang][Sema] Don't say "is declared here" for invalid template locations (PR #71264)

Justin Bogner via flang-commits flang-commits at lists.llvm.org
Thu Nov 30 11:53:35 PST 2023


================
@@ -7909,6 +7903,37 @@ bool Sema::CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
                                          Arg.getLocation());
 }
 
+static Sema::SemaDiagnosticBuilder noteLocation(Sema &S, const NamedDecl &Decl,
+                                                unsigned HereDiagID,
+                                                unsigned ExternalDiagID) {
+  if (Decl.getLocation().isValid())
+    return S.Diag(Decl.getLocation(), HereDiagID);
+
+  SmallString<128> Str;
+  llvm::raw_svector_ostream Out(Str);
+  PrintingPolicy PP = S.getPrintingPolicy();
+  PP.TerseOutput = 1;
+  Decl.print(Out, PP);
+  return S.Diag(Decl.getLocation(), ExternalDiagID) << Out.str();
----------------
bogner wrote:

Using `<< &Decl` here just gives the name. With print we get:
```
template declaration from hidden source: template <class element = float, int element_count = 4> using vector = element __attribute__((ext_vector_type(element_count)))
template parameter from hidden source: class element = float
```
whereas with the stream operator it's
```
note: template declaration from hidden source: 'vector'
note: template parameter from hidden source: 'element'
```

Similarly in #71265 it's the difference between printing `template <class element_type> class RWBuffer final` vs just `RWBuffer`

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


More information about the flang-commits mailing list