[PATCH] D39730: Enabling constructor code completion

Jan Korous via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 10 10:25:39 PST 2017


jkorous-apple updated this revision to Diff 122470.
jkorous-apple added a comment.

I am able to enable ctor completion selectively in translate unit scope and namespace scope so ctor completion does not appear in dot access context. I haven't figured out how to explicitly specify that completion context needs to be qualified id though.


https://reviews.llvm.org/D39730

Files:
  lib/Sema/SemaCodeComplete.cpp
  test/CodeCompletion/ctor.cpp


Index: test/CodeCompletion/ctor.cpp
===================================================================
--- /dev/null
+++ test/CodeCompletion/ctor.cpp
@@ -0,0 +1,50 @@
+struct foo {
+  foo();
+  ~foo();
+
+  foo(const foo&) = delete;
+  foo(foo&&) = delete;
+  foo& operator=(const foo&) = delete;
+  foo& operator=(foo&&) = delete;
+
+  static bool faz;
+  int far;
+};
+
+foo::foo() { }
+// RUN: c-index-test -code-completion-at=%s:14:7 %s | FileCheck -check-prefix=CHECK-TRANSLATION-UNIT %s
+// CHECK-TRANSLATION-UNIT:CXXConstructor:{TypedText foo}{LeftParen (}{RightParen )} (35)
+// CHECK-TRANSLATION-UNIT:CXXConstructor:{TypedText foo}{LeftParen (}{Placeholder const foo &}{RightParen )} (35) (unavailable)
+// CHECK-TRANSLATION-UNIT:CXXConstructor:{TypedText foo}{LeftParen (}{Placeholder foo &&}{RightParen )} (35) (unavailable)
+
+namespace ns_foo {
+struct foo {
+  foo();
+  ~foo();
+
+  foo(const foo&) = delete;
+  foo(foo&&) = delete;
+  foo& operator=(const foo&) = delete;
+  foo& operator=(foo&&) = delete;
+
+  static bool faz;
+  int far;
+};
+
+foo::foo() { }
+// RUN: c-index-test -code-completion-at=%s:34:7 %s | FileCheck -check-prefix=CHECK-NAMESPACE %s
+// CHECK-NAMESPACE: CXXConstructor:{TypedText foo}{LeftParen (}{RightParen )} (35)
+// CHECK-NAMESPACE: CXXConstructor:{TypedText foo}{LeftParen (}{Placeholder const ns_foo::foo &}{RightParen )} (35) (unavailable)
+// CHECK-NAMESPACE: CXXConstructor:{TypedText foo}{LeftParen (}{Placeholder ns_foo::foo &&}{RightParen )} (35) (unavailable)
+
+}
+
+int main() {
+  foo baz;
+  baz.far = 5;
+  foo::faz = 42;
+}
+// RUN: c-index-test -code-completion-at=%s:44:7 %s | not grep "CXXConstructor"
+// RUN: c-index-test -code-completion-at=%s:44:8 %s | not grep "CXXConstructor"
+// RUN: c-index-test -code-completion-at=%s:45:8 %s | not grep "CXXConstructor"
+// RUN: c-index-test -code-completion-at=%s:45:9 %s | not grep "CXXConstructor"
Index: lib/Sema/SemaCodeComplete.cpp
===================================================================
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -975,9 +975,11 @@
   bool AsNestedNameSpecifier = false;
   if (!isInterestingDecl(R.Declaration, AsNestedNameSpecifier))
     return;
-  
-  // C++ constructors are never found by name lookup.
-  if (isa<CXXConstructorDecl>(R.Declaration))
+
+  if (isa<CXXConstructorDecl>(R.Declaration)
+      && dyn_cast<NamespaceDecl>(CurContext) == nullptr
+      && dyn_cast<TranslationUnitDecl>(CurContext) == nullptr
+    )
     return;
 
   if (Hiding && CheckHiddenResult(R, CurContext, Hiding))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39730.122470.patch
Type: text/x-patch
Size: 2579 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171110/435b1113/attachment.bin>


More information about the cfe-commits mailing list