When rebuilding a MemberExpr that refers to an anonymous union, be
sure to perform derived-to-base conversions on the base
expression. Fixes PR5868. Proper testcase is coming soon.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92139 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h
index cf424aa..61b57e7 100644
--- a/lib/Sema/TreeTransform.h
+++ b/lib/Sema/TreeTransform.h
@@ -956,8 +956,11 @@
       // We have a reference to an unnamed field.
       assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
 
+      Expr *BaseExpr = Base.takeAs<Expr>();
+      if (getSema().PerformObjectMemberConversion(BaseExpr, Member))
+        return getSema().ExprError();
       MemberExpr *ME =
-        new (getSema().Context) MemberExpr(Base.takeAs<Expr>(), isArrow,
+        new (getSema().Context) MemberExpr(BaseExpr, isArrow,
                                            Member, MemberLoc,
                                            cast<FieldDecl>(Member)->getType());
       return getSema().Owned(ME);