[CodeComplete] Constructor overload candidates report as vector(int) instead of vecto...
authorSam McCall <sam.mccall@gmail.com>
Fri, 15 Nov 2019 13:52:04 +0000 (14:52 +0100)
committerSam McCall <sam.mccall@gmail.com>
Fri, 15 Nov 2019 14:42:18 +0000 (15:42 +0100)
Summary:
This is shorter, shouldn't be confusing (is consistent with how they're declared),
and avoids messy cases that are printed as myclass<type-param-0-0>(int) in the
case of partial specialization.

Fixes part of https://github.com/clangd/clangd/issues/76

Reviewers: hokein, lh123

Subscribers: ilya-biryukov, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70307

clang/lib/Sema/SemaCodeComplete.cpp
clang/test/CodeCompletion/templates.cpp

index e4c4264d9dc2eb25fe8c0bd722d63fb4b9c54707..ade6e46d1bcad6a610f1341c365d74af3a555494 100644 (file)
@@ -3653,6 +3653,10 @@ CodeCompleteConsumer::OverloadCandidate::CreateSignatureString(
     unsigned CurrentArg, Sema &S, CodeCompletionAllocator &Allocator,
     CodeCompletionTUInfo &CCTUInfo, bool IncludeBriefComments) const {
   PrintingPolicy Policy = getCompletionPrintingPolicy(S);
+  // Show signatures of constructors as they are declared:
+  //   vector(int n) rather than vector<string>(int n)
+  // This is less noisy without being less clear, and avoids tricky cases.
+  Policy.SuppressTemplateArgsInCXXConstructors = true;
 
   // FIXME: Set priority, availability appropriately.
   CodeCompletionBuilder Result(Allocator, CCTUInfo, 1,
index 32a7b2125fec8426788454418b81ce866bd8db5c..f9811f4464768fe0408d537a556fd4b0d15af5ad 100644 (file)
@@ -24,5 +24,12 @@ void f() {
   // CHECK-CC2: foo
   // CHECK-CC2: in_base
   // CHECK-CC2: stop
-  
+}
+
 
+template <typename> struct X;
+template <typename T> struct X<T*> { X(double); };
+X<int*> x(42);
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:32:11 %s -o - | FileCheck -check-prefix=CHECK-CONSTRUCTOR %s
+// CHECK-CONSTRUCTOR: OVERLOAD: X(<#double#>)
+// (rather than X<type-parameter-0-0 *>(<#double#>)