This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/17177] New: Can not explicitly call protected superclass constructor in method


[jjamison@aspen ~/harmonia/src-main]$ /usr/misc/pkg/gcc-3.4.1/bin/gcc -Wall
/tmp/foo.cc
/tmp/foo.cc: In member function `C D::m()':
/tmp/foo.cc:3: error: `C::C(int)' is protected
/tmp/foo.cc:12: error: within this context
[jjamison@aspen ~/harmonia/src-main]$ /usr/misc/pkg/gcc-3.4.1/bin/gcc -v
Reading specs from
/.automount/project.EECS.Berkeley.EDU/vol/vol0/graham/b/sggs/local/x86-unknown-linux/pkg/gcc-3.4.1/bin/../lib/gcc/i686-pc-linux-gnu/3.4.1/specs
Configured with: ../gcc-3.4.1/configure --prefix=/usr/misc/pkg/gcc-3.4.1
--with-gnu-as --with-as=/usr/misc/bin/as --with-gnu-ld
--with-ld=/usr/misc/bin/ld --enable-threads --enable-languages=c,c++
Thread model: posix
gcc version 3.4.1
[jjamison@aspen ~/harmonia/src-main]$ uname -a
Linux aspen.CS.Berkeley.EDU 2.4.22-1.2188.nptl #1 Wed Apr 21 20:36:05 EDT 2004
i686 i686 i386 GNU/Linux

--------foo.cc--------
class C {
 protected:
  C(int) {}
  void n() {}
 public:
  C() {}
  C m() { n(); return C(3); }
};
class D : public C {
  D() : C() {}
 public:
  C m() { n(); return C(3); }
};

int main(void) {
  return 0;
}
------end foo.cc------

In D::m(), I call C::C(int).  C::C(int) is a protected member of the superclass.
 g++ does not allow me to call it.  However, I can call C::n(), which is also a
protected member of the superclass.  Futhermore, calling either of these in C is
fine, as evidenced by C::m().

Is there a special rule that says you can only call protected superclass
constructors from a constructor?  I could not find any documentation that said
that, but I may have missed it.

-- 
           Summary: Can not explicitly call protected superclass constructor
                    in method
           Product: gcc
           Version: 3.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jjamison at cs dot berkeley dot edu
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: x86-unknown-linux
  GCC host triplet: x86-unknown-linux
GCC target triplet: x86-unknown-linux


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]