kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

CodeCompletion was not being triggered after successfully parsed
initializer lists, e.g.

  cpp
  void foo(int, bool);
  void bar() {
    foo({1}^, false);
  }

CodeCompletion would suggest the function foo as an overload candidate up until
the point marked with `^` but after that point we do not trigger signature help
since parsing succeeds.

This patch handles that case by failing in parsing expression lists whenever we
see a codecompletion token, in addition to getting an invalid subexpression.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73177

Files:
  clang/lib/Parse/ParseExpr.cpp
  clang/test/CodeCompletion/call.cpp


Index: clang/test/CodeCompletion/call.cpp
===================================================================
--- clang/test/CodeCompletion/call.cpp
+++ clang/test/CodeCompletion/call.cpp
@@ -25,4 +25,10 @@
   // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:19:13 %s -o - | 
FileCheck -check-prefix=CHECK-CC2 %s
   // CHECK-CC2-NOT: f(Y y, int ZZ)
   // CHECK-CC2: f(int i, int j, <#int k#>)
+  f({}, 0, 0);
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns 
-code-completion-at=%s:28:7 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+  // CHECK-CC3: OVERLOAD: [#void#]f()
+  // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#X#>)
+  // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#int i#>, int j, int k)
+  // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#float x#>, float y)
 }
Index: clang/lib/Parse/ParseExpr.cpp
===================================================================
--- clang/lib/Parse/ParseExpr.cpp
+++ clang/lib/Parse/ParseExpr.cpp
@@ -3128,6 +3128,11 @@
 
     if (Tok.is(tok::ellipsis))
       Expr = Actions.ActOnPackExpansion(Expr.get(), ConsumeToken());
+    else if (Tok.is(tok::code_completion)) {
+      SawError = true;
+      cutOffParsing();
+      break;
+    }
     if (Expr.isInvalid()) {
       SkipUntil(tok::comma, tok::r_paren, StopBeforeMatch);
       SawError = true;


Index: clang/test/CodeCompletion/call.cpp
===================================================================
--- clang/test/CodeCompletion/call.cpp
+++ clang/test/CodeCompletion/call.cpp
@@ -25,4 +25,10 @@
   // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:19:13 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
   // CHECK-CC2-NOT: f(Y y, int ZZ)
   // CHECK-CC2: f(int i, int j, <#int k#>)
+  f({}, 0, 0);
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:28:7 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+  // CHECK-CC3: OVERLOAD: [#void#]f()
+  // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#X#>)
+  // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#int i#>, int j, int k)
+  // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#float x#>, float y)
 }
Index: clang/lib/Parse/ParseExpr.cpp
===================================================================
--- clang/lib/Parse/ParseExpr.cpp
+++ clang/lib/Parse/ParseExpr.cpp
@@ -3128,6 +3128,11 @@
 
     if (Tok.is(tok::ellipsis))
       Expr = Actions.ActOnPackExpansion(Expr.get(), ConsumeToken());
+    else if (Tok.is(tok::code_completion)) {
+      SawError = true;
+      cutOffParsing();
+      break;
+    }
     if (Expr.isInvalid()) {
       SkipUntil(tok::comma, tok::r_paren, StopBeforeMatch);
       SawError = true;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D73177: [cl... Kadir Cetinkaya via Phabricator via cfe-commits

Reply via email to