In this testcase, main doesn't call anything, so the inline functions in
the classes can be optimized away, and we don't need the vtables or the
virtual functions they refer to. But cgraph_decide_is_function_needed
wants to write out all static functions at -O0, which in this case was
including the local thunk alias created by use_thunk. Clearly we don't
want to force such an alias out when it isn't needed, so I've added
same-body aliases to the list of things that we don't need to emit.
OK for trunk?
commit 9185aab5caf951ae4d46c8c36c33c00445ee4424
Author: Jason Merrill <ja...@redhat.com>
Date: Mon Jan 23 12:55:19 2012 -0500
PR c++/51812
* cgraphunit.c (cgraph_decide_is_function_needed): Don't always
output static aliases.
diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
index 6ea40ce..8f96d38 100644
--- a/gcc/cgraphunit.c
+++ b/gcc/cgraphunit.c
@@ -195,6 +195,7 @@ cgraph_decide_is_function_needed (struct cgraph_node *node, tree decl)
to change the behavior here. */
if (((TREE_PUBLIC (decl)
|| (!optimize
+ && !node->same_body_alias
&& !DECL_DISREGARD_INLINE_LIMITS (decl)
&& !DECL_DECLARED_INLINE_P (decl)
&& !(DECL_CONTEXT (decl)
diff --git a/gcc/testsuite/g++.dg/inherit/covariant20.C b/gcc/testsuite/g++.dg/inherit/covariant20.C
new file mode 100644
index 0000000..cf7e196
--- /dev/null
+++ b/gcc/testsuite/g++.dg/inherit/covariant20.C
@@ -0,0 +1,10 @@
+// PR c++/51812
+// { dg-do link }
+
+class Object {
+ virtual Object* clone() const;
+};
+class DNA: virtual public Object {
+ virtual DNA* clone() const {return new DNA(*this);}
+};
+int main() { }