]> granicus.if.org Git - clang/commitdiff
casting to void is ok for structs (C99 6.5.4p2), this fixes
authorChris Lattner <sabre@nondot.org>
Mon, 29 Oct 2007 04:26:44 +0000 (04:26 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 29 Oct 2007 04:26:44 +0000 (04:26 +0000)
one bogus error on PR1750.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43436 91177308-0d34-0410-b5e6-96231b3b80d8

Sema/SemaExpr.cpp
test/Sema/cast.c [new file with mode: 0644]

index 40205d335c71e75a0a1e89a3bafbaff512895c19..88a72eb982884ed834c95fd40541981a572796db 100644 (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);
 }
diff --git a/test/Sema/cast.c b/test/Sema/cast.c
new file mode 100644 (file)
index 0000000..14bfe13
--- /dev/null
@@ -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;
+}
+