[cfe-commits] r115979 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/Sema/cast-to-union.c
Abramo Bagnara
abramo.bagnara at gmail.com
Thu Oct 7 14:20:44 PDT 2010
Author: abramo
Date: Thu Oct 7 16:20:44 2010
New Revision: 115979
URL: http://llvm.org/viewvc/llvm-project?rev=115979&view=rev
Log:
Fixed cast to union with anonymous bitfields.
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/cast-to-union.c
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=115979&r1=115978&r2=115979&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Oct 7 16:20:44 2010
@@ -3986,7 +3986,8 @@
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;
Modified: cfe/trunk/test/Sema/cast-to-union.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/cast-to-union.c?rev=115979&r1=115978&r2=115979&view=diff
==============================================================================
--- cfe/trunk/test/Sema/cast-to-union.c (original)
+++ cfe/trunk/test/Sema/cast-to-union.c Thu Oct 7 16:20:44 2010
@@ -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}}
More information about the cfe-commits
mailing list