public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/23735] New: Visibility of template base class members
@ 2005-09-05 14:56 dreiners at iastate dot edu
  2005-09-05 15:01 ` [Bug c++/23735] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: dreiners at iastate dot edu @ 2005-09-05 14:56 UTC (permalink / raw)
  To: gcc-bugs

Hi everybody,

I'm running into some unexpected behavior with template base classes:

template <int Q>
struct A
{
   int a;
};

template <int Q>
struct B : public A<Q>
{
    B(void);
};

template <int Q>
B<Q>::B(void)
{
    a = 0;       // This doesn't work
    A<Q>::a = 0; // This does ...
    this->a = 0; // and so does this
}

gcc 3.4.2 says:

> test.cpp: In constructor `B<Q>::B()':
> test.cpp:23: error: `a' undeclared (first use this function)
> test.cpp:23: error: (Each undeclared identifier is reported only once
> for each function it appears in.)

gcc 4.1.0 says:

> test.cpp: In constructor 'B<Q>::B()':
> test.cpp:22: error: 'a' was not declared in this scope

It works fine with VS.Net and Intel compilers. 

This was tested with the following systems:

gcc 3:
Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/
usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-
system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-
awt=gtk --host=i386-redhat-linux
Thread model: posix
gcc version 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)

gcc 4:
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc/configure --prefix=/opt/gcc-4.0 --with-gcc-version-
trigger=/opt/gcc-4.0/gcc/gcc/version.c --enable-languages=c,c++
Thread model: posix
gcc version 4.1.0 20050727 (experimental)

Thanks for your help!

   Dirk

-- 
           Summary: Visibility of template base class members
           Product: gcc
           Version: 3.4.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dreiners at iastate dot edu
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23735


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/23735] Visibility of template base class members
  2005-09-05 14:56 [Bug c++/23735] New: Visibility of template base class members dreiners at iastate dot edu
@ 2005-09-05 15:01 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-09-05 15:01 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-09-05 15:00 -------
Not a bug.  Read <http://gcc.gnu.org/gcc-3.4/changes.html>:
In a template definition, unqualified names will no longer find members of a dependent base (as 
specified by [temp.dep]/3 in the C++ standard). 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, e.g. 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 ();
        }
As an alternative solution (unfortunately not backwards compatible with GCC 3.3), you may use using 
declarations instead of this->:

        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 ();
          }
        };

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23735


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-09-05 15:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-05 14:56 [Bug c++/23735] New: Visibility of template base class members dreiners at iastate dot edu
2005-09-05 15:01 ` [Bug c++/23735] " pinskia at gcc dot gnu dot org

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).