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);
}
llvm-svn: 145918
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 1ec7e39..869922f 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/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.
diff --git a/clang/test/SemaCXX/condition.cpp b/clang/test/SemaCXX/condition.cpp
index 21671fa..7854d51 100644
--- a/clang/test/SemaCXX/condition.cpp
+++ b/clang/test/SemaCXX/condition.cpp
@@ -52,3 +52,7 @@
if (test3) // expected-warning {{address of function 'test3' will always evaluate to 'true'}}
(void) 0;
}
+
+void test4(bool (&x)(void)) {
+ while (x);
+}