+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.
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);
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,
...));
(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. */
--- /dev/null
+// { 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);
+}
+
--- /dev/null
+// { 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);
+}