forked from OSchip/llvm-project
Fixed cast to union with anonymous bitfields.
llvm-svn: 115979
This commit is contained in:
parent
ae8d67d3bb
commit
5d3e724fc5
|
@ -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;
|
||||
|
|
|
@ -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}}
|
||||
|
|
Loading…
Reference in New Issue