public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/17177] New: Can not explicitly call protected superclass constructor in method
@ 2004-08-24 20:45 jjamison at cs dot berkeley dot edu
  2004-08-24 22:45 ` [Bug c++/17177] " bangerth at dealii dot org
  2004-08-24 23:03 ` jjamison at cs dot berkeley dot edu
  0 siblings, 2 replies; 3+ messages in thread
From: jjamison at cs dot berkeley dot edu @ 2004-08-24 20:45 UTC (permalink / raw)
  To: gcc-bugs

[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


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

* [Bug c++/17177] Can not explicitly call protected superclass constructor in method
  2004-08-24 20:45 [Bug c++/17177] New: Can not explicitly call protected superclass constructor in method jjamison at cs dot berkeley dot edu
@ 2004-08-24 22:45 ` bangerth at dealii dot org
  2004-08-24 23:03 ` jjamison at cs dot berkeley dot edu
  1 sibling, 0 replies; 3+ messages in thread
From: bangerth at dealii dot org @ 2004-08-24 22:45 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-08-24 22:45 -------
Protected members are only accessible in derived classes when called through this->, 
not for any object. What you try is equivalent to 
---------------- 
class C  
{ 
  protected: 
    void foo(); 
}; 
 
class D : public C 
{ 
    void bar () 
      { 
	C c; 
	c.foo(); 
      } 
}; 
-------------------------------- 
which fails for the same reason. 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

* [Bug c++/17177] Can not explicitly call protected superclass constructor in method
  2004-08-24 20:45 [Bug c++/17177] New: Can not explicitly call protected superclass constructor in method jjamison at cs dot berkeley dot edu
  2004-08-24 22:45 ` [Bug c++/17177] " bangerth at dealii dot org
@ 2004-08-24 23:03 ` jjamison at cs dot berkeley dot edu
  1 sibling, 0 replies; 3+ messages in thread
From: jjamison at cs dot berkeley dot edu @ 2004-08-24 23:03 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jjamison at cs dot berkeley dot edu  2004-08-24 23:03 -------
I assume the previous comment should be modified to read:
Protected non-static members are ....
as the following works:
--------------
class C  
{ 
  protected: 
    static void foo(); 
}; 
 
class D : public C 
{ 
    void bar () 
      { 
        C c; 
        c.foo(); 
      } 
}; 

-- 


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


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

end of thread, other threads:[~2004-08-24 23:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-24 20:45 [Bug c++/17177] New: Can not explicitly call protected superclass constructor in method jjamison at cs dot berkeley dot edu
2004-08-24 22:45 ` [Bug c++/17177] " bangerth at dealii dot org
2004-08-24 23:03 ` jjamison at cs dot berkeley dot edu

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).