casting to void is ok for structs (C99 6.5.4p2), this fixes

one bogus error on PR1750.

llvm-svn: 43436
This commit is contained in:
Chris Lattner 2007-10-29 04:26:44 +00:00
parent cc779571b8
commit 3bc4d20862
2 changed files with 17 additions and 8 deletions

View File

@ -693,14 +693,15 @@ ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
// C99 6.5.4p2: the cast type needs to be void or scalar and the expression
// type needs to be scalar.
if (!castType->isScalarType() && !castType->isVoidType()) {
return Diag(LParenLoc, diag::err_typecheck_cond_expect_scalar,
castType.getAsString(), SourceRange(LParenLoc, RParenLoc));
}
if (!castExpr->getType()->isScalarType()) {
return Diag(castExpr->getLocStart(),
diag::err_typecheck_expect_scalar_operand,
castExpr->getType().getAsString(), castExpr->getSourceRange());
if (!castType->isVoidType()) { // Cast to void allows any expr type.
if (!castType->isScalarType())
return Diag(LParenLoc, diag::err_typecheck_cond_expect_scalar,
castType.getAsString(), SourceRange(LParenLoc, RParenLoc));
if (!castExpr->getType()->isScalarType()) {
return Diag(castExpr->getLocStart(),
diag::err_typecheck_expect_scalar_operand,
castExpr->getType().getAsString(),castExpr->getSourceRange());
}
}
return new CastExpr(castType, castExpr, LParenLoc);
}

8
clang/test/Sema/cast.c Normal file
View File

@ -0,0 +1,8 @@
// RUN: clang -fsyntax-only %s -verify
typedef struct { unsigned long bits[(((1) + (64) - 1) / (64))]; } cpumask_t;
cpumask_t x;
void foo() {
(void)x;
}