]> granicus.if.org Git - clang/commitdiff
Fixed failing assert in code completion.
authorIlya Biryukov <ibiryukov@google.com>
Fri, 21 Jul 2017 09:24:00 +0000 (09:24 +0000)
committerIlya Biryukov <ibiryukov@google.com>
Fri, 21 Jul 2017 09:24:00 +0000 (09:24 +0000)
Summary:
The code was accessing uninstantiated default argument.
This resulted in failing assertion at ParmVarDecl::getDefaultArg().

Reviewers: erikjv, klimek, bkramer, krasimir

Reviewed By: krasimir

Subscribers: cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@308722 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaCodeComplete.cpp
test/CodeCompletion/uninstantiated_params.cpp [new file with mode: 0644]

index 91a8c619b26c09ec7fba085030609f040d3b5931..4de7d422072dab43de63d954201f7708b60af49b 100644 (file)
@@ -2401,10 +2401,7 @@ formatBlockPlaceholder(const PrintingPolicy &Policy, const NamedDecl *BlockDecl,
 static std::string GetDefaultValueString(const ParmVarDecl *Param,
                                          const SourceManager &SM,
                                          const LangOptions &LangOpts) {
-  const Expr *defaultArg = Param->getDefaultArg();
-  if (!defaultArg)
-    return "";
-  const SourceRange SrcRange = defaultArg->getSourceRange();
+  const SourceRange SrcRange = Param->getDefaultArgRange();
   CharSourceRange CharSrcRange = CharSourceRange::getTokenRange(SrcRange);
   bool Invalid = CharSrcRange.isInvalid();
   if (Invalid)
diff --git a/test/CodeCompletion/uninstantiated_params.cpp b/test/CodeCompletion/uninstantiated_params.cpp
new file mode 100644 (file)
index 0000000..57a520d
--- /dev/null
@@ -0,0 +1,13 @@
+template <class T>
+struct unique_ptr {
+  typedef T* pointer;
+
+  void reset(pointer ptr = pointer());
+};
+
+void test() {
+  unique_ptr<int> x;
+  x.
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:10:5 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+  // CHECK-CC1: [#void#]reset({#<#unique_ptr<int>::pointer ptr = pointer()#>#})
+}