================
@@ -39,20 +40,24 @@ Hints declHints(const Decl *D) {
 }
 
 std::vector<Hinted<SymbolLocation>> locateDecl(const Decl &D) {
-  std::vector<Hinted<SymbolLocation>> Result;
-  // FIXME: Should we also provide physical locations?
-  if (auto SS = tooling::stdlib::Recognizer()(&D)) {
-    Result.push_back({*SS, Hints::CompleteSymbol});
-    if (!D.hasBody())
-      return Result;
-  }
+  SourceManager &SM = D.getASTContext().getSourceManager();
+  bool HasBodyInMainFile = llvm::any_of(D.redecls(), [&](Decl *Redecl) {
+    return Redecl->hasBody() && SM.isInMainFile(Redecl->getLocation());
+  });
+  // if decl has body and in main file, we don't need to do further search.
+  if (!HasBodyInMainFile)
----------------
kadircet wrote:

glad to hear that we're aligned here!

`decl in user written file > stdlib recognition > other found.` makes sense to 
me in theory, but i don't think it's implementable in practice. moreover i 
don't understand what the 3rd category around "other" means.

telling apart a "physical" stdlib header (e.g. `<__utility/pair.h>`) from a 
user header (e.g. `<my_stdlib/pair.h>`) isn't possible. hence when something 
goes wrong, we'll always "insert" the wrong header (implementation detail, 
rather than public header for a stdlib symbol).

Hence I'd suggest going with:

1. "virtual" stdlib header (the one provided by 
`clang::tooling::stdlib::Header`)
2. any other physical location, providing the decl

This means we might do the wrong thing when the user has their own stdlib 
implementation (mixing your own symbols with standard library is a recipe for 
disaster, i don't think we need to care about that state). But we'll at least 
stop complaining once they include the "right" header. Moreover if need be we 
can improve handling for this case by turning of virtual stdlib support 
completely, when we detect we're working in an environment with a custom stdlib 
implementaiton.

WDYT?

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

Reply via email to