[PATCH] D44480: [Sema] Don't skip function bodies with 'auto' without trailing return type

Ilya Biryukov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 27 07:29:12 PDT 2018


ilya-biryukov updated this revision to Diff 139926.
ilya-biryukov added a comment.

- Replace auto with explicit type


Repository:
  rC Clang

https://reviews.llvm.org/D44480

Files:
  lib/Sema/SemaDecl.cpp
  test/CodeCompletion/crash-skipped-bodies-template-inst.cpp


Index: test/CodeCompletion/crash-skipped-bodies-template-inst.cpp
===================================================================
--- /dev/null
+++ test/CodeCompletion/crash-skipped-bodies-template-inst.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:24:5 %s -o - 2>&1 | FileCheck %s
+template <class T>
+auto make_func() {
+  struct impl {
+    impl* func() {
+      int x;
+      if (x = 10) {}
+      // Check that body of this function is actually skipped.
+      // CHECK-NOT: crash-skipped-bodies-template-inst.cpp:7:{{[0-9]+}}: warning: using the result of an assignment as a condition without parentheses
+      return this;
+    }
+  };
+
+  int x;
+  if (x = 10) {}
+  // Check that this function is not skipped.
+  // CHECK: crash-skipped-bodies-template-inst.cpp:15:9: warning: using the result of an assignment as a condition without parentheses
+  return impl();
+}
+
+void foo() {
+  []() {
+    make_func<int>();
+    m
+    // CHECK: COMPLETION: make_func : [#auto#]make_func<<#class T#>>()
+  };
+}
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -12603,9 +12603,15 @@
   // rest of the file.
   // We cannot skip the body of a function with an undeduced return type,
   // because any callers of that function need to know the type.
-  if (const FunctionDecl *FD = D->getAsFunction())
-    if (FD->isConstexpr() || FD->getReturnType()->isUndeducedType())
+  if (const FunctionDecl *FD = D->getAsFunction()) {
+    if (FD->isConstexpr())
       return false;
+    // We can't simply call Type::isUndeducedType here, because it returns
+    // false on C++14's auto return type without trailing return type.
+    DeducedType *DT = FD->getReturnType()->getContainedDeducedType();
+    if (DT && DT->getDeducedType().isNull())
+      return false;
+  }
   return Consumer.shouldSkipFunctionBody(D);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44480.139926.patch
Type: text/x-patch
Size: 1957 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180327/5bfcb948/attachment.bin>


More information about the cfe-commits mailing list