aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMatt Austern <austern@apple.com>2002-09-13 18:08:16 +0000
committerMatt Austern <austern@gcc.gnu.org>2002-09-13 18:08:16 +0000
commit6c6e776d78091abbf41d27cf42cdac5cd5693fff (patch)
tree03daa98a70f555ccc4b8fb9394928702aa0dc368 /gcc
parentd5909a796384bd39e8b9ed6c883f78e47438ef5b (diff)
downloadgcc-6c6e776d78091abbf41d27cf42cdac5cd5693fff.zip
gcc-6c6e776d78091abbf41d27cf42cdac5cd5693fff.tar.gz
gcc-6c6e776d78091abbf41d27cf42cdac5cd5693fff.tar.bz2
cp-tree.h, tree.c: New function non_cast_lvalue_p.
2002-09-13 Matt Austern <austern@apple.com> * cp/cp-tree.h, cp/tree.c: New function non_cast_lvalue_p. * cp/call.c: Change call-by-const-reference mechanism to use non_cast_lvalue_p when deciding whether the create a temporary. We need a temporary when passing, e.g. (long) x by const ref. * testsuite/g++.dg/other/constref[12].C: New, regression tests for passing a cast expression to a function by const reference. From-SVN: r57115
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/cp/call.c2
-rw-r--r--gcc/cp/cp-tree.h1
-rw-r--r--gcc/cp/tree.c8
-rw-r--r--gcc/testsuite/g++.dg/other/constref1.C16
-rw-r--r--gcc/testsuite/g++.dg/other/constref2.C16
6 files changed, 50 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 5a8c3c5..3b620b7 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2002-09-13 Matt Austern <austern@apple.com>
+ * cp/cp-tree.h, cp/tree.c: New function non_cast_lvalue_p.
+ * cp/call.c: Change call-by-const-reference mechanism to use
+ non_cast_lvalue_p when deciding whether the create a temporary.
+ We need a temporary when passing, e.g. (long) x by const ref.
+ * testsuite/g++.dg/other/constref[12].C: New, regression tests for
+ passing a cast expression to a function by const reference.
+
2002-09-13 Richard Henderson <rth@redhat.com>
* config/alpha/alpha.md (attr type): Add callpal.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 0715f2f..b428145 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -4059,7 +4059,7 @@ convert_like_real (convs, expr, fn, argnum, inner)
tree ref_type = totype;
/* If necessary, create a temporary. */
- if (NEED_TEMPORARY_P (convs) || !lvalue_p (expr))
+ if (NEED_TEMPORARY_P (convs) || !non_cast_lvalue_p (expr))
{
tree type = TREE_TYPE (TREE_OPERAND (convs, 0));
expr = build_target_expr_with_type (expr, type);
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 8dd6b9c..96c615d 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -4184,6 +4184,7 @@ extern tree canonical_type_variant PARAMS ((tree));
extern void unshare_base_binfos PARAMS ((tree));
extern int member_p PARAMS ((tree));
extern cp_lvalue_kind real_lvalue_p PARAMS ((tree));
+extern int non_cast_lvalue_p PARAMS ((tree));
extern int non_cast_lvalue_or_else PARAMS ((tree, const char *));
extern tree build_min PARAMS ((enum tree_code, tree,
...));
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index b0bd4fe..4fb4e49 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -229,6 +229,14 @@ lvalue_p (ref)
(lvalue_p_1 (ref, /*class rvalue ok*/ 1, /*cast*/ 1) != clk_none);
}
+int
+non_cast_lvalue_p (ref)
+ tree ref;
+{
+ return
+ (lvalue_p_1 (ref, /*class rvalue ok*/ 1, /*cast*/ 0) != clk_none);
+}
+
/* Return nonzero if REF is an lvalue valid for this language;
otherwise, print an error message and return zero. */
diff --git a/gcc/testsuite/g++.dg/other/constref1.C b/gcc/testsuite/g++.dg/other/constref1.C
new file mode 100644
index 0000000..900a07d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/other/constref1.C
@@ -0,0 +1,16 @@
+// { dg-do compile }
+
+// Copyright (C) 2002 Free Software Foundation, Inc.
+// Contributed by Matt Austern 12 Sep 2002 <austern@apple.com>
+
+// Make sure that we can pass a cast-expression as an argument that's
+// passed by const reference.
+
+void bar (const long&)
+{ }
+
+void foo (int x)
+{
+ bar ((long) x);
+}
+
diff --git a/gcc/testsuite/g++.dg/other/constref2.C b/gcc/testsuite/g++.dg/other/constref2.C
new file mode 100644
index 0000000..5c82e2d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/other/constref2.C
@@ -0,0 +1,16 @@
+// { dg-do compile }
+
+// Copyright (C) 2002 Free Software Foundation, Inc.
+// Contributed by Matt Austern 12 Sep 2002 <austern@apple.com>
+
+// Make sure that we can pass a cast-expression as an argument that's
+// passed to a function template by const reference.
+
+template <class T>
+void bar (const T&)
+{ }
+
+void foo (int x)
+{
+ bar ((long) x);
+}