public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/24592]  New: Static_cast loses access to protected
@ 2005-10-31 10:29 igodard at pacbell dot net
  2005-10-31 10:32 ` [Bug c++/24592] " igodard at pacbell dot net
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: igodard at pacbell dot net @ 2005-10-31 10:29 UTC (permalink / raw)
  To: gcc-bugs

The code:

template<typename T>
struct b1 {
protected:
    void    inc() {}
    T*      dummy;
    };
template<typename T, template<typename>class F>
struct b2 {
    void    f() {
        F<T>*   s = static_cast<F<T>*>(this);
        s->inc();
        }
    };

template<typename T>
struct G : public b1<T>, public b2<T, G> {

    };

int main() {
    G<int> g;
    g.f();
    }


gets you:

~/ootbc/members/src$ g++ foo.cc
foo.cc: In member function `void b2<T, F>::f() [with T = int, F = G]':
foo.cc:22:   instantiated from here
foo.cc:4: error: `void b1<T>::inc() [with T = int]' is protected
foo.cc:11: error: within this context

The access to "inc" is "s->inc()". "s" is a "F<T>", which after parameter 
substitution is a "G<int>". "b2<T, G>" is a public base of G, which after 
substitution means that "b2<int, G>" is a public base of "G<int>" and so is
also 
a public base of "s". Hence the protected member "b2<int, G>::inc" should be 
visible via "s", but is not.

Ivan


-- 
           Summary: Static_cast loses access to protected
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: igodard at pacbell dot net


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


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

* [Bug c++/24592] Static_cast loses access to protected
  2005-10-31 10:29 [Bug c++/24592] New: Static_cast loses access to protected igodard at pacbell dot net
@ 2005-10-31 10:32 ` igodard at pacbell dot net
  2005-10-31 15:32 ` pinskia at gcc dot gnu dot org
  2005-10-31 22:48 ` igodard at pacbell dot net
  2 siblings, 0 replies; 4+ messages in thread
From: igodard at pacbell dot net @ 2005-10-31 10:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from igodard at pacbell dot net  2005-10-31 10:32 -------
Sorry, screwed up the explanation. Should be:

The access to "inc" is "s->inc()". "s" is a "F<T>*", which after parameter 
substitution is a "G<int>*". "b1<T>" is a public base of G<T>, which after 
substitution means that "b1<int>" is a public base of "G<int>" and so is
also a public base of "s". Hence the protected member "b1<int>::inc" should be 
visible via "s", but is not.


-- 


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


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

* [Bug c++/24592] Static_cast loses access to protected
  2005-10-31 10:29 [Bug c++/24592] New: Static_cast loses access to protected igodard at pacbell dot net
  2005-10-31 10:32 ` [Bug c++/24592] " igodard at pacbell dot net
@ 2005-10-31 15:32 ` pinskia at gcc dot gnu dot org
  2005-10-31 22:48 ` igodard at pacbell dot net
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-10-31 15:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2005-10-31 15:32 -------
No, you cannot get around access checking like this.

b2 does not know anything about its super classes at all, and it should not
know anything about them.

Also the following applies:
b2 cannot access the stuff in another base class of G.
Like:
class b1{protected: int i;}  ;struct G; struct b2 { int f(G *); }; struct G:
b1, b2 {};  int b2::f(G *a){return a->i;}
is invalid as b2 cannot access b1's fields.


-- 

pinskia at gcc dot gnu dot org changed:

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


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


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

* [Bug c++/24592] Static_cast loses access to protected
  2005-10-31 10:29 [Bug c++/24592] New: Static_cast loses access to protected igodard at pacbell dot net
  2005-10-31 10:32 ` [Bug c++/24592] " igodard at pacbell dot net
  2005-10-31 15:32 ` pinskia at gcc dot gnu dot org
@ 2005-10-31 22:48 ` igodard at pacbell dot net
  2 siblings, 0 replies; 4+ messages in thread
From: igodard at pacbell dot net @ 2005-10-31 22:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from igodard at pacbell dot net  2005-10-31 22:48 -------
Ys of course; sorry :-(


-- 


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


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

end of thread, other threads:[~2005-10-31 22:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-31 10:29 [Bug c++/24592] New: Static_cast loses access to protected igodard at pacbell dot net
2005-10-31 10:32 ` [Bug c++/24592] " igodard at pacbell dot net
2005-10-31 15:32 ` pinskia at gcc dot gnu dot org
2005-10-31 22:48 ` igodard at pacbell dot net

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