summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/ipa/devirt-14.C
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/g++.dg/ipa/devirt-14.C')
-rw-r--r--gcc/testsuite/g++.dg/ipa/devirt-14.C34
1 files changed, 34 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/ipa/devirt-14.C b/gcc/testsuite/g++.dg/ipa/devirt-14.C
new file mode 100644
index 0000000000..456d44f84b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ipa/devirt-14.C
@@ -0,0 +1,34 @@
+/* No devirtualization happens here, but A::foo should not end up as reachable
+ because the constructor of A is unreachable and therefore the virtual
+ method table referring to A::foo is optimized out. */
+/* { dg-do run } */
+/* { dg-options "-O2 -fdump-tree-ssa" } */
+class B {
+public:
+ virtual int foo(void)
+{
+ return 0;
+}
+};
+namespace {
+class A : public B {
+public:
+ virtual int foo(void)
+{
+ return 1;
+}
+};
+}
+class B a, *b=&a;
+main()
+{
+ if (0)
+ {
+ class A a;
+ a.foo();
+ }
+ return b->foo();
+}
+
+/* { dg-final { scan-tree-dump-not "A::foo" "ssa"} } */
+/* { dg-final { cleanup-tree-dump "ssa" } } */