Bug 11711 - Inheritance from partially specialized template does not work
Summary: Inheritance from partially specialized template does not work
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: 3.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 11759 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-07-29 19:11 UTC by Geoffrey Furnish
Modified: 2005-07-23 22:49 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Geoffrey Furnish 2003-07-29 19:12:00 UTC
The following code will not compile under GCC 3.3, 3.3.1 (prerelease,
2003/07/20 snapshot), or 3.4 (cvs head as of 2003/07/29).

template<class H, class T> struct TL {};

template<class X> class Base;

template<class H, class T>
class Base< TL<H,T> >
{
  public:
    template<int I> void f() {}
};

template<class H, class T>
class Derived
    : public Base< TL<H,T> >
{
  public:
    void g()
    {
        f<1>();
    }
};

KCC 4.0f --strict compiles this code, which is some evidence that the code
is in fact legal.  The problem seems to be that class Derived isn't actually
inheriting from the specialized Base variant, or at least, name lookup
is failing to find the (template) member function f().
Comment 1 Mark Mitchell 2003-07-29 20:36:30 UTC
This is correct behavior per the standard.  

The base class is dependent; therefore name lookup does look into the base 
class.

See gcc/doc/trouble.texi for more information.
Comment 2 Geoffrey Furnish 2003-07-29 21:37:17 UTC
I stand corrected.  And thanks for pointing me to the explanation, as it was
good to be reminded of that.

However, if I make the suggested correction to the call site to make
the reference dependent, GCC still fails to compile the (corrected) code.

For example, if we try

template<class H, class T>
class Derived
    : public Base< TL<H,T> >
{
  public:
    void g()
    {
        this->f<1>();
    }
};

Then gcc 3.3.1 (prerelease) gives:
/opt/gcc-3.3.1/bin/c++ -v -c x.cc
Reading specs from /opt/gcc-3.3.1/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/specs
Configured with: ./configure --prefix=/opt/gcc-3.3.1 : (reconfigured)
./configure --prefix=/opt/gcc-3.3.1 --enable-languages=c,c++,f77
Thread model: posix
gcc version 3.3.1 20030720 (prerelease)
...
x.cc: In member function `void Derived<H, T>::g()':
x.cc:20: error: parse error before `;' token

which I think is the same error message as before, and gcc 3.4 (cvs head) gives:

/opt/gcc-3.4/bin/c++ -v -c x.cc
Reading specs from /opt/gcc-3.4/lib/gcc-lib/i686-pc-linux-gnu/3.4/specs
Configured with: ./configure --prefix=/opt/gcc-3.4 : (reconfigured) ./configure
--prefix=/opt/gcc-3.4 --enable-languages=c,c++,f77,java
Thread model: posix
gcc version 3.4 20030729 (experimental)
...
x.cc: In member function `void Derived<H, T>::g()':
x.cc:20: error: expected primary-expression


Similarly, if we qualify the call site in this way:
template<class H, class T>
class Derived
    : public Base< TL<H,T> >
{
  public:
    void g()
    {
        Base< TL<H,T> >::f<1>();
    }
};

which if I understand the trouble.texi correctly, should also be a legal way
to introduce the dependency, then it still fails to compile with the same
errors as with this->, quoted above, for all versions of gcc 3.2 through 3.4.

Consequently, I am reopening the bug.
Comment 3 Andrew Pinski 2003-07-29 21:43:49 UTC
With icc 6.0 in strict mode (-Xc) icc rejects this after adding this-> or Base< TL<H,T> >:: before 
f<1>.
The code is still invalid as f is template but the standard says it is not a template so adding 
template in front of f<1> fixes it.
template<class H, class T>
class Derived
    : public Base< TL<H,T> >
{
  public:
    void g()
    {
        Base< TL<H,T> >::template f<1>(); // or this->template  f<1>();
    }
};
Comment 4 Andrew Pinski 2003-08-01 10:57:23 UTC
*** Bug 11759 has been marked as a duplicate of this bug. ***