summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/template/ptrmem18.C
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/g++.dg/template/ptrmem18.C')
-rw-r--r--gcc/testsuite/g++.dg/template/ptrmem18.C49
1 files changed, 49 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/template/ptrmem18.C b/gcc/testsuite/g++.dg/template/ptrmem18.C
new file mode 100644
index 000000000..c3124cd81
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/ptrmem18.C
@@ -0,0 +1,49 @@
+// PR c++/33616
+// { dg-do run }
+// { dg-options "-O2" }
+
+extern "C" void abort ();
+
+struct S {
+ int c;
+ S () : c (0) {}
+ virtual void f1 () { c += 1; }
+ virtual void f2 () { c += 16; }
+};
+
+struct T {
+ S s;
+};
+
+typedef void (S::*Q) ();
+
+template <Q P>
+void test1 (T *t)
+{
+ (t->s.*P)();
+}
+
+template <Q P>
+void test2 (T *t)
+{
+ S &s = t->s;
+ (s.*P)();
+}
+
+int
+main ()
+{
+ T t;
+ test1 <&S::f1> (&t);
+ if (t.s.c != 1)
+ abort ();
+ test1 <&S::f2> (&t);
+ if (t.s.c != 17)
+ abort ();
+ test2 <&S::f1> (&t);
+ if (t.s.c != 18)
+ abort ();
+ test2 <&S::f2> (&t);
+ if (t.s.c != 34)
+ abort ();
+}