Bug 22884 - g++ becomes confused about private/public in templates.
g++ becomes confused about private/public in templates.
Status: CLOSED NOTABUG
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
7.0
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
David Lawrence
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2000-12-27 11:01 EST by Need Real Name
Modified: 2007-04-18 12:30 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2000-12-29 08:44:23 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Need Real Name 2000-12-27 11:01:35 EST
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 08:44:19 EST
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 16:03:42 EST
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.