This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

http://gcc.gnu.org/gcc-3.4/changes.html


Hi,

Giovanni Bajo asked me (se mail below) to provide a patch of
http://gcc.gnu.org/gcc-3.4/changes.html

I don't really know how to do that but here is the modified part:

    <li>In a template definition, unqualified names will no longer
        find members of a dependent base. For example,
        <pre>
        template &lt;typename T&gt; struct B {
          int m;
          int n;
          int f ();
          int g ();
        };
        int n;
        int g ();
        template &lt;typename T&gt; struct C : B&lt;T&gt; {
          void h ()
          {
            m = 0; // error
            f ();  // error
            n = 0; // ::n is modified
            g ();  // ::g is called
          }
        };</pre>
        <p>You must make the names dependent, e.g. by prefixing them
        with <code>this-&gt;</code>. Here is the corrected definition
        of <code>C&lt;T&gt;::h</code>,</p>
        <pre>
        template &lt;typename T&gt; void C&lt;T&gt;::h ()
        {
          this-&gt;m = 0;
          this-&gt;f ();
          this-&gt;n = 0
          this-&gt;g ();
        }</pre>
        <p>As an alternative solution, you may use <code>using</code>
        declarations instead of <code>this-&gt;</code>:</p>
        <pre>
        template &lt;typename T&gt; struct C : B&lt;T&gt; {
          using B&lt;T&gt;::m;
          using B&lt;T&gt;::f;
          using B&lt;T&gt;::n;
          using B&lt;T&gt;::g;
          void h ()
          {
            m = 0;
            f ();
            n = 0;
            g ();
          }
        };</pre></li>

BR,
Johan


-----Original Message-----
From: Giovanni Bajo [mailto:giovannibajo@libero.it]
Sent: den 18 september 2004 01:39
To: Johan Bergman (KI/EAB)
Cc: gcc@gcc.gnu.org
Subject: Re: Error on GCC 3.4 release web page


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]