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. + auto *DT = FD->getReturnType()->getContainedDeducedType(); + if (DT && DT->getDeducedType().isNull()) + return false; + } return Consumer.shouldSkipFunctionBody(D); } 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 +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(); + m + // CHECK: COMPLETION: make_func : [#auto#]make_func<<#class T#>>() + }; +}