aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Sema/SemaExpr.cpp17
-rw-r--r--test/Sema/cast.c8
2 files changed, 17 insertions, 8 deletions
diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp
index 40205d335c..88a72eb982 100644
--- a/Sema/SemaExpr.cpp
+++ b/Sema/SemaExpr.cpp
@@ -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);
}
diff --git a/test/Sema/cast.c b/test/Sema/cast.c
new file mode 100644
index 0000000000..14bfe138f3
--- /dev/null
+++ b/test/Sema/cast.c
@@ -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;
+}
+