[PATCH] D61057: [Sema] Naively create CallExpr when there's one lookup candidate.

Sam McCall via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 24 01:51:33 PDT 2019


sammccall created this revision.
Herald added subscribers: llvm-commits, kadircet, arphaman, jkorous.
Herald added a project: LLVM.

This is not suitable to land, just something to talk about.


Repository:
  rL LLVM

https://reviews.llvm.org/D61057

Files:
  clang-tools-extra/unittests/clangd/XRefsTests.cpp
  clang/lib/Sema/SemaOverload.cpp


Index: clang/lib/Sema/SemaOverload.cpp
===================================================================
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -12095,9 +12095,22 @@
       }
     }
 
+    CallExpr *FakeCE = nullptr;
+    if (AllowTypoCorrection && CandidateSet->size() == 1) {
+      auto& Candidate = *CandidateSet->begin();
+      Fn = SemaRef.FixOverloadedFunctionReference(Fn, Candidate.FoundDecl,
+                                                  Candidate.Function);
+      FakeCE =
+          CallExpr::Create(SemaRef.getASTContext(), Fn, Args,
+                           Candidate.Function->getReturnType(), VK_RValue,
+                           RParenLoc, 0, Candidate.IsADLCandidate);
+    }
+
     SemaRef.Diag(Fn->getBeginLoc(), diag::err_ovl_no_viable_function_in_call)
         << ULE->getName() << Fn->getSourceRange();
     CandidateSet->NoteCandidates(SemaRef, OCD_AllCandidates, Args);
+    if (FakeCE)
+      return FakeCE;
     break;
   }
 
Index: clang-tools-extra/unittests/clangd/XRefsTests.cpp
===================================================================
--- clang-tools-extra/unittests/clangd/XRefsTests.cpp
+++ clang-tools-extra/unittests/clangd/XRefsTests.cpp
@@ -416,6 +416,13 @@
           auto x = m^akeX();
         }
       )cpp",
+
+      R"cpp(// Broken code: one overload, but not valid.
+        int $decl[[foo]](int);
+        void bar() {
+          ^foo(42, 43);
+        }
+      )cpp",
   };
   for (const char *Test : Tests) {
     Annotations T(Test);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61057.196397.patch
Type: text/x-patch
Size: 1545 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190424/8f7cb441/attachment.bin>


More information about the llvm-commits mailing list