* RE: Error on GCC 3.4 release web page
@ 2004-09-17 23:38 Johan Bergman (KI/EAB)
2004-09-18 3:08 ` Giovanni Bajo
0 siblings, 1 reply; 3+ messages in thread
From: Johan Bergman (KI/EAB) @ 2004-09-17 23:38 UTC (permalink / raw)
To: 'gcc@gnu.org'
Hi again,
Maybe you could also mention the following alternative corrected definition of C<T>::h.
It might save a lot of work for those struggling to make their code GCC 3.4 compliant.
template <typename T> struct C : B<T> {
using B<T>::m;
using B<T>::f;
using B<T>::n;
using B<T>::g;
void h ()
{
m = 0;
f ();
n = 0;
g ();
}
};
BR,
Johan
-----Original Message-----
From: Johan Bergman (KI/EAB)
Sent: den 18 september 2004 00:07
To: 'gcc@gnu.org'
Subject: Error on GCC 3.4 release web page
Hi,
There seems to be an error in the following example, found on http://gcc.gnu.org/gcc-3.4/changes.html.
In a template definition, unqualified names will no longer find members of a dependent base. For example,
template <typename T> struct B {
int m;
int n;
int f ();
int g ();
};
int n;
int g ();
template <typename T> struct C : B<T> {
void g ()
{
m = 0; // error
f (); // error
n = 0; // ::n is modified
g (); // ::g is called
}
};
You must make the names dependent by prefixing them with this->. Here is the corrected definition of C<T>::g,
template <typename T> void C<T>::g ()
{
this->m = 0;
this->f ();
this->n = 0
this->g ();
}
The problem with the example is that the member function g() in C<T> calls itself. The following should work better:
In a template definition, unqualified names will no longer find members of a dependent base. For example,
template <typename T> struct B {
int m;
int n;
int f ();
int g ();
};
int n;
int g ();
template <typename T> struct C : B<T> {
void h ()
{
m = 0; // error
f (); // error
n = 0; // ::n is modified
g (); // ::g is called
}
};
You must make the names dependent by prefixing them with this->. Here is the corrected definition of C<T>::h,
template <typename T> void C<T>::h ()
{
this->m = 0;
this->f ();
this->n = 0
this->g ();
}
My only change was that 'g' was replaced with 'h' in three places (two in the code and one in the text).
BR,
Johan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Error on GCC 3.4 release web page
2004-09-17 23:38 Error on GCC 3.4 release web page Johan Bergman (KI/EAB)
@ 2004-09-18 3:08 ` Giovanni Bajo
0 siblings, 0 replies; 3+ messages in thread
From: Giovanni Bajo @ 2004-09-18 3:08 UTC (permalink / raw)
To: Johan Bergman (KI/EAB); +Cc: gcc
Johan Bergman (KI/EAB) wrote:
> There seems to be an error in the following example, found on
http://gcc.gnu.org/gcc-3.4/changes.html.
> The problem with the example is that the member function g() in C<T> calls
itself.
Actually the example is meant to show name lookup issue, not to have a proper
runtime behaviour. Anyway, I would not object renaming that function to avoid
any confusion for the user.
> Maybe you could also mention the following alternative corrected
> definition of C<T>::h.
> template <typename T> struct C : B<T> {
> using B<T>::m;
> using B<T>::f;
> using B<T>::n;
> using B<T>::g;
Makes sense. Can you please provide a patch against the HTML file, and post it
to gcc-patches@gcc.gnu.org?
Thanks,
Giovanni Bajo
^ permalink raw reply [flat|nested] 3+ messages in thread
* Error on GCC 3.4 release web page
@ 2004-09-17 23:35 Johan Bergman (KI/EAB)
0 siblings, 0 replies; 3+ messages in thread
From: Johan Bergman (KI/EAB) @ 2004-09-17 23:35 UTC (permalink / raw)
To: 'gcc@gnu.org'
Hi,
There seems to be an error in the following example, found on http://gcc.gnu.org/gcc-3.4/changes.html.
In a template definition, unqualified names will no longer find members of a dependent base. For example,
template <typename T> struct B {
int m;
int n;
int f ();
int g ();
};
int n;
int g ();
template <typename T> struct C : B<T> {
void g ()
{
m = 0; // error
f (); // error
n = 0; // ::n is modified
g (); // ::g is called
}
};
You must make the names dependent by prefixing them with this->. Here is the corrected definition of C<T>::g,
template <typename T> void C<T>::g ()
{
this->m = 0;
this->f ();
this->n = 0
this->g ();
}
The problem with the example is that the member function g() in C<T> calls itself. The following should work better:
In a template definition, unqualified names will no longer find members of a dependent base. For example,
template <typename T> struct B {
int m;
int n;
int f ();
int g ();
};
int n;
int g ();
template <typename T> struct C : B<T> {
void h ()
{
m = 0; // error
f (); // error
n = 0; // ::n is modified
g (); // ::g is called
}
};
You must make the names dependent by prefixing them with this->. Here is the corrected definition of C<T>::h,
template <typename T> void C<T>::h ()
{
this->m = 0;
this->f ();
this->n = 0
this->g ();
}
My only change was that 'g' was replaced with 'h' in three places (two in the code and one in the text).
BR,
Johan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-09-17 23:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-17 23:38 Error on GCC 3.4 release web page Johan Bergman (KI/EAB)
2004-09-18 3:08 ` Giovanni Bajo
-- strict thread matches above, loose matches on Subject: below --
2004-09-17 23:35 Johan Bergman (KI/EAB)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).