This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: patch reversion request
- From: Matt Austern <austern at apple dot com>
- To: Mark Mitchell <mark at codesourcery dot com>
- Cc: Nathan Sidwell <nathan at codesourcery dot com>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, "jason at redhat dot com" <jason at redhat dot com>
- Date: Thu, 12 Sep 2002 16:29:46 -0700
- Subject: Re: patch reversion request
On Thursday, September 12, 2002, at 11:51 AM, Mark Mitchell wrote:
The attached patch breaks the following well formed C++,
void baz (const long &)
void foo (int a)
{
baz((long)a);
}
which is a regresion. see gnats prs 7828 & 7858
OK, I understand what's going on. I see two ways to
fix it. I'm writing to see if people have opinions about
which one is better. (If you don't like either one, I
could probably come up with a third.)
What's happening is that we've got error checking in
build_unary_op to verify that the thing you're applying
& to is really an lvalue. We certainly want to do that
error checking for user code.
The compiler is calling build_unary_op as part of the
pass-by-reference mechanism. It checks to see if it
needs a temporary. If not, it just calls build_unary_op.
The trouble is that the check to see whether or not it
needs a temporary isn't quite the same as the error-
checking in build_unary_op. So convert_like_real
thinks that int and long are so similar that no temporary
is necessary, but build_unary_op disagrees.
OK, so here are my two options:
1. Change the check in convert_like_real, so that a
cast like static_cast<long>(a) is treated as something
that needs a temporary. This is a trivial one-line change.
2. Add a parameter to build_unary_op telling it that it's
it's not dealing with user code and it doesn't need to
worry about error checking. Conceptually easy, but
involves touching more lines of code.
I prefer option 1. Opinions?
(Either way, of course, I'll also check in a new regression
test case.)
--Matt