Commit f19319db by Gabriel Dos Reis Committed by Gabriel Dos Reis

re PR c++/5293 (confusing message when binding a temporary to a reference)

PR c++/5293
* call.c (initialize_reference): Improve diagnostic.

From-SVN: r69332
parent c573d965
2003-07-14 Gabriel Dos Reis <gdr@integrable-solutions.net>
PR c++/5293
* call.c (initialize_reference): Improve diagnostic.
2003-07-14 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/11154
......
......@@ -6035,7 +6035,13 @@ initialize_reference (tree type, tree expr, tree decl)
conv = reference_binding (type, TREE_TYPE (expr), expr, LOOKUP_NORMAL);
if (!conv || ICS_BAD_FLAG (conv))
{
error ("could not convert `%E' to `%T'", expr, type);
if (!(TYPE_QUALS (TREE_TYPE (type)) & TYPE_QUAL_CONST)
&& !real_lvalue_p (expr))
error ("invalid initialization of non-const reference of "
"type '%T' from a temporary of type '%T'",
type, TREE_TYPE (expr));
else
error ("could not convert `%E' to `%T'", expr, type);
return error_mark_node;
}
......
struct A {
A operator=(const A&);
};
A operator*(A, A);
A& operator+=(A& a, const A& b)
{
return a = a * b; // { dg-error "non-const reference" }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment