[cfe-commits] r90874 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp test/SemaObjCXX/composite-objc-pointertype.mm

Douglas Gregor dgregor at apple.com
Tue Dec 8 13:10:57 PST 2009


On Dec 8, 2009, at 12:04 PM, Fariborz Jahanian wrote:

> Author: fjahanian
> Date: Tue Dec  8 14:04:24 2009
> New Revision: 90874
>
> URL: http://llvm.org/viewvc/llvm-project?rev=90874&view=rev
> Log:
> Patch to allow matching 0 with an objective-c pointer type
> in objective-c++ mode. Fixes radar 7443165
>
>
> Added:
>    cfe/trunk/test/SemaObjCXX/composite-objc-pointertype.mm
> Modified:
>    cfe/trunk/lib/Sema/SemaExprCXX.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=90874&r1=90873&r2=90874&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Tue Dec  8 14:04:24 2009
> @@ -1881,8 +1881,8 @@
>   assert(getLangOptions().CPlusPlus && "This function assumes C++");
>   QualType T1 = E1->getType(), T2 = E2->getType();
>
> -  if (!T1->isPointerType() && !T1->isMemberPointerType() &&
> -      !T2->isPointerType() && !T2->isMemberPointerType())
> +  if (!T1->isAnyPointerType() && !T1->isMemberPointerType() &&
> +      !T2->isAnyPointerType() && !T2->isMemberPointerType())
>    return QualType();

This will work for NULL and any Objective-C pointer type, but there  
are larger issues in this function for Objective-C since nothing  
beyond the null-pointer-constant checks will work. For example, here's  
a case where we should be able to find the composite type between two  
interface pointers:

   @interface C1 { } @end
   @interface C2 : C1 { } @end

   void f(int Cond, C1 *c1, const C2 *c2) {
     (void)(Cond? c1 : c2);
   }

This compiles with GCC (Objective-C and Objective-C++ mode) and with  
Clang in Objective-C mode, but with Clang Objective-C++ we get

t.mm:5:14: error: incompatible operand types ('C1 *' and 'C2 const *')
   (void)(Cond? c1 : c2);
              ^ ~~   ~~
1 diagnostic generated.

	- Doug



More information about the cfe-commits mailing list