This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
(C++) tweak to build_conditional_expr
- To: gcc-patches at gcc dot gnu dot org
- Subject: (C++) tweak to build_conditional_expr
- From: Jason Merrill <jason at redhat dot com>
- Date: Sun, 22 Oct 2000 16:16:57 -0400
The lvalue-to-rvalue conversion can fail for a class that cannot be
copied; this patch prevents a crash when that happens.
2000-10-22 Jason Merrill <jason@redhat.com>
* call.c (build_conditional_expr): Use ocp_convert to force
rvalue conversion.
Index: call.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/call.c,v
retrieving revision 1.231
diff -c -p -r1.231 call.c
*** call.c 2000/09/19 03:26:11 1.231
--- call.c 2000/10/22 20:20:24
*************** build_conditional_expr (arg1, arg2, arg3
*** 3036,3051 ****
We need to force the lvalue-to-rvalue conversion here for class types,
so we get TARGET_EXPRs; trying to deal with a COND_EXPR of class rvalues
that isn't wrapped with a TARGET_EXPR plays havoc with exception
! regions. */
if (IS_AGGR_TYPE (TREE_TYPE (arg2)) && real_lvalue_p (arg2))
! arg2 = build_user_type_conversion (TREE_TYPE (arg2), arg2, LOOKUP_NORMAL);
else
arg2 = decay_conversion (arg2);
arg2_type = TREE_TYPE (arg2);
if (IS_AGGR_TYPE (TREE_TYPE (arg3)) && real_lvalue_p (arg3))
! arg3 = build_user_type_conversion (TREE_TYPE (arg3), arg3, LOOKUP_NORMAL);
else
arg3 = decay_conversion (arg3);
arg3_type = TREE_TYPE (arg3);
--- 3036,3056 ----
We need to force the lvalue-to-rvalue conversion here for class types,
so we get TARGET_EXPRs; trying to deal with a COND_EXPR of class rvalues
that isn't wrapped with a TARGET_EXPR plays havoc with exception
! regions.
+ We use ocp_convert rather than build_user_type_conversion because the
+ latter returns NULL_TREE on failure, while the former gives an error. */
+
if (IS_AGGR_TYPE (TREE_TYPE (arg2)) && real_lvalue_p (arg2))
! arg2 = ocp_convert (TREE_TYPE (arg2), arg2,
! CONV_IMPLICIT|CONV_FORCE_TEMP, LOOKUP_NORMAL);
else
arg2 = decay_conversion (arg2);
arg2_type = TREE_TYPE (arg2);
if (IS_AGGR_TYPE (TREE_TYPE (arg3)) && real_lvalue_p (arg3))
! arg3 = ocp_convert (TREE_TYPE (arg3), arg3,
! CONV_IMPLICIT|CONV_FORCE_TEMP, LOOKUP_NORMAL);
else
arg3 = decay_conversion (arg3);
arg3_type = TREE_TYPE (arg3);
Index: ../testsuite/g++.old-deja/g++.other/volatile1.C
===================================================================
RCS file: volatile1.C
diff -N volatile1.C
*** /dev/null Tue May 5 13:32:27 1998
--- ../testsuite/g++.old-deja/g++.other/volatile1.C Sun Oct 22 13:20:24 2000
***************
*** 0 ****
--- 1,19 ----
+ // Test that failed lvalue-to-rvalue conversion of vf doesn't crash the
+ // compiler.
+
+ class f_class
+ { }; // ERROR - candidates
+
+ volatile f_class
+ ret_v_f_class()
+ {
+ f_class t;
+ return t;
+ }
+
+ int main(void)
+ {
+ volatile f_class vf;
+ 0 ? ret_v_f_class() : vf; // ERROR - can't copy volatile lvalue
+ return 0;
+ }