Index: lib/Analysis/CFG.cpp =================================================================== --- lib/Analysis/CFG.cpp +++ lib/Analysis/CFG.cpp @@ -3902,7 +3902,20 @@ case CFGElement::AutomaticObjectDtor: { const VarDecl *var = castAs().getVarDecl(); QualType ty = var->getType(); - ty = ty.getNonReferenceType(); + + // FIXME: See CFGBuilder::addLocalScopeForVarDecl. + // + // Lifetime-extending constructs are handled here. This works for a single + // temporary in an initializer expression. + if (ty.getTypePtr()->isReferenceType()) { + if (const Expr *Init = var->getInit()) { + if (const ExprWithCleanups *EWC = dyn_cast(Init)) + Init = EWC->getSubExpr(); + if (isa(Init)) + ty = getReferenceInitTemporaryType(astContext, Init); + } + } + while (const ArrayType *arrayType = astContext.getAsArrayType(ty)) { ty = arrayType->getElementType(); } Index: test/SemaCXX/warn-thread-safety-analysis.cpp =================================================================== --- test/SemaCXX/warn-thread-safety-analysis.cpp +++ test/SemaCXX/warn-thread-safety-analysis.cpp @@ -5160,6 +5160,21 @@ } // end namespace GlobalAcquiredBeforeAfterTest +namespace LifetimeExtensionTest { + +struct Holder { + virtual ~Holder() throw() {} + int i = 0; +}; + +void test() { + // Should not crash. + const auto &value = Holder().i; +} + +} // end namespace LifetimeExtensionTest + + namespace LockableUnions { union LOCKABLE MutexUnion {