cvt.c (warn_ref_binding): New static function, broken out of ...

* cvt.c (warn_ref_binding): New static function, broken out of ...
	(convert_to_reference): ... here. Use it.

From-SVN: r35672
This commit is contained in:
Nathan Sidwell 2000-08-14 10:18:15 +00:00 committed by Nathan Sidwell
parent 08498793c0
commit 08aead780e
2 changed files with 42 additions and 25 deletions

View File

@ -1,3 +1,8 @@
2000-08-14 Nathan Sidwell <nathan@codesourcery.com>
* cvt.c (warn_ref_binding): New static function, broken out of ...
(convert_to_reference): ... here. Use it.
2000-08-11 Kriang Lerdsuwanakij <lerdsuwa@scf-fs.usc.edu> 2000-08-11 Kriang Lerdsuwanakij <lerdsuwa@scf-fs.usc.edu>
* parse.y (template_arg): Add rule for template qualified with * parse.y (template_arg): Add rule for template qualified with

View File

@ -38,6 +38,7 @@ Boston, MA 02111-1307, USA. */
static tree cp_convert_to_pointer PARAMS ((tree, tree)); static tree cp_convert_to_pointer PARAMS ((tree, tree));
static tree convert_to_pointer_force PARAMS ((tree, tree)); static tree convert_to_pointer_force PARAMS ((tree, tree));
static tree build_up_reference PARAMS ((tree, tree, int)); static tree build_up_reference PARAMS ((tree, tree, int));
static void warn_ref_binding PARAMS ((tree, tree, tree));
/* Change of width--truncation and extension of integers or reals-- /* Change of width--truncation and extension of integers or reals--
is represented with NOP_EXPR. Proper functioning of many things is represented with NOP_EXPR. Proper functioning of many things
@ -410,6 +411,37 @@ build_up_reference (type, arg, flags)
return rval; return rval;
} }
/* Subroutine of convert_to_reference. REFTYPE is the target reference type.
INTYPE is the original rvalue type and DECL is an optional _DECL node
for diagnostics.
[dcl.init.ref] says that if an rvalue is used to
initialize a reference, then the reference must be to a
non-volatile const type. */
static void
warn_ref_binding (reftype, intype, decl)
tree reftype, intype, decl;
{
tree ttl = TREE_TYPE (reftype);
if (!CP_TYPE_CONST_NON_VOLATILE_P (ttl))
{
const char *msg;
if (CP_TYPE_VOLATILE_P (ttl) && decl)
msg = "initialization of volatile reference type `%#T' from rvalue of type `%T'";
else if (CP_TYPE_VOLATILE_P (ttl))
msg = "conversion to volatile reference type `%#T' from rvalue of type `%T'";
else if (decl)
msg = "initialization of non-const reference type `%#T' from rvalue of type `%T'";
else
msg = "conversion to non-const reference type `%#T' from rvalue of type `%T'";
cp_pedwarn (msg, reftype, intype);
}
}
/* For C++: Only need to do one-level references, but cannot /* For C++: Only need to do one-level references, but cannot
get tripped up on signed/unsigned differences. get tripped up on signed/unsigned differences.
@ -472,27 +504,10 @@ convert_to_reference (reftype, expr, convtype, flags, decl)
tree ttl = TREE_TYPE (reftype); tree ttl = TREE_TYPE (reftype);
tree ttr = lvalue_type (expr); tree ttr = lvalue_type (expr);
/* [dcl.init.ref] says that if an rvalue is used to if (! real_lvalue_p (expr))
initialize a reference, then the reference must be to a warn_ref_binding (reftype, intype, decl);
non-volatile const type. */
if (! real_lvalue_p (expr) if (! (convtype & CONV_CONST)
&& !CP_TYPE_CONST_NON_VOLATILE_P (ttl))
{
const char *msg;
if (CP_TYPE_VOLATILE_P (ttl) && decl)
msg = "initialization of volatile reference type `%#T'";
else if (CP_TYPE_VOLATILE_P (ttl))
msg = "conversion to volatile reference type `%#T'";
else if (decl)
msg = "initialization of non-const reference type `%#T'";
else
msg = "conversion to non-const reference type `%#T'";
cp_pedwarn (msg, reftype);
cp_pedwarn ("from rvalue of type `%T'", intype);
}
else if (! (convtype & CONV_CONST)
&& !at_least_as_qualified_p (ttl, ttr)) && !at_least_as_qualified_p (ttl, ttr))
cp_pedwarn ("conversion from `%T' to `%T' discards qualifiers", cp_pedwarn ("conversion from `%T' to `%T' discards qualifiers",
ttr, reftype); ttr, reftype);
@ -528,11 +543,8 @@ convert_to_reference (reftype, expr, convtype, flags, decl)
"converting", 0, 0); "converting", 0, 0);
if (rval == NULL_TREE || rval == error_mark_node) if (rval == NULL_TREE || rval == error_mark_node)
return rval; return rval;
warn_ref_binding (reftype, intype, decl);
rval = build_up_reference (reftype, rval, flags); rval = build_up_reference (reftype, rval, flags);
if (rval && ! CP_TYPE_CONST_P (TREE_TYPE (reftype)))
cp_pedwarn ("initializing non-const `%T' with `%T' will use a temporary",
reftype, intype);
} }
if (rval) if (rval)