Index: ChangeLog
===================================================================
--- ChangeLog	(revision 166644)
+++ ChangeLog	(working copy)
@@ -1,3 +1,8 @@
+2010-11-12  James Dennett <jdennett@google.com>
+	PR/39415
+	* cp/typeck.c (build_static_cast_1): Convert to the target type
+	when doing static_cast<cv Derived*>(Base*).
+
 2010-11-11  Nathan Froyd  <froydnj@codesourcery.com>

 	PR c/44782
Index: testsuite/g++.dg/expr/static_cast7.C
===================================================================
--- testsuite/g++.dg/expr/static_cast7.C	(revision 0)
+++ testsuite/g++.dg/expr/static_cast7.C	(revision 0)
@@ -0,0 +1,10 @@
+// Regression test for bug 39415 (and its duplicate 44916).
+struct S {};
+struct T : S {};
+int f(const T*) {}
+void f(T*);
+int main() {
+  S* s(0);
+  int a = f(static_cast<const T*>(s));
+  int b = f(static_cast<const T*>(0));
+}
Index: cp/typeck.c
===================================================================
--- cp/typeck.c	(revision 166644)
+++ cp/typeck.c	(working copy)
@@ -5884,7 +5884,8 @@ build_static_cast_1 (tree type, tree exp
       base = lookup_base (TREE_TYPE (type), TREE_TYPE (intype),
 			  c_cast_p ? ba_unique : ba_check,
 			  NULL);
-      return build_base_path (MINUS_EXPR, expr, base, /*nonnull=*/false);
+      expr = build_base_path (MINUS_EXPR, expr, base, /*nonnull=*/false);
+      return cp_fold_convert(type, expr);
     }

   if ((TYPE_PTRMEM_P (type) && TYPE_PTRMEM_P (intype))
