aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbramo Bagnara <abramo.bagnara@gmail.com>2010-10-07 21:20:44 +0000
committerAbramo Bagnara <abramo.bagnara@gmail.com>2010-10-07 21:20:44 +0000
commit8c4bfe52e528d6c9810cfb0c59859bca9ddc41f0 (patch)
tree245251a66b648121d4f3029a17aa70aed5c2304d
parent9ff3e66b204602301b779072c20ca8e9c6743759 (diff)
Fixed cast to union with anonymous bitfields.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@115979 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaExpr.cpp3
-rw-r--r--test/Sema/cast-to-union.c3
2 files changed, 4 insertions, 2 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 9a3cb442a7..fec8cb9166 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -3986,7 +3986,8 @@ bool Sema::CheckCastTypes(SourceRange TyR, QualType castType, Expr *&castExpr,
for (Field = RD->field_begin(), FieldEnd = RD->field_end();
Field != FieldEnd; ++Field) {
if (Context.hasSameUnqualifiedType(Field->getType(),
- castExpr->getType())) {
+ castExpr->getType()) &&
+ !Field->isUnnamedBitfield()) {
Diag(TyR.getBegin(), diag::ext_typecheck_cast_to_union)
<< castExpr->getSourceRange();
break;
diff --git a/test/Sema/cast-to-union.c b/test/Sema/cast-to-union.c
index 6f275e8b50..c32964dfc0 100644
--- a/test/Sema/cast-to-union.c
+++ b/test/Sema/cast-to-union.c
@@ -1,11 +1,12 @@
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
-union u { int i; };
+union u { int i; unsigned : 3; };
void f(union u);
void test(int x) {
f((union u)x); // expected-warning {{C99 forbids casts to union type}}
f((union u)&x); // expected-error {{cast to union type from type 'int *' not present in union}}
+ f((union u)2U); // expected-error {{cast to union type from type 'unsigned int' not present in union}}
}
union u w = (union u)2; // expected-warning {{C99 forbids casts to union type}}