diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index d118f05ba5b8c5f456436d629fae3e87070559bc..c33d57b545747aa2b54656de13174755376441f0 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2004-03-18  Mark Mitchell  <mark@codesourcery.com>
+
+	* c-common.c (pointer_int_sum): Do not complain about using
+	pointers to pointers-to-members.
+
 2004-03-18  Kazu Hirata  <kazu@cs.umass.edu>
 
 	* system.h (MD_ASM_CLOBBERS): Move to "Old target macros that
diff --git a/gcc/c-common.c b/gcc/c-common.c
index 057ebeeeaf5e838506748bd5b11c236bd057366e..49c9ccf613cd31c4f5728b5f03667a6ced411bb8 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -2484,12 +2484,6 @@ pointer_int_sum (enum tree_code resultcode, tree ptrop, tree intop)
 	pedwarn ("pointer to member function used in arithmetic");
       size_exp = integer_one_node;
     }
-  else if (TREE_CODE (TREE_TYPE (result_type)) == OFFSET_TYPE)
-    {
-      if (pedantic || warn_pointer_arith)
-	pedwarn ("pointer to a member used in arithmetic");
-      size_exp = integer_one_node;
-    }
   else
     size_exp = size_in_bytes (TREE_TYPE (result_type));
 
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 00e506659b5f9eda9857337ddf2189cad253f4e0..1052abed8af927bb8e93fefeb42b0416f8649d44 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,17 @@
+2004-03-18  Mark Mitchell  <mark@codesourcery.com>
+
+	* call.c (build_conditional_expr): Do not call force_rvalue for
+	operands of void_type when the conditional expression itself has
+	void type.
+	* name-lookup.c (pushdecl): Don't consider a declaration of a
+	function named "main" to be an overload of a type named "main".
+	* parser.c (cp_parser_template_name): Perform name lookup when the
+	template name is proceeded by "template" if the qualifying scope
+	is non-dependent.
+	* typeck.c (composite_pointer_type_r): Correctly handle
+	pointer-to-member types.
+	(build_const_cast): Likewise.
+
 2004-03-18  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>
 
 	* cp-tree.def (TEMPLATE_TYPE_PARM, TYPEOF_TYPE): Update comments.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 62182f3950ceee74737a90497a78dc42def09103..7a3039bd3b81c8e1ae3d9807c30cb79d98edced8 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -3178,18 +3178,24 @@ build_conditional_expr (tree arg1, tree arg2, tree arg3)
 	   type of the other and is an rvalue.
 
 	 --Both the second and the third operands have type void; the
-	   result is of type void and is an rvalue.  */
+	   result is of type void and is an rvalue.  
+
+         We must avoid calling force_rvalue for expressions of type
+	 "void" because it will complain that their value is being
+	 used.   */
       if (TREE_CODE (arg2) == THROW_EXPR 
 	  && TREE_CODE (arg3) != THROW_EXPR)
 	{
-	  arg3 = force_rvalue (arg3);
+	  if (!VOID_TYPE_P (arg3_type))
+	    arg3 = force_rvalue (arg3);
 	  arg3_type = TREE_TYPE (arg3);
 	  result_type = arg3_type;
 	}
       else if (TREE_CODE (arg2) != THROW_EXPR 
 	       && TREE_CODE (arg3) == THROW_EXPR)
 	{
-	  arg2 = force_rvalue (arg2);
+	  if (!VOID_TYPE_P (arg2_type))
+	    arg2 = force_rvalue (arg2);
 	  arg2_type = TREE_TYPE (arg2);
 	  result_type = arg2_type;
 	}
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index ce101de168c4ffe559d9c7812988a355bf1da9ce..15896821282d28f4484bb47ac4743dae59453ee7 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -706,7 +706,7 @@ pushdecl (tree x)
 
 		  POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, t);
 		}
-	      else if (DECL_MAIN_P (x))
+	      else if (DECL_MAIN_P (x) && TREE_CODE (t) == FUNCTION_DECL)
 		{
 		  /* A redeclaration of main, but not a duplicate of the
 		     previous one.
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index db4025251f4d779874ba8cc6ad227c3901eb861a..0dc63cd8d27885d2cfd3278933a0212453fc586a 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -8203,7 +8203,15 @@ cp_parser_template_name (cp_parser* parser,
 	    *is_identifier = true;
 	  return identifier;
 	}
-      if (template_keyword_p)
+
+      /* If the "template" keyword is present, then there is generally
+	 no point in doing name-lookup, so we just return IDENTIFIER.
+	 But, if the qualifying scope is non-dependent then we can
+	 (and must) do name-lookup normally.  */
+      if (template_keyword_p
+	  && (!parser->scope
+	      || (TYPE_P (parser->scope) 
+		  && dependent_type_p (parser->scope))))
 	return identifier;
     }
 
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 10103c8aecbb6591abc72015412988afd9e0fb7d..e353d3f57aca545d1f001a3ea79c56790b6efdb4 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -443,7 +443,6 @@ composite_pointer_type_r (tree t1, tree t2, const char* location)
   result_type = cp_build_qualified_type (result_type,
 					 (cp_type_quals (pointee1)
 					  | cp_type_quals (pointee2)));
-  result_type = build_pointer_type (result_type);
   /* If the original types were pointers to members, so is the
      result.  */
   if (TYPE_PTR_TO_MEMBER_P (t1))
@@ -456,6 +455,8 @@ composite_pointer_type_r (tree t1, tree t2, const char* location)
       result_type = build_ptrmem_type (TYPE_PTRMEM_CLASS_TYPE (t1),
 				       result_type);
     }
+  else
+    result_type = build_pointer_type (result_type);
 
   /* Merge the attributes.  */
   attributes = (*targetm.merge_type_attributes) (t1, t2);
@@ -4726,7 +4727,7 @@ build_const_cast (tree type, tree expr)
       return t;
     }
 
-  if (!POINTER_TYPE_P (type))
+  if (!POINTER_TYPE_P (type) && !TYPE_PTRMEM_P (type))
     error ("invalid use of const_cast with type `%T', which is not a pointer, reference, nor a pointer-to-data-member type", type);
   else if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
     {
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index b7ff475b02da9ba271b8db4fdc87a4fbd2b573fe..be760c89c87ca21d3bd9c54c9dba2ef79f65b37c 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,12 @@
+2004-03-18  Mark Mitchell  <mark@codesourcery.com>
+
+	* g++.dg/expr/cond5.C: New test.
+	* g++.dg/expr/constcast1.C: Likewise.
+	* g++.dg/expr/ptrmem2.C: Likewise.
+	* g++.dg/expr/ptrmem3.C: Likewise.
+	* g++.dg/lookup/main1.C: Likewise.
+	* g++.dg/template/lookup6.C: Likewise.
+
 2004-03-18  Mark Mitchell  <mark@codesourcery.com>
 
 	* gcc.dg/local1.c: New test.
diff --git a/gcc/testsuite/g++.dg/lookup/main1.C b/gcc/testsuite/g++.dg/lookup/main1.C
new file mode 100644
index 0000000000000000000000000000000000000000..1de834235a6dfdc38c2db4eda870512395526e48
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lookup/main1.C
@@ -0,0 +1,3 @@
+struct main {};
+
+int main () {}
diff --git a/gcc/testsuite/g++.dg/template/lookup6.C b/gcc/testsuite/g++.dg/template/lookup6.C
new file mode 100644
index 0000000000000000000000000000000000000000..2ca6dcc7547d428bb0d0c5406a8b71ecab8afdb3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/lookup6.C
@@ -0,0 +1,11 @@
+struct S
+{
+  template<typename T> static void g();
+};
+
+template<typename T>
+void f() { return S::template g<T>(); }
+
+void g() {
+  f<int>();
+}