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
This commit is contained in:
Richard Trieu 2011-12-06 04:48:01 +00:00
parent 5e2192adb5
commit 5f623229ec
2 changed files with 9 additions and 4 deletions

View File

@ -3771,12 +3771,13 @@ void CheckImplicitConversion(Sema &S, Expr *E, QualType T,
}
if (D && !D->isWeak()) {
FunctionDecl* F = cast<FunctionDecl>(D);
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.
}

View File

@ -52,3 +52,7 @@ void test3() {
if (test3) // expected-warning {{address of function 'test3' will always evaluate to 'true'}}
(void) 0;
}
void test4(bool (&x)(void)) {
while (x);
}