diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 712dfaab34a7e12c37439cad5bf87b841fdb54be..7954df7805bea70a8b2d7733627e05ec15640369 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,21 @@
+2010-09-27  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+	Merge from 'apple/trunk' branch on FSF servers.  Removed small
+	change in build_conditional_expr that had been added when fixing
+	PR objc/27377 and which did the same check in a less complete way.
+
+	2005-12-15  Fariborz Jahanian <fjahanian@apple.com>
+
+	Radar 4229905
+	* c-typeck.c (build_conditional_expr): Call objc_have_common_type when
+	looking for objective-c common pointer types.
+	
+	2005-06-22  Ziemowit Laski  <zlaski@apple.com>
+
+	Radar 4154928
+	* c-typeck.c (build_conditional_expr): For two ObjC pointer types,
+	use their ObjC common type.
+
 2010-09-27  Richard Guenther  <rguenther@suse.de>
 
 	* dbxout.c (dbxout_symbol): Use DECL_FILE_SCOPE_P.
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 7d3e3dddf7cc080ecc3dbc1641c8edacdad9c308..25603f90e2523b845092334268551c85470b837a 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,19 @@
+2010-09-27  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+	Merge from 'apple/trunk' branch on FSF servers.	
+
+	2005-12-15  Fariborz Jahanian <fjahanian@apple.com>
+
+	Radar 4229905	
+	* c-common.h (objc_have_common_type): New declaration.
+	* stub-objc.c (objc_have_common_type): New stub.
+
+	2005-06-22  Ziemowit Laski  <zlaski@apple.com>
+
+	Radar 4154928
+	* c-common.h (objc_common_type): New prototype.
+	* stub-objc.c (objc_common_type): New stub.	
+
 2010-09-24  Jan Hubicka  <jh@suse.cz>
 
 	* c-common.c (handle_leaf_attribute): New function.
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index de72c192edfcc3a9bfe87ccd154606114ed250ae..296f69058e903baeb097a9024df1da59d7e3889a 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -941,7 +941,9 @@ extern tree objc_is_class_name (tree);
 extern tree objc_is_object_ptr (tree);
 extern void objc_check_decl (tree);
 extern int objc_is_reserved_word (tree);
+extern tree objc_common_type (tree, tree);
 extern bool objc_compare_types (tree, tree, int, tree);
+extern bool objc_have_common_type (tree, tree, int, tree);
 extern void objc_volatilize_decl (tree);
 extern bool objc_type_quals_match (tree, tree);
 extern tree objc_rewrite_function_call (tree, tree);
diff --git a/gcc/c-family/stub-objc.c b/gcc/c-family/stub-objc.c
index 0ce1feffb41a570c96ff293bf4e1100178aa12d4..0384b486fcee9a67926b7300d8600259faa520dc 100644
--- a/gcc/c-family/stub-objc.c
+++ b/gcc/c-family/stub-objc.c
@@ -62,6 +62,12 @@ objc_is_reserved_word (tree ARG_UNUSED (ident))
   return 0;
 }
 
+tree
+objc_common_type (tree ARG_UNUSED (type1), tree ARG_UNUSED (type2))
+{
+  return 0;
+}
+
 bool
 objc_compare_types (tree ARG_UNUSED (ltyp), tree ARG_UNUSED (rtyp),
 		    int ARG_UNUSED (argno), tree ARG_UNUSED (callee))
@@ -69,6 +75,13 @@ objc_compare_types (tree ARG_UNUSED (ltyp), tree ARG_UNUSED (rtyp),
   return false;
 }
 
+bool
+objc_have_common_type (tree ARG_UNUSED (ltyp), tree ARG_UNUSED (rtyp),
+		       int ARG_UNUSED (argno), tree ARG_UNUSED (callee))
+{
+  return false;
+}
+
 void
 objc_volatilize_decl (tree ARG_UNUSED (decl))
 {
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 065e9b802c76edadb4a4fa4fd52763aa45ab15f5..e20c234006b3c2acf5042836de7a237dc9bc5b85 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -4051,7 +4051,6 @@ build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp,
   bool int_const, op1_int_operands, op2_int_operands, int_operands;
   bool ifexp_int_operands;
   tree ret;
-  bool objc_ok;
 
   op1_int_operands = EXPR_INT_CONST_OPERANDS (orig_op1);
   if (op1_int_operands)
@@ -4088,8 +4087,6 @@ build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp,
       return error_mark_node;
     }
 
-  objc_ok = objc_compare_types (type1, type2, -3, NULL_TREE);
-
   if ((TREE_CODE (op1) == EXCESS_PRECISION_EXPR
        || TREE_CODE (op2) == EXCESS_PRECISION_EXPR)
       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
@@ -4255,13 +4252,15 @@ build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp,
 	  result_type = build_pointer_type (qualify_type (TREE_TYPE (type2),
 							  TREE_TYPE (type1)));
 	}
+      /* Objective-C pointer comparisons are a bit more lenient.  */
+      else if (objc_have_common_type (type1, type2, -3, NULL_TREE))
+	result_type = objc_common_type (type1, type2);
       else
 	{
 	  int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
 
-	  if (!objc_ok)
-	    pedwarn (colon_loc, 0,
-		     "pointer type mismatch in conditional expression");
+	  pedwarn (colon_loc, 0,
+		   "pointer type mismatch in conditional expression");
 	  result_type = build_pointer_type
 			  (build_qualified_type (void_type_node, qual));
 	}
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 4b6eb74fe8db227bbb97d25e27288ff5f0f2fa2a..f60080057bc7c588d60fff3e449ca88a94d020f8 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,21 @@
+2010-09-27  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+	Merge from apple/trunk branch on FSF servers:
+	
+	2005-12-15  Fariborz Jahanian <fjahanian@apple.com>
+
+	Radar 4229905
+	* typeck.c (composite_pointer_type): Call objc_have_common_type
+	when comparing two objective-c pointer types.
+
+	2005-06-22  Ziemowit Laski  <zlaski@apple.com>
+
+	Radar 4154928
+	* call.c (standard_conversion): Allow for a pointer conversion
+	between any two ObjC pointer types.
+	* typeck.c (composite_pointer_type): Determine common type
+	for two ObjC pointer types.
+	
 2010-09-24  Jan Hubicka  <jh@suse.cz>
 
 	* decl.c (finish_function): Use decl_replaceable_p
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 89ab75723f49a477dd5d8a1f6b97857268ba20d4..c3a579929c3c04f95b37e4e7183c3a44dac6d9e4 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -900,6 +900,11 @@ standard_conversion (tree to, tree from, tree expr, bool c_cast_p,
       else if (expr && string_conv_p (to, expr, 0))
 	/* converting from string constant to char *.  */
 	conv = build_conv (ck_qual, to, conv);
+      /* Allow conversions among compatible ObjC pointer types (base
+	 conversions have been already handled above).  */
+      else if (c_dialect_objc ()
+	       && objc_compare_types (to, from, -4, NULL_TREE))
+	conv = build_conv (ck_ptr, to, conv);
       else if (ptr_reasonably_similar (to_pointee, from_pointee))
 	{
 	  conv = build_conv (ck_ptr, to, conv);
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 019c51eed856dd4f4e1cdc2baeb71560e85b31d9..9959e409f538814e787c28173c52b25f102d5cf0 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -632,8 +632,8 @@ composite_pointer_type (tree t1, tree t2, tree arg1, tree arg2,
   if (c_dialect_objc () && TREE_CODE (t1) == POINTER_TYPE
       && TREE_CODE (t2) == POINTER_TYPE)
     {
-      if (objc_compare_types (t1, t2, -3, NULL_TREE))
-	return t1;
+      if (objc_have_common_type (t1, t2, -3, NULL_TREE))
+	return objc_common_type (t1, t2);
     }
 
   /* [expr.eq] permits the application of a pointer conversion to
diff --git a/gcc/objc/ChangeLog b/gcc/objc/ChangeLog
index 9a2e46b96ab1d782de837d1ad79e2f4b9e7dec6a..8e70e208bcda04abfca256d7ff3070788cba481e 100644
--- a/gcc/objc/ChangeLog
+++ b/gcc/objc/ChangeLog
@@ -1,3 +1,17 @@
+2010-09-27  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+	Merge from 'apple/trunk' branch on FSF servers.
+
+	2005-12-15  Fariborz Jahanian <fjahanian@apple.com>
+
+	Radar 4229905
+	* objc-act.c (objc_have_common_types): New function.
+	
+	2005-06-22  Ziemowit Laski  <zlaski@apple.com>
+
+	Radar 4154928
+	* objc-act.c (objc_common_type): New function.
+	
 2010-09-27  Richard Guenther  <rguenther@suse.de>
 
 	* objc-act.c (objc_get_class_reference): Use CP_TYPE_CONTEXT.
diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c
index e4483da7adb4a94c70ee059d9597748449f2f779..5d76596479c148c9dbdcd81f0d5d9585f6003cb7 100644
--- a/gcc/objc/objc-act.c
+++ b/gcc/objc/objc-act.c
@@ -1100,6 +1100,35 @@ objc_compare_protocols (tree lcls, tree ltyp, tree rcls, tree rtyp, bool warn)
   return have_lproto || (rcls != NULL_TREE);
 }
 
+/* Given two types TYPE1 and TYPE2, return their least common ancestor.
+   Both TYPE1 and TYPE2 must be pointers, and already determined to be
+   compatible by objc_compare_types() below.  */
+
+tree
+objc_common_type (tree type1, tree type2)
+{
+  tree inner1 = TREE_TYPE (type1), inner2 = TREE_TYPE (type2);
+
+  while (POINTER_TYPE_P (inner1))
+    {
+      inner1 = TREE_TYPE (inner1);
+      inner2 = TREE_TYPE (inner2);
+    }
+
+  /* If one type is derived from another, return the base type.  */
+  if (DERIVED_FROM_P (inner1, inner2))
+    return type1;
+  else if (DERIVED_FROM_P (inner2, inner1))
+    return type2;
+
+  /* If both types are 'Class', return 'Class'.  */
+  if (objc_is_class_id (inner1) && objc_is_class_id (inner2))
+    return objc_class_type;
+
+  /* Otherwise, return 'id'.  */
+  return objc_object_type;
+}
+
 /* Determine if it is permissible to assign (if ARGNO is greater than -3)
    an instance of RTYP to an instance of LTYP or to compare the two
    (if ARGNO is equal to -3), per ObjC type system rules.  Before
@@ -1273,6 +1302,28 @@ objc_compare_types (tree ltyp, tree rtyp, int argno, tree callee)
   return true;
 }
 
+/* This routine is similar to objc_compare_types except that function-pointers are
+   excluded. This is because, caller assumes that common types are of (id, Object*)
+   variety and calls objc_common_type to obtain a common type. There is no commonolty
+   between two function-pointers in this regard. */
+
+bool 
+objc_have_common_type (tree ltyp, tree rtyp, int argno, tree callee)
+{
+  if (objc_compare_types (ltyp, rtyp, argno, callee))
+    {
+      /* exclude function-pointer types. */
+      do
+        {
+          ltyp = TREE_TYPE (ltyp);  /* Remove indirections.  */
+          rtyp = TREE_TYPE (rtyp);
+        }
+      while (POINTER_TYPE_P (ltyp) && POINTER_TYPE_P (rtyp));
+      return !(TREE_CODE (ltyp) == FUNCTION_TYPE && TREE_CODE (rtyp) == FUNCTION_TYPE);
+    }
+  return false;
+}
+
 /* Check if LTYP and RTYP have the same type qualifiers.  If either type
    lives in the volatilized hash table, ignore the 'volatile' bit when
    making the comparison.  */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index dc21e6456d4dc6c3793bc019be2017db50be5365..24f0c17c4bdfc75f95281bb7014712430b93a79d 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,19 @@
+2010-09-27  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+	Merge from 'apple/trunk' branch on FSF servers.  Renamed
+	const-str-12.m to constr-str-12b.m to avoid conflicts.
+	
+	2005-12-15  Fariborz Jahanian <fjahanian@apple.com>
+
+	Radar 4229905
+	* obj-c++.dg/warn5.mm: New
+	
+	2005-06-22  Ziemowit Laski  <zlaski@apple.com>
+
+	Radar 4154928
+	* obj-c++.dg/const-str-12.mm: New.
+	* objc.dg/const-str-12.m: New.
+
 2010-09-27  Tobias Burnus  <burnus@net-b.de>
 
 	PR fortran/40569
diff --git a/gcc/testsuite/obj-c++.dg/const-str-12.mm b/gcc/testsuite/obj-c++.dg/const-str-12.mm
new file mode 100644
index 0000000000000000000000000000000000000000..d6bb1bead2156062d5a2b7a2c7760f9144786d18
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/const-str-12.mm
@@ -0,0 +1,26 @@
+/* Test if ObjC types play nice in conditional expressions.  */
+/* Author: Ziemowit Laski  */
+
+/* { dg-options "-fconstant-string-class=Foo" } */
+/* { dg-do compile } */
+
+#include "../objc-obj-c++-shared/Object1.h"
+
+@interface Foo: Object {
+  char *cString;
+  unsigned int len;
+}
++ (id)description;
+@end
+
+@interface Bar: Object
++ (Foo *) getString: (int) which;
+@end
+
+struct objc_class _FooClassReference;
+
+@implementation Bar
++ (Foo *) getString: (int) which {
+  return which? [Foo description]: @"Hello";
+}
+@end
diff --git a/gcc/testsuite/obj-c++.dg/warn5.mm b/gcc/testsuite/obj-c++.dg/warn5.mm
new file mode 100644
index 0000000000000000000000000000000000000000..b46daed77fdf2e61a96d9bca53177967873e2b78
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/warn5.mm
@@ -0,0 +1,25 @@
+/* Check to make sure that a c++ program compiled in objective-c++ mode
+   has no trace of meta-data specific diagnosis coming out of compiling it.
+   This is replicate of warn5.C.
+*/
+// { dg-do assemble  }
+// { dg-options "-Wpointer-arith" }
+
+double X(const double x) { return x; }
+double Y() { return 1.0; }
+double Z() { return 2.0; }
+
+struct A {
+  void bar() { }
+  void foo() { }
+};
+
+typedef void (A::*pmf)();
+
+static int mememe = &A::foo - &A::bar;  // { dg-warning "" } 
+pmf b = &A::foo-1;      // { dg-warning "" } 
+
+int main() {
+    double y;
+    y=X(Y-Z);   // { dg-warning "" } 
+}
diff --git a/gcc/testsuite/objc.dg/const-str-12b.m b/gcc/testsuite/objc.dg/const-str-12b.m
new file mode 100644
index 0000000000000000000000000000000000000000..d6bb1bead2156062d5a2b7a2c7760f9144786d18
--- /dev/null
+++ b/gcc/testsuite/objc.dg/const-str-12b.m
@@ -0,0 +1,26 @@
+/* Test if ObjC types play nice in conditional expressions.  */
+/* Author: Ziemowit Laski  */
+
+/* { dg-options "-fconstant-string-class=Foo" } */
+/* { dg-do compile } */
+
+#include "../objc-obj-c++-shared/Object1.h"
+
+@interface Foo: Object {
+  char *cString;
+  unsigned int len;
+}
++ (id)description;
+@end
+
+@interface Bar: Object
++ (Foo *) getString: (int) which;
+@end
+
+struct objc_class _FooClassReference;
+
+@implementation Bar
++ (Foo *) getString: (int) which {
+  return which? [Foo description]: @"Hello";
+}
+@end