Fix handling of pointers-to-members and comma expressions when
lifetime-extending temporaries in reference bindings.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183089 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/JumpDiagnostics.cpp b/lib/Sema/JumpDiagnostics.cpp
index 5f92cff..8e446f8 100644
--- a/lib/Sema/JumpDiagnostics.cpp
+++ b/lib/Sema/JumpDiagnostics.cpp
@@ -172,14 +172,19 @@
if (EWC)
Init = EWC->getSubExpr();
+ // FIXME: Why are we looking through reference initialization?
+ // This causes us to incorrectly accept invalid code such as:
+ // struct S { int n; };
+ // int f() { goto x; S &&s = S(); x: return x.n; }
const MaterializeTemporaryExpr *M = NULL;
Init = Init->findMaterializedTemporary(M);
+ SmallVector<const Expr *, 2> CommaLHSs;
SmallVector<SubobjectAdjustment, 2> Adjustments;
- Init = Init->skipRValueSubobjectAdjustments(Adjustments);
+ Init = Init->skipRValueSubobjectAdjustments(CommaLHSs, Adjustments);
QualType QT = Init->getType();
- if (QT.isNull())
+ if (QT.isNull() || !CommaLHSs.empty())
return ScopePair(diag::note_protected_by_variable_init, 0);
const Type *T = QT.getTypePtr();