case CFGElement::AutomaticObjectDtor: {
const VarDecl *var = castAs<CFGAutomaticObjDtor>().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->isReferenceType()) {
+ if (const Expr *Init = var->getInit()) {
+ ty = getReferenceInitTemporaryType(astContext, Init);
+ }
+ }
+
while (const ArrayType *arrayType = astContext.getAsArrayType(ty)) {
ty = arrayType->getElementType();
}
} // end namespace GlobalAcquiredBeforeAfterTest
+namespace LifetimeExtensionText {
+
+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 {