ilya-biryukov created this revision. ilya-biryukov added reviewers: aaron.ballman, sammccall.
Skipping them was clearly not intentional. It's impossible to guarantee correctness if the bodies are skipped. Also adds a test case for r327504, now that it does not produce invalid errors that made the test fail. 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. + 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 <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. + auto *DT = FD->getReturnType()->getContainedDeducedType(); + if (DT && DT->getDeducedType().isNull()) + return false; + } return Consumer.shouldSkipFunctionBody(D); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits