User account creation filtered due to spam.

Bug 13830 - Invalid covariant type for identical type, friend related
Summary: Invalid covariant type for identical type, friend related
Status: RESOLVED DUPLICATE of bug 1016
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: 4.0.1
Assignee: Kriang Lerdsuwanakij
Keywords: rejects-valid
Depends on: 1016
Blocks: 12944
  Show dependency treegraph
Reported: 2004-01-23 12:04 UTC by MattyT
Modified: 2005-05-22 14:06 UTC (History)
2 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2004-04-23 20:13:18


Note You need to log in before you can comment on or make changes to this bug.
Description MattyT 2004-01-23 12:04:19 UTC
The code below:

template < class TP >
class A {
  friend class X;
  typedef X * XP;
  class X {};
  virtual XP method();
template < class TP >
class B : public A< TP > {
  virtual typename A< TP >::XP method();
int main() {
  B<int> a;

gives the error in 3.4: In instantiation of `B<int>':   instantiated from here error: invalid covariant return type for `typename A<TP>::XP
B<TP>::method() [with TP = int]' error:   overriding `X* A<TP>::method() [with TP = int]'

as best as I can tell, the type is identical and so it should compile.
Comment 1 Wolfgang Bangerth 2004-01-23 16:26:02 UTC
Confirmed. Nathan, your call! 
Comment 2 Andrew Pinski 2004-04-23 20:13:18 UTC
Actually it looks like the problem has to do with friend classes.
If I add "class X {};" before the first template class, it works.
Comment 3 Wolfgang Bangerth 2004-04-24 05:30:04 UTC
Of course it has to do with friend classes. In the original code, 
in the friend declaration we look up X, don't find anything, and 
inject this name in the global namespace. When we later come back 
in the derived class, we see the friend declaration again, but this 
time we seem to know that the base class also has a member class X and 
think that the friend declaration corresponded to this. 
If you add a global class X to the snippet, then the name injection doesn't 
have to happen, and we seem to always believe that the friend declaration 
corresponds to the global class X. 
Comment 4 Kriang Lerdsuwanakij 2004-10-13 15:17:29 UTC
Working on friend injection issues.
Comment 5 Kriang Lerdsuwanakij 2004-12-28 15:29:49 UTC
The patch for PR1016 will also fix this bug.  That patch is ready 
and the plan is getting it in after GCC 4.0 is branched.  I am
closing this as a duplicate.

*** This bug has been marked as a duplicate of 1016 ***
Comment 6 Kriang Lerdsuwanakij 2005-05-22 11:42:47 UTC
Also fixed in GCC 4.0.1.