This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: C++ PATCH: Fix PR 5293 (regression)
Mark Mitchell <mark@codesourcery.com> writes:
| On Tue, 2003-07-08 at 00:46, Gabriel Dos Reis wrote:
| > Jason Merrill <jason@redhat.com> writes:
| >
| > | FYI, I've been told in the past that substituting pieces of text makes life
| > | difficult for translators.
| > |
| > | Also, it seems to me that the interesting case is the one where we are
| > | trying to initialize a non-const reference from an rvalue, either because
| > | we explicitly wrote an rvalue or because we need a conversion which
| > | produces an rvalue. You should test for this with NEED_TEMPORARY_P, not
| > | real_lvalue_p.
| > |
| > | For other cases, the old error message is correct; telling people that the
| > | argument is an lvalue doesn't help them to find the problem with their
| > | code.
| >
| > Thank you very much for your comments. I'll incorporate them in the
| > revised patch and apply it; Mark, does that sound OK for you?
|
| Sure.
Here is the final version I committed to mainline.
It is up to you to decide whether you want it for GCC-3.3.1 or not.
Thanks,
-- Gaby
Index: cp/ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/ChangeLog,v
retrieving revision 1.3518
diff -p -r1.3518 ChangeLog
*** cp/ChangeLog 14 Jul 2003 10:48:55 -0000 1.3518
--- cp/ChangeLog 14 Jul 2003 15:00:52 -0000
***************
*** 1,3 ****
--- 1,8 ----
+ 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
Index: cp/call.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/call.c,v
retrieving revision 1.405
diff -p -r1.405 call.c
*** cp/call.c 14 Jul 2003 03:04:24 -0000 1.405
--- cp/call.c 14 Jul 2003 15:01:02 -0000
*************** initialize_reference (tree type, tree ex
*** 6035,6041 ****
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);
return error_mark_node;
}
--- 6035,6047 ----
conv = reference_binding (type, TREE_TYPE (expr), expr, LOOKUP_NORMAL);
if (!conv || ICS_BAD_FLAG (conv))
{
! 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;
}
Index: testsuite/g++.dg/init/ref8.C
===================================================================
RCS file: testsuite/g++.dg/init/ref8.C
diff -N testsuite/g++.dg/init/ref8.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/init/ref8.C 14 Jul 2003 15:01:04 -0000
***************
*** 0 ****
--- 1,10 ----
+ 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" }
+ }