public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/32519]  New: g++ allows access to protected template member functions of base class
@ 2007-06-27  2:56 gsayfan at numenta dot com
  2007-06-27 19:01 ` [Bug c++/32519] [4.1/4.2/4.3 regression] " bangerth at dealii dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: gsayfan at numenta dot com @ 2007-06-27  2:56 UTC (permalink / raw)
  To: gcc-bugs

Derived classes may access protected members of their base class only on
themselves or other instances of the same type or derived type. Here is a link
to the relevant section in the draft of the C++ standard:

http://www.csci.csusb.edu/dick/c++std/cd2/access.html#class.protected

I don't have access to the actual standard, but I figure you do :-).

The bug occurs when the protected member is a template member function. If the
protected member is a simple data member the code fails to compile as it
should.

BTW, VC++ 2005 catches this bug and refuses to compile the test program.

Test Program (bug.cpp)
----------------------
struct B
{
protected:
  template <typename T>
  T getX()
  {
    return T(x);
  }
protected:
  int x;
};

struct D : public B
{
  D(B * b)
  {
    //x = b->x;         // fails to compile (correct)
    x = b->getX<int>(); // doesn't fail to compile (bug)
  }
};

int main (int argc, char * const argv[]) 
{
  B b;
  D d(&b);
}

Output of gcc -v
----------------
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../src/gcc-4.0.2/configure  : (reconfigured)
../src/gcc-4.0.2/configure 
Thread model: posix
gcc version 4.0.2

Build command
-------------
g++ -Wall bug.cpp -o bug


-- 
           Summary: g++ allows access to protected template member functions
                    of base class
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gsayfan at numenta dot com


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


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

end of thread, other threads:[~2008-12-04 15:06 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-27  2:56 [Bug c++/32519] New: g++ allows access to protected template member functions of base class gsayfan at numenta dot com
2007-06-27 19:01 ` [Bug c++/32519] [4.1/4.2/4.3 regression] " bangerth at dealii dot org
2007-07-04  3:31 ` mmitchel at gcc dot gnu dot org
2007-07-20  3:52 ` mmitchel at gcc dot gnu dot org
2007-10-09 19:30 ` mmitchel at gcc dot gnu dot org
2008-02-01 17:05 ` jsm28 at gcc dot gnu dot org
2008-05-19 20:27 ` [Bug c++/32519] [4.1/4.2/4.3/4.4 " jsm28 at gcc dot gnu dot org
2008-07-04 22:48 ` [Bug c++/32519] [4.2/4.3/4.4 " jsm28 at gcc dot gnu dot org
2008-09-05 13:24 ` fabien dot chene at gmail dot com
2008-11-28 22:27 ` jason at gcc dot gnu dot org
2008-12-04 15:06 ` jason 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).