summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.old-deja/g++.brendan/operators4.C
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/g++.old-deja/g++.brendan/operators4.C
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/g++.old-deja/g++.brendan/operators4.C')
-rw-r--r--gcc/testsuite/g++.old-deja/g++.brendan/operators4.C124
1 files changed, 124 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.old-deja/g++.brendan/operators4.C b/gcc/testsuite/g++.old-deja/g++.brendan/operators4.C
new file mode 100644
index 000000000..6408815cd
--- /dev/null
+++ b/gcc/testsuite/g++.old-deja/g++.brendan/operators4.C
@@ -0,0 +1,124 @@
+// { dg-do assemble }
+// { dg-options "" }
+
+// GROUPS passed operators
+// Check that the & operator, when applied to a global function
+// or member function returns a proper value as long as the context
+// in which the result of & is used requires a pointer to a specific
+// unambigous (function-pointer) type.
+//
+// This test fails (in test5()) when compiled with g++ 1.34.1.
+
+extern "C" int printf (const char *, ...);
+
+int function (char c);
+int function (float f);
+
+class base {
+ int filler;
+public:
+ int method (char);
+ int method (float);
+};
+
+void* vp;
+
+typedef int (*ptr_to_func_of_char)(char);
+typedef int (*ptr_to_func_of_float)(float);
+typedef int (base::*ptr_to_method_of_char)(char);
+typedef int (base::*ptr_to_method_of_float)(float);
+
+int test2 (void*);
+int test3 (void*);
+int test4 (void*);
+int test5 (void*);
+
+base* base_ptr;
+
+int fail ()
+{
+ printf ("FAIL\n");
+ return 1;
+}
+
+int main ()
+{
+ base_ptr = new base;
+
+ ptr_to_func_of_char p0 = &function;
+ vp = (void*) p0;
+ if (test2 (vp))
+ return fail ();
+ ptr_to_func_of_float p1 = &function;
+ vp = (void*) p1;
+ if (test3 (vp))
+ return fail ();
+ ptr_to_method_of_char p2 = &base::method;
+ vp = (void*) p2; // { dg-warning "converting" }
+ if (test4 (vp))
+ return fail ();
+ ptr_to_method_of_float p3 = &base::method;
+ vp = (void*) p3; // { dg-warning "converting" }
+ if (test5 (vp))
+ return fail ();
+
+ printf ("PASS\n");
+ return 0;
+}
+
+int test2 (void* vp)
+{
+ char ch = 'x';
+
+ return (((ptr_to_func_of_char)vp)(ch) != 9901);
+}
+
+int test3 (void* vp)
+{
+ float flt = 9.9;
+
+ return (((ptr_to_func_of_float)vp)(flt) != 9902);
+}
+
+int test4 (void* vp)
+{
+ char ch = 'x';
+ ptr_to_method_of_char p = (ptr_to_method_of_char) vp; // { dg-error "invalid cast" } bad type conversion
+
+ return ((base_ptr->*p)(ch) != 9904);
+}
+
+int test5 (void* vp)
+{
+ float flt = 9.9;
+ ptr_to_method_of_float p = (ptr_to_method_of_float) vp; // { dg-error "invalid cast" } bad type conversion
+
+ if ((base_ptr->*p)(flt) != 9905) {
+ return 1;
+ } else
+ return 0;
+}
+
+int function (char c)
+{
+ c = c;
+ return 9901;
+}
+
+int function (float f)
+{
+ f = f;
+ return 9902;
+}
+
+int base::method (char c)
+{
+ c = c;
+ return 9904;
+}
+
+int base::method (float f)
+{
+ f = f;
+ return 9905;
+}