1 /* Language-level data type conversion for GNU C++.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
5 Hacked by Michael Tiemann (tiemann@cygnus.com)
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
14 GCC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
24 /* This file contains the functions for converting C++ expressions
25 to different data types. The only entry point is `convert'.
26 Every language front end must have a `convert' function
27 but what kind of conversions it does will depend on the language. */
31 #include "coretypes.h"
42 static tree cp_convert_to_pointer (tree, tree);
43 static tree convert_to_pointer_force (tree, tree);
44 static tree build_type_conversion (tree, tree);
45 static tree build_up_reference (tree, tree, int, tree);
46 static void warn_ref_binding (tree, tree, tree);
48 /* Change of width--truncation and extension of integers or reals--
49 is represented with NOP_EXPR. Proper functioning of many things
50 assumes that no other conversions can be NOP_EXPRs.
52 Conversion between integer and pointer is represented with CONVERT_EXPR.
53 Converting integer to real uses FLOAT_EXPR
54 and real to integer uses FIX_TRUNC_EXPR.
56 Here is a list of all the functions that assume that widening and
57 narrowing is always done with a NOP_EXPR:
58 In convert.c, convert_to_integer.
59 In c-typeck.c, build_binary_op_nodefault (boolean ops),
60 and c_common_truthvalue_conversion.
61 In expr.c: expand_expr, for operands of a MULT_EXPR.
62 In fold-const.c: fold.
63 In tree.c: get_narrower and get_unwidened.
65 C++: in multiple-inheritance, converting between pointers may involve
66 adjusting them by a delta stored within the class definition. */
68 /* Subroutines of `convert'. */
70 /* if converting pointer to pointer
71 if dealing with classes, check for derived->base or vice versa
72 else if dealing with method pointers, delegate
74 else if converting class, pass off to build_type_conversion
75 else try C-style pointer conversion. */
78 cp_convert_to_pointer (tree type, tree expr)
80 tree intype = TREE_TYPE (expr);
83 if (intype == error_mark_node)
84 return error_mark_node;
86 if (MAYBE_CLASS_TYPE_P (intype))
88 intype = complete_type (intype);
89 if (!COMPLETE_TYPE_P (intype))
91 error ("can't convert from incomplete type %qT to %qT",
93 return error_mark_node;
96 rval = build_type_conversion (type, expr);
99 if (rval == error_mark_node)
100 error ("conversion of %qE from %qT to %qT is ambiguous",
106 /* Handle anachronistic conversions from (::*)() to cv void* or (*)(). */
107 if (TREE_CODE (type) == POINTER_TYPE
108 && (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
109 || VOID_TYPE_P (TREE_TYPE (type))))
111 if (TYPE_PTRMEMFUNC_P (intype)
112 || TREE_CODE (intype) == METHOD_TYPE)
113 return convert_member_func_to_ptr (type, expr);
114 if (TREE_CODE (TREE_TYPE (expr)) == POINTER_TYPE)
115 return build_nop (type, expr);
116 intype = TREE_TYPE (expr);
119 if (expr == error_mark_node)
120 return error_mark_node;
122 form = TREE_CODE (intype);
124 if (POINTER_TYPE_P (intype))
126 intype = TYPE_MAIN_VARIANT (intype);
128 if (TYPE_MAIN_VARIANT (type) != intype
129 && TREE_CODE (type) == POINTER_TYPE
130 && TREE_CODE (TREE_TYPE (type)) == RECORD_TYPE
131 && MAYBE_CLASS_TYPE_P (TREE_TYPE (type))
132 && MAYBE_CLASS_TYPE_P (TREE_TYPE (intype))
133 && TREE_CODE (TREE_TYPE (intype)) == RECORD_TYPE)
135 enum tree_code code = PLUS_EXPR;
141 intype_class = TREE_TYPE (intype);
142 type_class = TREE_TYPE (type);
144 same_p = same_type_p (TYPE_MAIN_VARIANT (intype_class),
145 TYPE_MAIN_VARIANT (type_class));
147 /* Try derived to base conversion. */
149 binfo = lookup_base (intype_class, type_class, ba_check, NULL);
150 if (!same_p && !binfo)
152 /* Try base to derived conversion. */
153 binfo = lookup_base (type_class, intype_class, ba_check, NULL);
156 if (binfo == error_mark_node)
157 return error_mark_node;
161 expr = build_base_path (code, expr, binfo, 0);
162 /* Add any qualifier conversions. */
163 return build_nop (type, expr);
167 if (TYPE_PTRMEMFUNC_P (type))
169 error ("cannot convert %qE from type %qT to type %qT",
171 return error_mark_node;
174 return build_nop (type, expr);
176 else if ((TYPE_PTRMEM_P (type) && TYPE_PTRMEM_P (intype))
177 || (TYPE_PTRMEMFUNC_P (type) && TYPE_PTRMEMFUNC_P (intype)))
178 return convert_ptrmem (type, expr, /*allow_inverse_p=*/false,
179 /*c_cast_p=*/false, tf_warning_or_error);
180 else if (TYPE_PTRMEMFUNC_P (intype))
184 if (TREE_CODE (expr) == PTRMEM_CST)
185 return cp_convert_to_pointer (type,
186 PTRMEM_CST_MEMBER (expr));
187 else if (TREE_CODE (expr) == OFFSET_REF)
189 tree object = TREE_OPERAND (expr, 0);
190 return get_member_function_from_ptrfunc (&object,
191 TREE_OPERAND (expr, 1));
194 error ("cannot convert %qE from type %qT to type %qT",
196 return error_mark_node;
199 if (null_ptr_cst_p (expr))
201 if (TYPE_PTRMEMFUNC_P (type))
202 return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), expr, 0,
203 /*c_cast_p=*/false, tf_warning_or_error);
205 if (TYPE_PTRMEM_P (type))
207 /* A NULL pointer-to-member is represented by -1, not by
209 expr = build_int_cst_type (type, -1);
212 expr = build_int_cst (type, 0);
216 else if (TYPE_PTR_TO_MEMBER_P (type) && INTEGRAL_CODE_P (form))
218 error ("invalid conversion from %qT to %qT", intype, type);
219 return error_mark_node;
222 if (INTEGRAL_CODE_P (form))
224 if (TYPE_PRECISION (intype) == POINTER_SIZE)
225 return build1 (CONVERT_EXPR, type, expr);
226 expr = cp_convert (c_common_type_for_size (POINTER_SIZE, 0), expr);
227 /* Modes may be different but sizes should be the same. There
228 is supposed to be some integral type that is the same width
230 gcc_assert (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (expr)))
231 == GET_MODE_SIZE (TYPE_MODE (type)));
233 return convert_to_pointer (type, expr);
236 if (type_unknown_p (expr))
237 return instantiate_type (type, expr, tf_warning_or_error);
239 error ("cannot convert %qE from type %qT to type %qT",
241 return error_mark_node;
244 /* Like convert, except permit conversions to take place which
245 are not normally allowed due to access restrictions
246 (such as conversion from sub-type to private super-type). */
249 convert_to_pointer_force (tree type, tree expr)
251 tree intype = TREE_TYPE (expr);
252 enum tree_code form = TREE_CODE (intype);
254 if (form == POINTER_TYPE)
256 intype = TYPE_MAIN_VARIANT (intype);
258 if (TYPE_MAIN_VARIANT (type) != intype
259 && TREE_CODE (TREE_TYPE (type)) == RECORD_TYPE
260 && MAYBE_CLASS_TYPE_P (TREE_TYPE (type))
261 && MAYBE_CLASS_TYPE_P (TREE_TYPE (intype))
262 && TREE_CODE (TREE_TYPE (intype)) == RECORD_TYPE)
264 enum tree_code code = PLUS_EXPR;
267 binfo = lookup_base (TREE_TYPE (intype), TREE_TYPE (type),
271 binfo = lookup_base (TREE_TYPE (type), TREE_TYPE (intype),
275 if (binfo == error_mark_node)
276 return error_mark_node;
279 expr = build_base_path (code, expr, binfo, 0);
280 if (expr == error_mark_node)
281 return error_mark_node;
282 /* Add any qualifier conversions. */
283 if (!same_type_p (TREE_TYPE (TREE_TYPE (expr)),
285 expr = build_nop (type, expr);
291 return cp_convert_to_pointer (type, expr);
294 /* We are passing something to a function which requires a reference.
295 The type we are interested in is in TYPE. The initial
296 value we have to begin with is in ARG.
298 FLAGS controls how we manage access checking.
299 DIRECT_BIND in FLAGS controls how any temporaries are generated.
300 If DIRECT_BIND is set, DECL is the reference we're binding to. */
303 build_up_reference (tree type, tree arg, int flags, tree decl)
306 tree argtype = TREE_TYPE (arg);
307 tree target_type = TREE_TYPE (type);
309 gcc_assert (TREE_CODE (type) == REFERENCE_TYPE);
311 if ((flags & DIRECT_BIND) && ! real_lvalue_p (arg))
313 /* Create a new temporary variable. We can't just use a TARGET_EXPR
314 here because it needs to live as long as DECL. */
317 arg = make_temporary_var_for_ref_to_temp (decl, target_type);
319 /* Process the initializer for the declaration. */
320 DECL_INITIAL (arg) = targ;
321 cp_finish_decl (arg, targ, /*init_const_expr_p=*/false, NULL_TREE,
322 LOOKUP_ONLYCONVERTING|DIRECT_BIND);
324 else if (!(flags & DIRECT_BIND) && ! lvalue_p (arg))
325 return get_target_expr (arg);
327 /* If we had a way to wrap this up, and say, if we ever needed its
328 address, transform all occurrences of the register, into a memory
329 reference we could win better. */
330 rval = cp_build_addr_expr (arg, tf_warning_or_error);
331 if (rval == error_mark_node)
332 return error_mark_node;
334 if ((flags & LOOKUP_PROTECT)
335 && TYPE_MAIN_VARIANT (argtype) != TYPE_MAIN_VARIANT (target_type)
336 && MAYBE_CLASS_TYPE_P (argtype)
337 && MAYBE_CLASS_TYPE_P (target_type))
339 /* We go through lookup_base for the access control. */
340 tree binfo = lookup_base (argtype, target_type, ba_check, NULL);
341 if (binfo == error_mark_node)
342 return error_mark_node;
343 if (binfo == NULL_TREE)
344 return error_not_base_type (target_type, argtype);
345 rval = build_base_path (PLUS_EXPR, rval, binfo, 1);
349 = convert_to_pointer_force (build_pointer_type (target_type), rval);
350 return build_nop (type, rval);
353 /* Subroutine of convert_to_reference. REFTYPE is the target reference type.
354 INTYPE is the original rvalue type and DECL is an optional _DECL node
357 [dcl.init.ref] says that if an rvalue is used to
358 initialize a reference, then the reference must be to a
359 non-volatile const type. */
362 warn_ref_binding (tree reftype, tree intype, tree decl)
364 tree ttl = TREE_TYPE (reftype);
366 if (!CP_TYPE_CONST_NON_VOLATILE_P (ttl))
370 if (CP_TYPE_VOLATILE_P (ttl) && decl)
371 msg = G_("initialization of volatile reference type %q#T from "
372 "rvalue of type %qT");
373 else if (CP_TYPE_VOLATILE_P (ttl))
374 msg = G_("conversion to volatile reference type %q#T "
375 "from rvalue of type %qT");
377 msg = G_("initialization of non-const reference type %q#T from "
378 "rvalue of type %qT");
380 msg = G_("conversion to non-const reference type %q#T from "
381 "rvalue of type %qT");
383 permerror (input_location, msg, reftype, intype);
387 /* For C++: Only need to do one-level references, but cannot
388 get tripped up on signed/unsigned differences.
390 DECL is either NULL_TREE or the _DECL node for a reference that is being
391 initialized. It can be error_mark_node if we don't know the _DECL but
392 we know it's an initialization. */
395 convert_to_reference (tree reftype, tree expr, int convtype,
396 int flags, tree decl)
398 tree type = TYPE_MAIN_VARIANT (TREE_TYPE (reftype));
400 tree rval = NULL_TREE;
401 tree rval_as_conversion = NULL_TREE;
402 bool can_convert_intype_to_type;
404 if (TREE_CODE (type) == FUNCTION_TYPE
405 && TREE_TYPE (expr) == unknown_type_node)
406 expr = instantiate_type (type, expr,
407 (flags & LOOKUP_COMPLAIN)
408 ? tf_warning_or_error : tf_none);
410 if (expr == error_mark_node)
411 return error_mark_node;
413 intype = TREE_TYPE (expr);
415 gcc_assert (TREE_CODE (intype) != REFERENCE_TYPE);
416 gcc_assert (TREE_CODE (reftype) == REFERENCE_TYPE);
418 intype = TYPE_MAIN_VARIANT (intype);
420 can_convert_intype_to_type = can_convert (type, intype);
421 if (!can_convert_intype_to_type
422 && (convtype & CONV_IMPLICIT) && MAYBE_CLASS_TYPE_P (intype)
423 && ! (flags & LOOKUP_NO_CONVERSION))
425 /* Look for a user-defined conversion to lvalue that we can use. */
428 = build_type_conversion (reftype, expr);
430 if (rval_as_conversion && rval_as_conversion != error_mark_node
431 && real_lvalue_p (rval_as_conversion))
433 expr = rval_as_conversion;
434 rval_as_conversion = NULL_TREE;
436 can_convert_intype_to_type = 1;
440 if (((convtype & CONV_STATIC) && can_convert (intype, type))
441 || ((convtype & CONV_IMPLICIT) && can_convert_intype_to_type))
443 if (flags & LOOKUP_COMPLAIN)
445 tree ttl = TREE_TYPE (reftype);
446 tree ttr = lvalue_type (expr);
448 if (! real_lvalue_p (expr))
449 warn_ref_binding (reftype, intype, decl);
451 if (! (convtype & CONV_CONST)
452 && !at_least_as_qualified_p (ttl, ttr))
453 permerror (input_location, "conversion from %qT to %qT discards qualifiers",
457 return build_up_reference (reftype, expr, flags, decl);
459 else if ((convtype & CONV_REINTERPRET) && lvalue_p (expr))
461 /* When casting an lvalue to a reference type, just convert into
462 a pointer to the new type and deference it. This is allowed
463 by San Diego WP section 5.2.9 paragraph 12, though perhaps it
464 should be done directly (jason). (int &)ri ---> *(int*)&ri */
466 /* B* bp; A& ar = (A&)bp; is valid, but it's probably not what they
468 if (TREE_CODE (intype) == POINTER_TYPE
469 && (comptypes (TREE_TYPE (intype), type,
470 COMPARE_BASE | COMPARE_DERIVED)))
471 warning (0, "casting %qT to %qT does not dereference pointer",
474 rval = cp_build_addr_expr (expr, tf_warning_or_error);
475 if (rval != error_mark_node)
476 rval = convert_force (build_pointer_type (TREE_TYPE (reftype)),
478 if (rval != error_mark_node)
479 rval = build1 (NOP_EXPR, reftype, rval);
483 rval = convert_for_initialization (NULL_TREE, type, expr, flags,
484 ICR_CONVERTING, 0, 0,
485 tf_warning_or_error);
486 if (rval == NULL_TREE || rval == error_mark_node)
488 warn_ref_binding (reftype, intype, decl);
489 rval = build_up_reference (reftype, rval, flags, decl);
494 /* If we found a way to convert earlier, then use it. */
498 if (flags & LOOKUP_COMPLAIN)
499 error ("cannot convert type %qT to type %qT", intype, reftype);
501 return error_mark_node;
504 /* We are using a reference VAL for its value. Bash that reference all the
505 way down to its lowest form. */
508 convert_from_reference (tree val)
511 && TREE_CODE (TREE_TYPE (val)) == REFERENCE_TYPE)
513 tree t = TREE_TYPE (TREE_TYPE (val));
514 tree ref = build1 (INDIRECT_REF, t, val);
516 /* We *must* set TREE_READONLY when dereferencing a pointer to const,
517 so that we get the proper error message if the result is used
518 to assign to. Also, &* is supposed to be a no-op. */
519 TREE_READONLY (ref) = CP_TYPE_CONST_P (t);
520 TREE_THIS_VOLATILE (ref) = CP_TYPE_VOLATILE_P (t);
521 TREE_SIDE_EFFECTS (ref)
522 = (TREE_THIS_VOLATILE (ref) || TREE_SIDE_EFFECTS (val));
523 REFERENCE_REF_P (ref) = 1;
530 /* Really perform an lvalue-to-rvalue conversion, including copying an
531 argument of class type into a temporary. */
534 force_rvalue (tree expr)
536 if (MAYBE_CLASS_TYPE_P (TREE_TYPE (expr)) && TREE_CODE (expr) != TARGET_EXPR)
537 expr = ocp_convert (TREE_TYPE (expr), expr,
538 CONV_IMPLICIT|CONV_FORCE_TEMP, LOOKUP_NORMAL);
540 expr = decay_conversion (expr);
546 /* Fold away simple conversions, but make sure the result is an rvalue. */
549 cp_fold_convert (tree type, tree expr)
551 return rvalue (fold_convert (type, expr));
554 /* C++ conversions, preference to static cast conversions. */
557 cp_convert (tree type, tree expr)
559 return ocp_convert (type, expr, CONV_OLD_CONVERT, LOOKUP_NORMAL);
562 /* C++ equivalent of convert_and_check but using cp_convert as the
565 Convert EXPR to TYPE, warning about conversion problems with constants.
566 Invoke this function on every expression that is converted implicitly,
567 i.e. because of language rules and not because of an explicit cast. */
570 cp_convert_and_check (tree type, tree expr)
574 if (TREE_TYPE (expr) == type)
577 result = cp_convert (type, expr);
579 if (c_inhibit_evaluation_warnings == 0
580 && !TREE_OVERFLOW_P (expr)
581 && result != error_mark_node)
582 warnings_for_convert_and_check (type, expr, result);
589 FLAGS indicates how we should behave. */
592 ocp_convert (tree type, tree expr, int convtype, int flags)
595 enum tree_code code = TREE_CODE (type);
596 const char *invalid_conv_diag;
599 if (error_operand_p (e) || type == error_mark_node)
600 return error_mark_node;
602 complete_type (type);
603 complete_type (TREE_TYPE (expr));
605 if ((invalid_conv_diag
606 = targetm.invalid_conversion (TREE_TYPE (expr), type)))
608 error (invalid_conv_diag);
609 return error_mark_node;
612 /* FIXME remove when moving to c_fully_fold model. */
613 /* FIXME do we still need this test? */
614 if (!CLASS_TYPE_P (type))
615 e = integral_constant_value (e);
616 if (error_operand_p (e))
617 return error_mark_node;
619 if (MAYBE_CLASS_TYPE_P (type) && (convtype & CONV_FORCE_TEMP))
620 /* We need a new temporary; don't take this shortcut. */;
621 else if (same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (e)))
623 if (same_type_p (type, TREE_TYPE (e)))
624 /* The call to fold will not always remove the NOP_EXPR as
625 might be expected, since if one of the types is a typedef;
626 the comparison in fold is just equality of pointers, not a
627 call to comptypes. We don't call fold in this case because
628 that can result in infinite recursion; fold will call
629 convert, which will call ocp_convert, etc. */
631 /* For complex data types, we need to perform componentwise
633 else if (TREE_CODE (type) == COMPLEX_TYPE)
634 return fold_if_not_in_template (convert_to_complex (type, e));
635 else if (TREE_CODE (e) == TARGET_EXPR)
637 /* Don't build a NOP_EXPR of class type. Instead, change the
638 type of the temporary. */
639 TREE_TYPE (e) = TREE_TYPE (TARGET_EXPR_SLOT (e)) = type;
644 /* We shouldn't be treating objects of ADDRESSABLE type as
646 gcc_assert (!TREE_ADDRESSABLE (type));
647 return fold_if_not_in_template (build_nop (type, e));
651 e1 = targetm.convert_to_type (type, e);
655 if (code == VOID_TYPE && (convtype & CONV_STATIC))
657 e = convert_to_void (e, ICV_CAST, tf_warning_or_error);
661 if (INTEGRAL_CODE_P (code))
663 tree intype = TREE_TYPE (e);
665 if (TREE_CODE (type) == ENUMERAL_TYPE)
667 /* enum = enum, enum = int, enum = float, (enum)pointer are all
669 if (((INTEGRAL_OR_ENUMERATION_TYPE_P (intype)
670 || TREE_CODE (intype) == REAL_TYPE)
671 && ! (convtype & CONV_STATIC))
672 || TREE_CODE (intype) == POINTER_TYPE)
674 if (flags & LOOKUP_COMPLAIN)
675 permerror (input_location, "conversion from %q#T to %q#T", intype, type);
677 if (!flag_permissive)
678 return error_mark_node;
681 /* [expr.static.cast]
683 8. A value of integral or enumeration type can be explicitly
684 converted to an enumeration type. The value is unchanged if
685 the original value is within the range of the enumeration
686 values. Otherwise, the resulting enumeration value is
688 if (TREE_CODE (expr) == INTEGER_CST
689 && !int_fits_type_p (expr, ENUM_UNDERLYING_TYPE (type)))
690 warning (OPT_Wconversion,
691 "the result of the conversion is unspecified because "
692 "%qE is outside the range of type %qT",
695 if (MAYBE_CLASS_TYPE_P (intype))
698 rval = build_type_conversion (type, e);
701 if (flags & LOOKUP_COMPLAIN)
702 error ("%q#T used where a %qT was expected", intype, type);
703 return error_mark_node;
705 if (code == BOOLEAN_TYPE)
706 return cp_truthvalue_conversion (e);
708 return fold_if_not_in_template (convert_to_integer (type, e));
710 if (NULLPTR_TYPE_P (type) && e && null_ptr_cst_p (e))
712 if (POINTER_TYPE_P (type) || TYPE_PTR_TO_MEMBER_P (type))
713 return fold_if_not_in_template (cp_convert_to_pointer (type, e));
714 if (code == VECTOR_TYPE)
716 tree in_vtype = TREE_TYPE (e);
717 if (MAYBE_CLASS_TYPE_P (in_vtype))
720 ret_val = build_type_conversion (type, e);
723 if (flags & LOOKUP_COMPLAIN)
724 error ("%q#T used where a %qT was expected", in_vtype, type);
725 return error_mark_node;
727 return fold_if_not_in_template (convert_to_vector (type, e));
729 if (code == REAL_TYPE || code == COMPLEX_TYPE)
731 if (MAYBE_CLASS_TYPE_P (TREE_TYPE (e)))
734 rval = build_type_conversion (type, e);
738 if (flags & LOOKUP_COMPLAIN)
739 error ("%q#T used where a floating point value was expected",
742 if (code == REAL_TYPE)
743 return fold_if_not_in_template (convert_to_real (type, e));
744 else if (code == COMPLEX_TYPE)
745 return fold_if_not_in_template (convert_to_complex (type, e));
748 /* New C++ semantics: since assignment is now based on
749 memberwise copying, if the rhs type is derived from the
750 lhs type, then we may still do a conversion. */
751 if (RECORD_OR_UNION_CODE_P (code))
753 tree dtype = TREE_TYPE (e);
754 tree ctor = NULL_TREE;
756 dtype = TYPE_MAIN_VARIANT (dtype);
758 /* Conversion between aggregate types. New C++ semantics allow
759 objects of derived type to be cast to objects of base type.
760 Old semantics only allowed this between pointers.
762 There may be some ambiguity between using a constructor
763 vs. using a type conversion operator when both apply. */
767 if (abstract_virtuals_error (NULL_TREE, type))
768 return error_mark_node;
770 if (BRACE_ENCLOSED_INITIALIZER_P (ctor))
771 ctor = perform_implicit_conversion (type, ctor, tf_warning_or_error);
772 else if ((flags & LOOKUP_ONLYCONVERTING)
773 && ! (CLASS_TYPE_P (dtype) && DERIVED_FROM_P (type, dtype)))
774 /* For copy-initialization, first we create a temp of the proper type
775 with a user-defined conversion sequence, then we direct-initialize
776 the target with the temp (see [dcl.init]). */
777 ctor = build_user_type_conversion (type, ctor, flags);
780 VEC(tree,gc) *ctor_vec = make_tree_vector_single (ctor);
781 ctor = build_special_member_call (NULL_TREE,
782 complete_ctor_identifier,
785 tf_warning_or_error);
786 release_tree_vector (ctor_vec);
789 return build_cplus_new (type, ctor);
792 if (flags & LOOKUP_COMPLAIN)
794 /* If the conversion failed and expr was an invalid use of pointer to
795 member function, try to report a meaningful error. */
796 if (invalid_nonstatic_memfn_p (expr, tf_warning_or_error))
797 /* We displayed the error message. */;
799 error ("conversion from %qT to non-scalar type %qT requested",
800 TREE_TYPE (expr), type);
802 return error_mark_node;
805 /* When an expression is used in a void context, its value is discarded and
806 no lvalue-rvalue and similar conversions happen [expr.static.cast/4,
807 stmt.expr/1, expr.comma/1]. This permits dereferencing an incomplete type
808 in a void context. The C++ standard does not define what an `access' to an
809 object is, but there is reason to believe that it is the lvalue to rvalue
810 conversion -- if it were not, `*&*p = 1' would violate [expr]/4 in that it
811 accesses `*p' not to calculate the value to be stored. But, dcl.type.cv/8
812 indicates that volatile semantics should be the same between C and C++
813 where ever possible. C leaves it implementation defined as to what
814 constitutes an access to a volatile. So, we interpret `*vp' as a read of
815 the volatile object `vp' points to, unless that is an incomplete type. For
816 volatile references we do not do this interpretation, because that would
817 make it impossible to ignore the reference return value from functions. We
818 issue warnings in the confusing cases.
820 The IMPLICIT is ICV_CAST when the user is explicitly converting an expression
821 to void via a cast. If an expression is being implicitly converted, IMPLICIT
822 indicates the context of the implicit conversion. */
825 convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain)
827 if (expr == error_mark_node
828 || TREE_TYPE (expr) == error_mark_node)
829 return error_mark_node;
831 if (implicit == ICV_CAST)
832 mark_exp_read (expr);
837 while (TREE_CODE (exprv) == COMPOUND_EXPR)
838 exprv = TREE_OPERAND (exprv, 1);
840 || handled_component_p (exprv)
841 || TREE_CODE (exprv) == INDIRECT_REF)
842 /* Expr is not being 'used' here, otherwise we whould have
843 called mark_{rl}value_use use here, which would have in turn
844 called mark_exp_read. Rather, we call mark_exp_read directly
845 to avoid some warnings when
846 -Wunused-but-set-{variable,parameter} is in effect. */
847 mark_exp_read (exprv);
850 if (!TREE_TYPE (expr))
852 if (invalid_nonstatic_memfn_p (expr, complain))
853 return error_mark_node;
854 if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR)
856 if (complain & tf_error)
857 error ("pseudo-destructor is not called");
858 return error_mark_node;
860 if (VOID_TYPE_P (TREE_TYPE (expr)))
862 switch (TREE_CODE (expr))
866 /* The two parts of a cond expr might be separate lvalues. */
867 tree op1 = TREE_OPERAND (expr,1);
868 tree op2 = TREE_OPERAND (expr,2);
869 bool side_effects = TREE_SIDE_EFFECTS (op1) || TREE_SIDE_EFFECTS (op2);
870 tree new_op1, new_op2;
871 if (implicit != ICV_CAST && !side_effects)
873 new_op1 = convert_to_void (op1, ICV_SECOND_OF_COND, complain);
874 new_op2 = convert_to_void (op2, ICV_THIRD_OF_COND, complain);
878 new_op1 = convert_to_void (op1, ICV_CAST, complain);
879 new_op2 = convert_to_void (op2, ICV_CAST, complain);
882 expr = build3 (COND_EXPR, TREE_TYPE (new_op1),
883 TREE_OPERAND (expr, 0), new_op1, new_op2);
889 /* The second part of a compound expr contains the value. */
890 tree op1 = TREE_OPERAND (expr,1);
892 if (implicit != ICV_CAST && !TREE_NO_WARNING (expr))
893 new_op1 = convert_to_void (op1, ICV_RIGHT_OF_COMMA, complain);
895 new_op1 = convert_to_void (op1, ICV_CAST, complain);
899 tree t = build2 (COMPOUND_EXPR, TREE_TYPE (new_op1),
900 TREE_OPERAND (expr, 0), new_op1);
907 case NON_LVALUE_EXPR:
909 /* These have already decayed to rvalue. */
912 case CALL_EXPR: /* We have a special meaning for volatile void fn(). */
917 tree type = TREE_TYPE (expr);
918 int is_reference = TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0)))
920 int is_volatile = TYPE_VOLATILE (type);
921 int is_complete = COMPLETE_TYPE_P (complete_type (type));
923 /* Can't load the value if we don't know the type. */
924 if (is_volatile && !is_complete)
926 if (complain & tf_warning)
930 warning (0, "conversion to void will not access "
931 "object of incomplete type %qT", type);
933 case ICV_SECOND_OF_COND:
934 warning (0, "indirection will not access object of "
935 "incomplete type %qT in second operand "
936 "of conditional expression", type);
938 case ICV_THIRD_OF_COND:
939 warning (0, "indirection will not access object of "
940 "incomplete type %qT in third operand "
941 "of conditional expression", type);
943 case ICV_RIGHT_OF_COMMA:
944 warning (0, "indirection will not access object of "
945 "incomplete type %qT in right operand of "
946 "comma operator", type);
948 case ICV_LEFT_OF_COMMA:
949 warning (0, "indirection will not access object of "
950 "incomplete type %qT in left operand of "
951 "comma operator", type);
954 warning (0, "indirection will not access object of "
955 "incomplete type %qT in statement", type);
957 case ICV_THIRD_IN_FOR:
958 warning (0, "indirection will not access object of "
959 "incomplete type %qT in for increment "
966 /* Don't load the value if this is an implicit dereference, or if
967 the type needs to be handled by ctors/dtors. */
968 else if (is_volatile && is_reference)
970 if (complain & tf_warning)
974 warning (0, "conversion to void will not access "
975 "object of type %qT", type);
977 case ICV_SECOND_OF_COND:
978 warning (0, "implicit dereference will not access object "
979 "of type %qT in second operand of "
980 "conditional expression", type);
982 case ICV_THIRD_OF_COND:
983 warning (0, "implicit dereference will not access object "
984 "of type %qT in third operand of "
985 "conditional expression", type);
987 case ICV_RIGHT_OF_COMMA:
988 warning (0, "implicit dereference will not access object "
989 "of type %qT in right operand of "
990 "comma operator", type);
992 case ICV_LEFT_OF_COMMA:
993 warning (0, "implicit dereference will not access object "
994 "of type %qT in left operand of comma operator",
998 warning (0, "implicit dereference will not access object "
999 "of type %qT in statement", type);
1001 case ICV_THIRD_IN_FOR:
1002 warning (0, "implicit dereference will not access object "
1003 "of type %qT in for increment expression",
1010 else if (is_volatile && TREE_ADDRESSABLE (type))
1012 if (complain & tf_warning)
1016 warning (0, "conversion to void will not access "
1017 "object of non-trivially-copyable type %qT",
1020 case ICV_SECOND_OF_COND:
1021 warning (0, "indirection will not access object of "
1022 "non-trivially-copyable type %qT in second "
1023 "operand of conditional expression", type);
1025 case ICV_THIRD_OF_COND:
1026 warning (0, "indirection will not access object of "
1027 "non-trivially-copyable type %qT in third "
1028 "operand of conditional expression", type);
1030 case ICV_RIGHT_OF_COMMA:
1031 warning (0, "indirection will not access object of "
1032 "non-trivially-copyable type %qT in right "
1033 "operand of comma operator", type);
1035 case ICV_LEFT_OF_COMMA:
1036 warning (0, "indirection will not access object of "
1037 "non-trivially-copyable type %qT in left "
1038 "operand of comma operator", type);
1041 warning (0, "indirection will not access object of "
1042 "non-trivially-copyable type %qT in statement",
1045 case ICV_THIRD_IN_FOR:
1046 warning (0, "indirection will not access object of "
1047 "non-trivially-copyable type %qT in for "
1048 "increment expression", type);
1054 if (is_reference || !is_volatile || !is_complete || TREE_ADDRESSABLE (type))
1056 /* Emit a warning (if enabled) when the "effect-less" INDIRECT_REF
1057 operation is stripped off. Note that we don't warn about
1058 - an expression with TREE_NO_WARNING set. (For an example of
1059 such expressions, see build_over_call in call.c.)
1060 - automatic dereferencing of references, since the user cannot
1061 control it. (See also warn_if_unused_value() in stmt.c.) */
1062 if (warn_unused_value
1063 && implicit != ICV_CAST
1064 && (complain & tf_warning)
1065 && !TREE_NO_WARNING (expr)
1067 warning (OPT_Wunused_value, "value computed is not used");
1068 expr = TREE_OPERAND (expr, 0);
1076 /* External variables might be incomplete. */
1077 tree type = TREE_TYPE (expr);
1078 int is_complete = COMPLETE_TYPE_P (complete_type (type));
1080 if (TYPE_VOLATILE (type) && !is_complete && (complain & tf_warning))
1084 warning (0, "conversion to void will not access "
1085 "object %qE of incomplete type %qT", expr, type);
1087 case ICV_SECOND_OF_COND:
1088 warning (0, "variable %qE of incomplete type %qT will not "
1089 "be accessed in second operand of "
1090 "conditional expression", expr, type);
1092 case ICV_THIRD_OF_COND:
1093 warning (0, "variable %qE of incomplete type %qT will not "
1094 "be accessed in third operand of "
1095 "conditional expression", expr, type);
1097 case ICV_RIGHT_OF_COMMA:
1098 warning (0, "variable %qE of incomplete type %qT will not "
1099 "be accessed in right operand of comma operator",
1102 case ICV_LEFT_OF_COMMA:
1103 warning (0, "variable %qE of incomplete type %qT will not "
1104 "be accessed in left operand of comma operator",
1108 warning (0, "variable %qE of incomplete type %qT will not "
1109 "be accessed in statement", expr, type);
1111 case ICV_THIRD_IN_FOR:
1112 warning (0, "variable %qE of incomplete type %qT will not "
1113 "be accessed in for increment expression",
1124 /* Don't bother with the temporary object returned from a function if
1125 we don't use it and don't need to destroy it. We'll still
1126 allocate space for it in expand_call or declare_return_variable,
1127 but we don't need to track it through all the tree phases. */
1128 if (TARGET_EXPR_IMPLICIT_P (expr)
1129 && TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (expr)))
1131 tree init = TARGET_EXPR_INITIAL (expr);
1132 if (TREE_CODE (init) == AGGR_INIT_EXPR
1133 && !AGGR_INIT_VIA_CTOR_P (init))
1135 tree fn = AGGR_INIT_EXPR_FN (init);
1136 expr = build_call_array_loc (input_location,
1137 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
1139 aggr_init_expr_nargs (init),
1140 AGGR_INIT_EXPR_ARGP (init));
1147 expr = resolve_nondeduced_context (expr);
1151 if (TREE_CODE (probe) == ADDR_EXPR)
1152 probe = TREE_OPERAND (expr, 0);
1153 if (type_unknown_p (probe))
1155 /* [over.over] enumerates the places where we can take the address
1156 of an overloaded function, and this is not one of them. */
1157 if (complain & tf_error)
1161 error ("conversion to void "
1162 "cannot resolve address of overloaded function");
1164 case ICV_SECOND_OF_COND:
1165 error ("second operand of conditional expression "
1166 "cannot resolve address of overloaded function");
1168 case ICV_THIRD_OF_COND:
1169 error ("third operand of conditional expression "
1170 "cannot resolve address of overloaded function");
1172 case ICV_RIGHT_OF_COMMA:
1173 error ("right operand of comma operator "
1174 "cannot resolve address of overloaded function");
1176 case ICV_LEFT_OF_COMMA:
1177 error ("left operand of comma operator "
1178 "cannot resolve address of overloaded function");
1182 "cannot resolve address of overloaded function");
1184 case ICV_THIRD_IN_FOR:
1185 error ("for increment expression "
1186 "cannot resolve address of overloaded function");
1190 return error_mark_node;
1191 expr = void_zero_node;
1193 else if (implicit != ICV_CAST && probe == expr && is_overloaded_fn (probe))
1195 /* Only warn when there is no &. */
1196 if (complain & tf_warning)
1199 case ICV_SECOND_OF_COND:
1200 warning (OPT_Waddress,
1201 "second operand of conditional expression "
1202 "is a reference, not call, to function %qE", expr);
1204 case ICV_THIRD_OF_COND:
1205 warning (OPT_Waddress,
1206 "third operand of conditional expression "
1207 "is a reference, not call, to function %qE", expr);
1209 case ICV_RIGHT_OF_COMMA:
1210 warning (OPT_Waddress,
1211 "right operand of comma operator "
1212 "is a reference, not call, to function %qE", expr);
1214 case ICV_LEFT_OF_COMMA:
1215 warning (OPT_Waddress,
1216 "left operand of comma operator "
1217 "is a reference, not call, to function %qE", expr);
1220 warning (OPT_Waddress,
1221 "statement is a reference, not call, to function %qE",
1224 case ICV_THIRD_IN_FOR:
1225 warning (OPT_Waddress,
1226 "for increment expression "
1227 "is a reference, not call, to function %qE", expr);
1233 if (TREE_CODE (expr) == COMPONENT_REF)
1234 expr = TREE_OPERAND (expr, 0);
1238 if (expr != error_mark_node && !VOID_TYPE_P (TREE_TYPE (expr)))
1240 if (implicit != ICV_CAST
1241 && warn_unused_value
1242 && !TREE_NO_WARNING (expr)
1243 && !processing_template_decl)
1245 /* The middle end does not warn about expressions that have
1246 been explicitly cast to void, so we must do so here. */
1247 if (!TREE_SIDE_EFFECTS (expr)) {
1248 if (complain & tf_warning)
1251 case ICV_SECOND_OF_COND:
1252 warning (OPT_Wunused_value,
1253 "second operand of conditional expression has no effect");
1255 case ICV_THIRD_OF_COND:
1256 warning (OPT_Wunused_value,
1257 "third operand of conditional expression has no effect");
1259 case ICV_RIGHT_OF_COMMA:
1260 warning (OPT_Wunused_value,
1261 "right operand of comma operator has no effect");
1263 case ICV_LEFT_OF_COMMA:
1264 warning (OPT_Wunused_value,
1265 "left operand of comma operator has no effect");
1268 warning (OPT_Wunused_value,
1269 "statement has no effect");
1271 case ICV_THIRD_IN_FOR:
1272 warning (OPT_Wunused_value,
1273 "for increment expression has no effect");
1282 enum tree_code code;
1283 enum tree_code_class tclass;
1286 /* We might like to warn about (say) "(int) f()", as the
1287 cast has no effect, but the compiler itself will
1288 generate implicit conversions under some
1289 circumstances. (For example a block copy will be
1290 turned into a call to "__builtin_memcpy", with a
1291 conversion of the return value to an appropriate
1292 type.) So, to avoid false positives, we strip
1293 conversions. Do not use STRIP_NOPs because it will
1294 not strip conversions to "void", as that is not a
1295 mode-preserving conversion. */
1296 while (TREE_CODE (e) == NOP_EXPR)
1297 e = TREE_OPERAND (e, 0);
1299 code = TREE_CODE (e);
1300 tclass = TREE_CODE_CLASS (code);
1301 if ((tclass == tcc_comparison
1302 || tclass == tcc_unary
1303 || (tclass == tcc_binary
1304 && !(code == MODIFY_EXPR
1305 || code == INIT_EXPR
1306 || code == PREDECREMENT_EXPR
1307 || code == PREINCREMENT_EXPR
1308 || code == POSTDECREMENT_EXPR
1309 || code == POSTINCREMENT_EXPR)))
1310 && (complain & tf_warning))
1311 warning (OPT_Wunused_value, "value computed is not used");
1314 expr = build1 (CONVERT_EXPR, void_type_node, expr);
1316 if (! TREE_SIDE_EFFECTS (expr))
1317 expr = void_zero_node;
1321 /* Create an expression whose value is that of EXPR,
1322 converted to type TYPE. The TREE_TYPE of the value
1323 is always TYPE. This function implements all reasonable
1324 conversions; callers should filter out those that are
1325 not permitted by the language being compiled.
1327 Most of this routine is from build_reinterpret_cast.
1329 The back end cannot call cp_convert (what was convert) because
1330 conversions to/from basetypes may involve memory references
1331 (vbases) and adding or subtracting small values (multiple
1332 inheritance), but it calls convert from the constant folding code
1333 on subtrees of already built trees after it has ripped them apart.
1335 Also, if we ever support range variables, we'll probably also have to
1336 do a little bit more work. */
1339 convert (tree type, tree expr)
1343 if (type == error_mark_node || expr == error_mark_node)
1344 return error_mark_node;
1346 intype = TREE_TYPE (expr);
1348 if (POINTER_TYPE_P (type) && POINTER_TYPE_P (intype))
1349 return fold_if_not_in_template (build_nop (type, expr));
1351 return ocp_convert (type, expr, CONV_OLD_CONVERT,
1352 LOOKUP_NORMAL|LOOKUP_NO_CONVERSION);
1355 /* Like cp_convert, except permit conversions to take place which
1356 are not normally allowed due to access restrictions
1357 (such as conversion from sub-type to private super-type). */
1360 convert_force (tree type, tree expr, int convtype)
1363 enum tree_code code = TREE_CODE (type);
1365 if (code == REFERENCE_TYPE)
1366 return (fold_if_not_in_template
1367 (convert_to_reference (type, e, CONV_C_CAST, LOOKUP_COMPLAIN,
1370 if (code == POINTER_TYPE)
1371 return fold_if_not_in_template (convert_to_pointer_force (type, e));
1373 /* From typeck.c convert_for_assignment */
1374 if (((TREE_CODE (TREE_TYPE (e)) == POINTER_TYPE && TREE_CODE (e) == ADDR_EXPR
1375 && TREE_CODE (TREE_TYPE (e)) == POINTER_TYPE
1376 && TREE_CODE (TREE_TYPE (TREE_TYPE (e))) == METHOD_TYPE)
1377 || integer_zerop (e)
1378 || TYPE_PTRMEMFUNC_P (TREE_TYPE (e)))
1379 && TYPE_PTRMEMFUNC_P (type))
1380 /* compatible pointer to member functions. */
1381 return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), e, 1,
1382 /*c_cast_p=*/1, tf_warning_or_error);
1384 return ocp_convert (type, e, CONV_C_CAST|convtype, LOOKUP_NORMAL);
1387 /* Convert an aggregate EXPR to type XTYPE. If a conversion
1388 exists, return the attempted conversion. This may
1389 return ERROR_MARK_NODE if the conversion is not
1390 allowed (references private members, etc).
1391 If no conversion exists, NULL_TREE is returned.
1393 FIXME: Ambiguity checking is wrong. Should choose one by the implicit
1394 object parameter, or by the second standard conversion sequence if
1395 that doesn't do it. This will probably wait for an overloading rewrite.
1399 build_type_conversion (tree xtype, tree expr)
1401 /* C++: check to see if we can convert this aggregate type
1402 into the required type. */
1403 return build_user_type_conversion (xtype, expr, LOOKUP_NORMAL);
1406 /* Convert the given EXPR to one of a group of types suitable for use in an
1407 expression. DESIRES is a combination of various WANT_* flags (q.v.)
1408 which indicates which types are suitable. If COMPLAIN is true, complain
1409 about ambiguity; otherwise, the caller will deal with it. */
1412 build_expr_type_conversion (int desires, tree expr, bool complain)
1414 tree basetype = TREE_TYPE (expr);
1415 tree conv = NULL_TREE;
1416 tree winner = NULL_TREE;
1418 if (expr == null_node
1419 && (desires & WANT_INT)
1420 && !(desires & WANT_NULL))
1421 warning_at (input_location, OPT_Wconversion_null,
1422 "converting NULL to non-pointer type");
1424 basetype = TREE_TYPE (expr);
1426 if (basetype == error_mark_node)
1427 return error_mark_node;
1429 if (! MAYBE_CLASS_TYPE_P (basetype))
1430 switch (TREE_CODE (basetype))
1433 if ((desires & WANT_NULL) && null_ptr_cst_p (expr))
1435 /* else fall through... */
1438 return (desires & WANT_INT) ? expr : NULL_TREE;
1440 return (desires & WANT_ENUM) ? expr : NULL_TREE;
1442 return (desires & WANT_FLOAT) ? expr : NULL_TREE;
1444 return (desires & WANT_POINTER) ? expr : NULL_TREE;
1448 return (desires & WANT_POINTER) ? decay_conversion (expr)
1453 if ((desires & WANT_VECTOR_OR_COMPLEX) == 0)
1455 switch (TREE_CODE (TREE_TYPE (basetype)))
1459 return (desires & WANT_INT) ? expr : NULL_TREE;
1461 return (desires & WANT_ENUM) ? expr : NULL_TREE;
1463 return (desires & WANT_FLOAT) ? expr : NULL_TREE;
1472 /* The code for conversions from class type is currently only used for
1473 delete expressions. Other expressions are handled by build_new_op. */
1474 if (!complete_type_or_maybe_complain (basetype, expr, complain))
1475 return error_mark_node;
1476 if (!TYPE_HAS_CONVERSION (basetype))
1479 for (conv = lookup_conversions (basetype, /*lookup_template_convs_p=*/true);
1481 conv = TREE_CHAIN (conv))
1485 tree cand = TREE_VALUE (conv);
1486 cand = OVL_CURRENT (cand);
1488 if (winner && winner == cand)
1491 if (DECL_NONCONVERTING_P (cand))
1494 candidate = non_reference (TREE_TYPE (TREE_TYPE (cand)));
1496 switch (TREE_CODE (candidate))
1500 win = (desires & WANT_INT); break;
1502 win = (desires & WANT_ENUM); break;
1504 win = (desires & WANT_FLOAT); break;
1506 win = (desires & WANT_POINTER); break;
1510 if ((desires & WANT_VECTOR_OR_COMPLEX) == 0)
1512 switch (TREE_CODE (TREE_TYPE (candidate)))
1516 win = (desires & WANT_INT); break;
1518 win = (desires & WANT_ENUM); break;
1520 win = (desires & WANT_FLOAT); break;
1536 error ("ambiguous default type conversion from %qT",
1538 error (" candidate conversions include %qD and %qD",
1541 return error_mark_node;
1550 tree type = non_reference (TREE_TYPE (TREE_TYPE (winner)));
1551 return build_user_type_conversion (type, expr, LOOKUP_NORMAL);
1557 /* Implements integral promotion (4.1) and float->double promotion. */
1560 type_promotes_to (tree type)
1564 if (type == error_mark_node)
1565 return error_mark_node;
1567 type = TYPE_MAIN_VARIANT (type);
1569 /* Check for promotions of target-defined types first. */
1570 promoted_type = targetm.promoted_type (type);
1572 return promoted_type;
1574 /* bool always promotes to int (not unsigned), even if it's the same
1576 if (TREE_CODE (type) == BOOLEAN_TYPE)
1577 type = integer_type_node;
1579 /* Normally convert enums to int, but convert wide enums to something
1581 else if (TREE_CODE (type) == ENUMERAL_TYPE
1582 || type == char16_type_node
1583 || type == char32_type_node
1584 || type == wchar_type_node)
1586 int precision = MAX (TYPE_PRECISION (type),
1587 TYPE_PRECISION (integer_type_node));
1588 tree totype = c_common_type_for_size (precision, 0);
1589 if (TREE_CODE (type) == ENUMERAL_TYPE)
1590 type = ENUM_UNDERLYING_TYPE (type);
1591 if (TYPE_UNSIGNED (type)
1592 && ! int_fits_type_p (TYPE_MAX_VALUE (type), totype))
1593 type = c_common_type_for_size (precision, 1);
1597 else if (c_promoting_integer_type_p (type))
1599 /* Retain unsignedness if really not getting bigger. */
1600 if (TYPE_UNSIGNED (type)
1601 && TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
1602 type = unsigned_type_node;
1604 type = integer_type_node;
1606 else if (type == float_type_node)
1607 type = double_type_node;
1612 /* The routines below this point are carefully written to conform to
1613 the standard. They use the same terminology, and follow the rules
1614 closely. Although they are used only in pt.c at the moment, they
1615 should presumably be used everywhere in the future. */
1617 /* Attempt to perform qualification conversions on EXPR to convert it
1618 to TYPE. Return the resulting expression, or error_mark_node if
1619 the conversion was impossible. */
1622 perform_qualification_conversions (tree type, tree expr)
1626 expr_type = TREE_TYPE (expr);
1628 if (same_type_p (type, expr_type))
1630 else if (TYPE_PTR_P (type) && TYPE_PTR_P (expr_type)
1631 && comp_ptr_ttypes (TREE_TYPE (type), TREE_TYPE (expr_type)))
1632 return build_nop (type, expr);
1633 else if (TYPE_PTR_TO_MEMBER_P (type)
1634 && TYPE_PTR_TO_MEMBER_P (expr_type)
1635 && same_type_p (TYPE_PTRMEM_CLASS_TYPE (type),
1636 TYPE_PTRMEM_CLASS_TYPE (expr_type))
1637 && comp_ptr_ttypes (TYPE_PTRMEM_POINTED_TO_TYPE (type),
1638 TYPE_PTRMEM_POINTED_TO_TYPE (expr_type)))
1639 return build_nop (type, expr);
1641 return error_mark_node;