This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Backporting to 4_0 the latest friend bits
- From: Kriang Lerdsuwanakij <lerdsuwa at users dot sourceforge dot net>
- To: pcarlini at suse dot de, Joe dot Buck at synopsys dot COM, mark at codesourcery dot com,gcc at gcc dot gnu dot org, matz at suse dot de
- Date: Sat, 30 Apr 2005 19:47:30 +0700
- Subject: Re: Backporting to 4_0 the latest friend bits
Joe Buck wrote:
>I don't quite understand your answer. It seems that (a) is the important
>issue; if the programs are valid, they compiled before, and they worked
>before, then it seems there really is a regression, even if we can argue
>that we were "right by accident" in the past.
>
This is a clarification of code validity issue: using sample code from
PR21235:
class KopeteAwayDialog { KopeteAwayDialog(); };
namespace Kopete
{
class Away
{
friend class KopeteAwayDialog;
};
}
using namespace Kopete;
KopeteAwayDialog::KopeteAwayDialog(){}
Sure, this code compiles with 4.1 and 3.4 but doesn't compile with 4.0.
Although the code is valid, I'd bet it doesn't work the way the
programmer of the above code (or other 99% who doesn't track
the standard closely) would expect.
In the above code, according to 4.0 and 4.1, there are actually
two 'KopeteAwayDialog' classes: 'Away::KopeteAwayDialog' and
'::KopeteAwayDialog'. Only the former is a friend of class 'Away'.
The later, with class and constructor defined by programmer, still cannot
access any private/protected member of 'Away'.
Simple fix is changing the friend declaration to:
friend class ::KopeteAwayDialog;
which is what programmer intend and should work on all versions
of GCC, new or old.
--Kriang