"invalid application of 'sizeof' to an incomplete type %0")
DIAG(err_alignof_incomplete_type, ERROR,
"invalid application of '__alignof' to an incomplete type %0")
-DIAG(err_alignof_bitfield, ERROR,
- "invalid application of '__alignof' to bitfield")
+DIAG(err_sizeof_alignof_bitfield, ERROR,
+ "invalid application of '%select{sizeof|__alignof}0' to bitfield")
DIAG(err_offsetof_record_type, ERROR,
"offsetof requires struct, union, or class type, %0 invalid")
DIAG(err_offsetof_array_type, ERROR,
if (MemberExpr *ME = dyn_cast<MemberExpr>(E)) {
if (FieldDecl *FD = dyn_cast<FieldDecl>(ME->getMemberDecl())) {
if (FD->isBitField()) {
- Diag(OpLoc, diag::err_alignof_bitfield) << ExprRange;
+ Diag(OpLoc, diag::err_sizeof_alignof_bitfield) << 1 << ExprRange;
return true;
}
// Other fields are ok.
// Verify that the operand is valid.
bool isInvalid;
- if (isSizeof)
- isInvalid = CheckSizeOfAlignOfOperand(ArgTy, OpLoc, Range, true);
- else
+ if (!isSizeof) {
isInvalid = CheckAlignOfExpr(ArgEx, OpLoc, Range);
+ } else if (ArgEx->isBitField()) { // C99 6.5.3.4p1.
+ Diag(OpLoc, diag::err_sizeof_alignof_bitfield) << 0;
+ isInvalid = true;
+ } else {
+ isInvalid = CheckSizeOfAlignOfOperand(ArgTy, OpLoc, Range, true);
+ }
if (isInvalid) {
DeleteExpr(ArgEx);
// PR3386
struct f { int x : 4; float y[]; };
int test9(struct f *P) {
- return __alignof(P->x) + // expected-error {{invalid application of '__alignof' to bitfield}} expected-warning {{extension used}}
- __alignof(P->y); // ok. expected-warning {{extension used}}
+ int R;
+ R = __alignof(P->x); // expected-error {{invalid application of '__alignof' to bitfield}} expected-warning {{extension used}}
+ R = __alignof(P->y); // ok. expected-warning {{extension used}}
+ R = sizeof(P->x); // expected-error {{invalid application of 'sizeof' to bitfield}}
+ return R;
}