[cfe-commits] r90867 - in /cfe/trunk: lib/Sema/SemaCXXCast.cpp test/SemaObjCXX/cstyle-cast.mm

Douglas Gregor dgregor at apple.com
Tue Dec 8 13:02:06 PST 2009


On Dec 8, 2009, at 11:22 AM, Fariborz Jahanian wrote:

> Author: fjahanian
> Date: Tue Dec  8 13:22:33 2009
> New Revision: 90867
>
> URL: http://llvm.org/viewvc/llvm-project?rev=90867&view=rev
> Log:
> Patch to allow cstyle cast of objective-c pointers in objective-c++
> mode as they are pervasive.
>
>
> Added:
>    cfe/trunk/test/SemaObjCXX/cstyle-cast.mm
> Modified:
>    cfe/trunk/lib/Sema/SemaCXXCast.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaCXXCast.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXCast.cpp?rev=90867&r1=90866&r2=90867&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Sema/SemaCXXCast.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaCXXCast.cpp Tue Dec  8 13:22:33 2009
> @@ -1160,6 +1160,10 @@
>   if (CastTy->isDependentType() || CastExpr->isTypeDependent())
>     return false;
>
> +  // allow c-style cast of objective-c pointers as they are  
> pervasive.
> +  if (CastTy->isObjCObjectPointerType())
> +    return false;
> +

I think this is too permissive. The C path does a bit of checking for  
scalar types in Sema::CheckCastTypes, which makes code like the  
following ill-formed:

   struct X { X(); };

   void f(X x) {
     (id)x;
   }

GCC rejects this code, Clang accepts it.

Also, before exiting this function we need to set CastKind to an  
appropriate value, to describe what kind of cast we're doing. It might  
involve adding new CastKinds to properly capture Objective-C casts.

	- Doug



More information about the cfe-commits mailing list