Allow for a GCC cast extension.
Fixes part of <rdar://problem/5980829> clang on xcode: used type 'NSRange' where arithmetic or pointer type is required.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51900 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 626e829..c978aca 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -845,9 +845,16 @@
// C99 6.5.4p2: the cast type needs to be void or scalar and the expression
// type needs to be scalar.
if (!castType->isVoidType()) { // Cast to void allows any expr type.
- if (!castType->isScalarType() && !castType->isVectorType())
- return Diag(LParenLoc, diag::err_typecheck_cond_expect_scalar,
- castType.getAsString(), SourceRange(LParenLoc, RParenLoc));
+ if (!castType->isScalarType() && !castType->isVectorType()) {
+ // GCC struct/union extension.
+ if (castType == castExpr->getType() &&
+ castType->isStructureType() || castType->isUnionType())
+ return Diag(LParenLoc, diag::ext_typecheck_cast_nonscalar,
+ SourceRange(LParenLoc, RParenLoc));
+ else
+ return Diag(LParenLoc, diag::err_typecheck_cond_expect_scalar,
+ castType.getAsString(), SourceRange(LParenLoc, RParenLoc));
+ }
if (!castExpr->getType()->isScalarType() &&
!castExpr->getType()->isVectorType())
return Diag(castExpr->getLocStart(),