Do not crash when static analysis encounters a FunctionDecl that has a delayed template parse of its body.

llvm-svn: 245616
This commit is contained in:
Aaron Ballman 2015-08-20 21:27:35 +00:00
parent d46da9ac31
commit 6569387327
2 changed files with 13 additions and 2 deletions

View File

@ -588,8 +588,8 @@ AnalysisConsumer::getModeForDecl(Decl *D, AnalysisMode Mode) {
// - Header files: run non-path-sensitive checks only. // - Header files: run non-path-sensitive checks only.
// - System headers: don't run any checks. // - System headers: don't run any checks.
SourceManager &SM = Ctx->getSourceManager(); SourceManager &SM = Ctx->getSourceManager();
SourceLocation SL = D->hasBody() ? D->getBody()->getLocStart() const Stmt *Body = D->getBody();
: D->getLocation(); SourceLocation SL = Body ? Body->getLocStart() : D->getLocation();
SL = SM.getExpansionLoc(SL); SL = SM.getExpansionLoc(SL);
if (!Opts->AnalyzeAll && !SM.isWrittenInMainFile(SL)) { if (!Opts->AnalyzeAll && !SM.isWrittenInMainFile(SL)) {

View File

@ -0,0 +1,11 @@
// RUN: %clang_cc1 -analyze -analyzer-checker=core -std=c++11 -fdelayed-template-parsing -verify %s
// expected-no-diagnostics
template <class T> struct remove_reference {typedef T type;};
template <class T> struct remove_reference<T&> {typedef T type;};
template <class T> struct remove_reference<T&&> {typedef T type;};
template <typename T>
typename remove_reference<T>::type&& move(T&& arg) { // this used to crash
return static_cast<typename remove_reference<T>::type&&>(arg);
}