This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: Enumerations in conditional op
- To: egcs-patches at egcs dot cygnus dot com
- Subject: C++ PATCH: Enumerations in conditional op
- From: Nathan Sidwell <nathan at acm dot org>
- Date: Thu, 02 Sep 1999 10:23:21 +0100
- Reply-To: nathan at compsci dot bristol dot ac dot uk
Hi,
I installed the attached approved bits from
http://egcs.cygnus.com/ml/gcc-patches/1999-08/msg00843.html
nathan
--
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
I have seen the death of PhotoShop -- it is called GIMP
nathan@acm.org http://www.cs.bris.ac.uk/~nathan/ nathan@cs.bris.ac.uk
1999-09-02 Nathan Sidwell <nathan@acm.org>
* call.c (build_conditional_expr): Warn on enum mismatches.
(convert_arg_to_ellipsis): Move non-pod check to after
conversion.
Index: gcc/cp/call.c
===================================================================
RCS file: /cvs/egcs/egcs/gcc/cp/call.c,v
retrieving revision 1.165
diff -c -3 -p -r1.165 call.c
*** call.c 1999/09/01 21:56:38 1.165
--- call.c 1999/09/02 09:11:12
*************** build_conditional_expr (arg1, arg2, arg3
*** 2991,2996 ****
--- 2991,3008 ----
/* In this case, there is always a common type. */
result_type = type_after_usual_arithmetic_conversions (arg2_type,
arg3_type);
+
+ if (TREE_CODE (arg2_type) == ENUMERAL_TYPE
+ && TREE_CODE (arg3_type) == ENUMERAL_TYPE)
+ cp_warning ("enumeral mismatch in conditional expression: `%T' vs `%T'",
+ arg2_type, arg3_type);
+ else if (extra_warnings
+ && ((TREE_CODE (arg2_type) == ENUMERAL_TYPE
+ && !same_type_p (arg3_type, type_promotes_to (arg2_type)))
+ || (TREE_CODE (arg3_type) == ENUMERAL_TYPE
+ && !same_type_p (arg2_type, type_promotes_to (arg3_type)))))
+ cp_warning ("enumeral and non-enumeral type in conditional expression");
+
arg2 = perform_implicit_conversion (result_type, arg2);
arg3 = perform_implicit_conversion (result_type, arg3);
}
*************** tree
*** 3755,3767 ****
convert_arg_to_ellipsis (arg)
tree arg;
{
- if (! pod_type_p (TREE_TYPE (arg)))
- {
- /* Undefined behaviour [expr.call] 5.2.2/7. */
- cp_warning ("cannot pass objects of non-POD type `%#T' through `...'",
- TREE_TYPE (arg));
- }
-
if (TREE_CODE (TREE_TYPE (arg)) == REAL_TYPE
&& (TYPE_PRECISION (TREE_TYPE (arg))
< TYPE_PRECISION (double_type_node)))
--- 3767,3772 ----
*************** convert_arg_to_ellipsis (arg)
*** 3773,3778 ****
--- 3778,3790 ----
arg = require_complete_type (arg);
+ if (arg != error_mark_node && ! pod_type_p (TREE_TYPE (arg)))
+ {
+ /* Undefined behaviour [expr.call] 5.2.2/7. */
+ cp_warning ("cannot pass objects of non-POD type `%#T' through `...'",
+ TREE_TYPE (arg));
+ }
+
return arg;
}