summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaCast.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2017-08-15 21:42:47 +0000
committerJohn McCall <rjmccall@apple.com>2017-08-15 21:42:47 +0000
commitf1ef796fd9f1fb4412698acffb649d5fa1d55b18 (patch)
tree809b07139f2f4c711728c5bfac5ae8dd475f96de /clang/lib/Sema/SemaCast.cpp
parent477b123ead3f9044fa98d2173b69e57a39ec3823 (diff)
downloadbcm5719-llvm-f1ef796fd9f1fb4412698acffb649d5fa1d55b18.tar.gz
bcm5719-llvm-f1ef796fd9f1fb4412698acffb649d5fa1d55b18.zip
Allow the target field of a CK_ToUnion to be more easily recovered.
llvm-svn: 310963
Diffstat (limited to 'clang/lib/Sema/SemaCast.cpp')
-rw-r--r--clang/lib/Sema/SemaCast.cpp19
1 files changed, 6 insertions, 13 deletions
diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index d603101c3fd..ad6348685b6 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -2458,24 +2458,17 @@ void CastOperation::CheckCStyleCast() {
// GCC's cast to union extension.
if (DestRecordTy && DestRecordTy->getDecl()->isUnion()) {
RecordDecl *RD = DestRecordTy->getDecl();
- RecordDecl::field_iterator Field, FieldEnd;
- for (Field = RD->field_begin(), FieldEnd = RD->field_end();
- Field != FieldEnd; ++Field) {
- if (Self.Context.hasSameUnqualifiedType(Field->getType(), SrcType) &&
- !Field->isUnnamedBitfield()) {
- Self.Diag(OpRange.getBegin(), diag::ext_typecheck_cast_to_union)
- << SrcExpr.get()->getSourceRange();
- break;
- }
- }
- if (Field == FieldEnd) {
+ if (CastExpr::getTargetFieldForToUnionCast(RD, SrcType)) {
+ Self.Diag(OpRange.getBegin(), diag::ext_typecheck_cast_to_union)
+ << SrcExpr.get()->getSourceRange();
+ Kind = CK_ToUnion;
+ return;
+ } else {
Self.Diag(OpRange.getBegin(), diag::err_typecheck_cast_to_union_no_type)
<< SrcType << SrcExpr.get()->getSourceRange();
SrcExpr = ExprError();
return;
}
- Kind = CK_ToUnion;
- return;
}
// OpenCL v2.0 s6.13.10 - Allow casts from '0' to event_t type.
OpenPOWER on IntegriCloud