]> granicus.if.org Git - clang/commitdiff
When we're performing an explicit cast of some sort, don't complain
authorDouglas Gregor <dgregor@apple.com>
Thu, 2 Dec 2010 21:47:04 +0000 (21:47 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 2 Dec 2010 21:47:04 +0000 (21:47 +0000)
about deprecated Objective-C pointer conversions. Plus, make sure to
actually set an appropriate AssignmentAction when performing an
implicit conversion from an InitializationSequence. Fixes regressions
in the GCC DejaGNU testsuite.

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

lib/Sema/SemaExprCXX.cpp
lib/Sema/SemaInit.cpp
test/SemaObjCXX/blocks.mm
test/SemaObjCXX/objc-pointer-conv.mm
test/SemaObjCXX/overload.mm

index f6bfee91eedc965b4216a73eabcefdb3785742ae..fceb542c793c3e53be491912cf44fcdd679a5a1b 100644 (file)
@@ -1732,7 +1732,7 @@ Sema::PerformImplicitConversion(Expr *&From, QualType ToType,
       }    
       else
         assert(0 && "Unknown conversion function kind!");
-      // Whatch out for elipsis conversion.
+      // Watch out for elipsis conversion.
       if (!ICS.UserDefined.EllipsisConversion) {
         if (PerformImplicitConversion(From, BeforeToType, 
                                       ICS.UserDefined.Before, AA_Converting,
@@ -1925,7 +1925,7 @@ Sema::PerformImplicitConversion(Expr *&From, QualType ToType,
     break;
 
   case ICK_Pointer_Conversion: {
-    if (SCS.IncompatibleObjC) {
+    if (SCS.IncompatibleObjC && Action != AA_Casting) {
       // Diagnose incompatible Objective-C conversions
       Diag(From->getSourceRange().getBegin(),
            diag::ext_typecheck_convert_incompatible_pointer)
index 455f7bbba74057e352d71e32ab177152747bfdde..26826aa87b51a56f64a8063269b7e4b07c2369f0 100644 (file)
@@ -3233,6 +3233,8 @@ getAssignmentAction(const InitializedEntity &Entity) {
   switch(Entity.getKind()) {
   case InitializedEntity::EK_Variable:
   case InitializedEntity::EK_New:
+  case InitializedEntity::EK_Exception:
+  case InitializedEntity::EK_Base:
     return Sema::AA_Initializing;
 
   case InitializedEntity::EK_Parameter:
@@ -3245,11 +3247,6 @@ getAssignmentAction(const InitializedEntity &Entity) {
   case InitializedEntity::EK_Result:
     return Sema::AA_Returning;
 
-  case InitializedEntity::EK_Exception:
-  case InitializedEntity::EK_Base:
-    llvm_unreachable("No assignment action for C++-specific initialization");
-    break;
-
   case InitializedEntity::EK_Temporary:
     // FIXME: Can we tell apart casting vs. converting?
     return Sema::AA_Casting;
@@ -3868,7 +3865,8 @@ InitializationSequence::Perform(Sema &S,
       bool IgnoreBaseAccess = Kind.isCStyleOrFunctionalCast();
 
       if (S.PerformImplicitConversion(CurInitExpr, Step->Type, *Step->ICS,
-                                      Sema::AA_Converting, IgnoreBaseAccess))
+                                      getAssignmentAction(Entity),
+                                      IgnoreBaseAccess))
         return ExprError();
         
       CurInit.release();
index 559739a48dce40bbe836e9570483d1c3292aabd0..f595863815117a84c5924879d5261fe9af1c13d1 100644 (file)
@@ -3,12 +3,12 @@
 
 void bar(id(^)(void));
 void foo(id <NSObject>(^objectCreationBlock)(void)) {
-    return bar(objectCreationBlock); // expected-warning{{incompatible pointer types converting 'id<NSObject> (^)()' to type 'id (^)()'}}
+    return bar(objectCreationBlock); // expected-warning{{incompatible pointer types passing 'id<NSObject> (^)()' to parameter of type 'id (^)()'}}
 }
 
 void bar2(id(*)(void));
 void foo2(id <NSObject>(*objectCreationBlock)(void)) {
-    return bar2(objectCreationBlock); // expected-warning{{incompatible pointer types converting 'id<NSObject> (*)()' to type 'id (*)()'}}
+    return bar2(objectCreationBlock); // expected-warning{{incompatible pointer types passing 'id<NSObject> (*)()' to parameter of type 'id (*)()'}}
 }
 
 void bar3(id(*)()); // expected-note{{candidate function}}
index e40dab749c6a2c5736d127cabf5674c727f691d5..209dcfdfd70590ab1f7388e19e697d41682c8fe1 100644 (file)
@@ -42,5 +42,7 @@ void foo(const I *p, I* sel) {
 void accept_derived(DerivedFromI*);
 
 void test_base_to_derived(I* i) {
-  accept_derived(i); // expected-warning{{incompatible pointer types converting 'I *' to type 'DerivedFromI *'}}
+  accept_derived(i); // expected-warning{{incompatible pointer types passing 'I *' to parameter of type 'DerivedFromI *'}}
+  DerivedFromI *di = i; // expected-warning{{incompatible pointer types initializing 'I *' with an expression of type 'DerivedFromI *'}}
+  DerivedFromI *di2 = (DerivedFromI *)i;
 }
index 84aedf6b69a5681172b234d4b9098b4a03a9a2c4..7000e54cfe007ebdd116445477b625e343559d1e 100644 (file)
@@ -52,12 +52,12 @@ void test0(A* a, B* b, id val) {
 }
 
 void test1(A* a) {
-  B* b = a; // expected-warning{{incompatible pointer types converting 'A *' to type 'B *'}}
+  B* b = a; // expected-warning{{incompatible pointer types initializing 'A *' with an expression of type 'B *'}}
   B *c; c = a; // expected-warning{{incompatible pointer types assigning to 'A *' from 'B *'}}
 }
 
 void test2(A** ap) {
-  B** bp = ap; // expected-warning{{incompatible pointer types converting 'A **' to type 'B **'}}
+  B** bp = ap; // expected-warning{{incompatible pointer types initializing 'A **' with an expression of type 'B **'}}
   bp = ap; // expected-warning{{incompatible pointer types assigning to 'A **' from 'B **'}}
 }
 
@@ -101,7 +101,7 @@ objc_exception_functions_t;
 
 void (*_NSExceptionRaiser(void))(NSException *) {
     objc_exception_functions_t exc_funcs;
-    return exc_funcs.throw_exc; // expected-warning{{incompatible pointer types converting 'void (*)(id)' to type 'void (*)(NSException *)'}}
+    return exc_funcs.throw_exc; // expected-warning{{incompatible pointer types returning 'void (*)(id)' from a function with result type 'void (*)(NSException *)'}}
 }
 
 namespace test5 {