[cfe-commits] r51900 - in /cfe/trunk: include/clang/Basic/DiagnosticKinds.def lib/Sema/SemaExpr.cpp

Steve Naroff snaroff at apple.com
Tue Jun 3 05:56:36 PDT 2008


Author: snaroff
Date: Tue Jun  3 07:56:35 2008
New Revision: 51900

URL: http://llvm.org/viewvc/llvm-project?rev=51900&view=rev
Log:
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.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=51900&r1=51899&r2=51900&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Tue Jun  3 07:56:35 2008
@@ -922,6 +922,8 @@
      "used type '%0' where arithmetic or pointer type is required")
 DIAG(ext_typecheck_cond_one_void, EXTENSION,
      "C99 forbids conditional expressions with only one void side")
+DIAG(ext_typecheck_cast_nonscalar, EXTENSION,
+     "C99 forbids casting nonscalar to the same type")
 DIAG(err_typecheck_expect_scalar_operand, ERROR,
      "operand of type '%0' where arithmetic or pointer type is required")
 DIAG(err_typecheck_cond_incompatible_operands, ERROR,

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=51900&r1=51899&r2=51900&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Jun  3 07:56:35 2008
@@ -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(), 





More information about the cfe-commits mailing list