Switch a cast to a dyn_cast and check the pointer before using. Fixes a crash
in the following code:
void test4(bool (&x)(void)) {
while (x);
}
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145918 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index 1ec7e39..869922f 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -3771,10 +3771,11 @@
}
if (D && !D->isWeak()) {
- FunctionDecl* F = cast<FunctionDecl>(D);
- S.Diag(E->getExprLoc(), diag::warn_impcast_function_to_bool)
- << F << E->getSourceRange() << SourceRange(CC);
- return;
+ if (FunctionDecl* F = dyn_cast<FunctionDecl>(D)) {
+ S.Diag(E->getExprLoc(), diag::warn_impcast_function_to_bool)
+ << F << E->getSourceRange() << SourceRange(CC);
+ return;
+ }
}
}
return; // Other casts to bool are not checked.