aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Mitchell <mark@codesourcery.com>1999-07-31 06:09:13 +0000
committerMark Mitchell <mmitchel@gcc.gnu.org>1999-07-31 06:09:13 +0000
commit442aa4ec8411c645aa325f3f369ae626e40b7da6 (patch)
treef5ee02c6a08ae507a7e93e43abe2ea485cd32942
parent278a994d001ace7a4229c5be0daf75f85c873d45 (diff)
downloadgcc-442aa4ec8411c645aa325f3f369ae626e40b7da6.zip
gcc-442aa4ec8411c645aa325f3f369ae626e40b7da6.tar.gz
gcc-442aa4ec8411c645aa325f3f369ae626e40b7da6.tar.bz2
call.c (build_conditional_expr): Call convert_from_reference to avoid reference/non-reference type confusion.
* call.c (build_conditional_expr): Call convert_from_reference to avoid reference/non-reference type confusion. Fix typo. From-SVN: r28353
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/call.c18
-rw-r--r--gcc/testsuite/g++.old-deja/g++.other/cond3.C18
3 files changed, 34 insertions, 7 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 97f0c93..7c7714a 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+1999-07-30 Mark Mitchell <mark@codesourcery.com>
+
+ * call.c (build_conditional_expr): Call convert_from_reference to
+ avoid reference/non-reference type confusion. Fix typo.
+
1999-07-30 Richard Henderson <rth@cygnus.com>
* typeck2.c (initializer_constant_valid_p): Moved to c-common.c.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 4deaac2..6f17fba 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -2734,10 +2734,9 @@ conditional_conversion (e1, e2)
}
/* Implement [expr.cond]. ARG1, ARG2, and ARG3 are the three
- arguments to the conditional expression. As an extension, g++
- allows users to overload the ?: operator. By the time this
- function is called, any suitable candidate functions are included
- in CANDIDATES. */
+ arguments to the conditional expression. By the time this function
+ is called, any suitable candidate functions are included in
+ CANDIDATES. */
tree
build_conditional_expr (arg1, arg2, arg3)
@@ -2780,6 +2779,11 @@ build_conditional_expr (arg1, arg2, arg3)
_conv_). */
arg1 = cp_convert (boolean_type_node, arg1);
+ /* Convert from reference types to ordinary types; no expressions
+ really have reference type in C++. */
+ arg2 = convert_from_reference (arg2);
+ arg3 = convert_from_reference (arg3);
+
/* [expr.cond]
If either the second or the third operand has type (possibly
@@ -2867,6 +2871,7 @@ build_conditional_expr (arg1, arg2, arg3)
else if (conv2 && !ICS_BAD_FLAG (conv2))
{
arg2 = convert_like (conv2, arg2);
+ arg2 = convert_from_reference (arg2);
/* That may not quite have done the trick. If the two types
are cv-qualified variants of one another, we will have
just used an IDENTITY_CONV. (There's no conversion from
@@ -2881,8 +2886,9 @@ build_conditional_expr (arg1, arg2, arg3)
else if (conv3 && !ICS_BAD_FLAG (conv3))
{
arg3 = convert_like (conv3, arg3);
+ arg3 = convert_from_reference (arg3);
if (!same_type_p (TREE_TYPE (arg3), arg2_type))
- arg2 = build1 (NOP_EXPR, arg2_type, arg3);
+ arg3 = build1 (NOP_EXPR, arg2_type, arg3);
arg3_type = TREE_TYPE (arg3);
}
}
@@ -2891,8 +2897,6 @@ build_conditional_expr (arg1, arg2, arg3)
If the second and third operands are lvalues and have the same
type, the result is of that type and is an lvalue. */
- arg2_type = non_reference (arg2_type);
- arg3_type = non_reference (arg3_type);
if (real_lvalue_p (arg2) && real_lvalue_p (arg3) &&
same_type_p (arg2_type, arg3_type))
{
diff --git a/gcc/testsuite/g++.old-deja/g++.other/cond3.C b/gcc/testsuite/g++.old-deja/g++.other/cond3.C
new file mode 100644
index 0000000..e5563a6
--- /dev/null
+++ b/gcc/testsuite/g++.old-deja/g++.other/cond3.C
@@ -0,0 +1,18 @@
+// Build don't link:
+// Origin: Loring Holden <lsh@cs.brown.edu>
+
+class Wtransf {};
+
+const Wtransf Identity2k;
+
+class HELPER {
+ public:
+ int current() const { return 0; }
+};
+
+void
+problem_function()
+{
+ HELPER tm;
+ Wtransf delta = (tm.current()) ? Identity2 : Wtransf();
+}