[cfe-commits] r43436 - in /cfe/trunk: Sema/SemaExpr.cpp test/Sema/cast.c
Chris Lattner
sabre at nondot.org
Sun Oct 28 21:26:44 PDT 2007
Author: lattner
Date: Sun Oct 28 23:26:44 2007
New Revision: 43436
URL: http://llvm.org/viewvc/llvm-project?rev=43436&view=rev
Log:
casting to void is ok for structs (C99 6.5.4p2), this fixes
one bogus error on PR1750.
Added:
cfe/trunk/test/Sema/cast.c
Modified:
cfe/trunk/Sema/SemaExpr.cpp
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=43436&r1=43435&r2=43436&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Sun Oct 28 23:26:44 2007
@@ -693,14 +693,15 @@
// 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);
}
Added: cfe/trunk/test/Sema/cast.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/cast.c?rev=43436&view=auto
==============================================================================
--- cfe/trunk/test/Sema/cast.c (added)
+++ cfe/trunk/test/Sema/cast.c Sun Oct 28 23:26:44 2007
@@ -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;
+}
+
More information about the cfe-commits
mailing list