Bug 22884 - g++ becomes confused about private/public in templates.
Summary: g++ becomes confused about private/public in templates.
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc
Version: 7.0
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: David Lawrence
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2000-12-27 16:01 UTC by Need Real Name
Modified: 2007-04-18 16:30 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2000-12-29 13:44:23 UTC
Embargoed:


Attachments (Terms of Use)

Description Need Real Name 2000-12-27 16:01:35 UTC
This code fails to compile with gcc-c++-2.96-69:

file test.cc:
#include <vector>
 
class LAS;
template <class A>
class EmROMReader
{
  public: class DatabaseType { };
  private: typedef std::vector<DatabaseType> DatabaseList;
  public:
    bool ContainsDB(void) {
      EmROMReader<LAS>::DatabaseList::const_iterator i;
      return false;
    }
};


Compiling this code gives this error:
test.cc: In method `bool EmROMReader<A>::ContainsDB ()':
test.cc:8: `typedef class vector<EmROMReader<LAS>::DatabaseType,
allocator<EmROMReader<LAS>::DatabaseType> >
EmROMReader<LAS>::DatabaseList' is private
test.cc:11: within this context

I'm far from a c++ expert, but I assume one is able to use a private
type within a public method of the same class (otherwice I see little
value of private types). Making this a normal class works and compiling
it with h8300-hms-g++ v.2.95.2 works (it doesn't give any warning).

Comment 1 Jakub Jelinek 2000-12-29 13:44:19 UTC
Simplified testcase (with no need to include headers) is:
class foo {
public:
  typedef int a;
};
class bar;
template <class A>
class baz
{
  typedef foo b;
  public:
    void c(void) {
      baz<bar>::b::a i;
    }
};
I believe g++ is correct though, ISO C++ access control clauses speak about
same class, but you have a template and its instantiation, which are not
the same thing. If you either use only b::a or baz<A>::b::a instead, then
it will compile just fine.
I'll ask C++ experts though...

Comment 2 Jakub Jelinek 2000-12-30 21:03:42 UTC
Ok, Jason Merill (one of the 2 gcc C++ maintainers) confirumed that
your code is not valid C++, a template and its instantation are not
considered the same class when doing access control.


Note You need to log in before you can comment on or make changes to this bug.