summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.old-deja/g++.brendan/reference1.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/reference1.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/reference1.C')
-rw-r--r--gcc/testsuite/g++.old-deja/g++.brendan/reference1.C54
1 files changed, 54 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.old-deja/g++.brendan/reference1.C b/gcc/testsuite/g++.old-deja/g++.brendan/reference1.C
new file mode 100644
index 000000000..92ff38d7d
--- /dev/null
+++ b/gcc/testsuite/g++.old-deja/g++.brendan/reference1.C
@@ -0,0 +1,54 @@
+// { dg-do run }
+// { dg-options "-w" }
+// GROUPS passed references
+// Check that if a reference is initialized to refer to a value
+// which is returned from a function call, the actual call to
+// the function is only invoked for the original initialization
+// of the reference, and not for each subsequent use of the
+// reference.
+//
+// This test fails with G++ 1.35.0- (pre-release).
+// Reported 4/4/89 by Kim Smith
+
+extern "C" int printf (const char *, ...);
+
+struct base {
+ mutable int data_member;
+
+ base () {}
+ void function_member () const;
+};
+
+base base_object;
+
+base base_returning_function ();
+
+int call_count = 0;
+
+int main ()
+{
+ const base& base_ref = base_returning_function ();
+
+ base_ref.function_member ();
+ base_ref.function_member ();
+ base_ref.data_member = 99;
+
+ if (call_count == 1)
+ printf ("PASS\n");
+ else
+ { printf ("FAIL\n"); return 1; }
+
+ return 0;
+}
+
+base base_returning_function ()
+{
+ base local_base_object;
+
+ call_count++;
+ return local_base_object;
+}
+
+void base::function_member () const
+{
+}