public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/16147] New: dynamic_cast fails to enforce accesssibility
@ 2004-06-22 22:58 gdr at gcc dot gnu dot org
  2004-06-23 13:19 ` [Bug c++/16147] " bangerth at dealii dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: gdr at gcc dot gnu dot org @ 2004-06-22 22:58 UTC (permalink / raw)
  To: gcc-bugs

Consider the following program

#include <assert.h>

struct A { virtual ~A() { } };

struct B : A { };

A* f() {
   struct C : private B {

      A* g() { return this; }
   };

   return (new C)->g();
}

int main()
{
   assert(dynamic_cast<B*>(f()) == 0);
}


According to 5.2.7/8, I believe the assert should pass.
I'm seeing this behaviour on GCC-3.3.x and probably before that too.

-- 
           Summary: dynamic_cast fails to enforce accesssibility
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gdr at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: plateform independent


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


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

* [Bug c++/16147] dynamic_cast fails to enforce accesssibility
  2004-06-22 22:58 [Bug c++/16147] New: dynamic_cast fails to enforce accesssibility gdr at gcc dot gnu dot org
@ 2004-06-23 13:19 ` bangerth at dealii dot org
  2004-08-29 15:17 ` gdr at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: bangerth at dealii dot org @ 2004-06-23 13:19 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-06-23 13:18 -------
Just as additional data points: 
gcc2.95 passes the assertion 
gcc3.2.3 through mainline fail it 
icc7.1 and 8 fail it as well. 
 
I may be dense, but I somehow miss why you claim that it should pass. Can 
you elaborate? 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   GCC host triplet|plateform independent       |


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


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

* [Bug c++/16147] dynamic_cast fails to enforce accesssibility
  2004-06-22 22:58 [Bug c++/16147] New: dynamic_cast fails to enforce accesssibility gdr at gcc dot gnu dot org
  2004-06-23 13:19 ` [Bug c++/16147] " bangerth at dealii dot org
@ 2004-08-29 15:17 ` gdr at gcc dot gnu dot org
  2004-08-29 16:46 ` nathan at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: gdr at gcc dot gnu dot org @ 2004-08-29 15:17 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From gdr at gcc dot gnu dot org  2004-08-29 15:17 -------
(In reply to comment #1)
> Just as additional data points: 
> gcc2.95 passes the assertion 
> gcc3.2.3 through mainline fail it 
> icc7.1 and 8 fail it as well. 
>  
> I may be dense, but I somehow miss why you claim that it should pass. Can 
> you elaborate? 

5.2.7/8 states:

  The run-time check logically executes as follows:
  --- If, in the most derived object pointed (referred) to by v, v points 
      (refers) to a public base class subobject of a T object, and if only one 
      object of type T is derived from the sub-object pointed (referred) to by 
      v, the result is a pointer (an lvalue referring) to that T object.
 
  ---  Otherwise, if v points (refers) to a public base class sub-object of the 
       most derived object, and the type of the most derived object has a base 
       class, of type T, that is unambiguous and public, the result is a 
       pointer (an lvalue referring) to the T sub-object of the most derived
       object.

  --- Otherwise, the run-time check fails.

The reason the test should fail is that A is not a public base of the most
derived object (which is of type C).

-- Gaby


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nathan at codesourcery dot
                   |                            |com


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


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

* [Bug c++/16147] dynamic_cast fails to enforce accesssibility
  2004-06-22 22:58 [Bug c++/16147] New: dynamic_cast fails to enforce accesssibility gdr at gcc dot gnu dot org
  2004-06-23 13:19 ` [Bug c++/16147] " bangerth at dealii dot org
  2004-08-29 15:17 ` gdr at gcc dot gnu dot org
@ 2004-08-29 16:46 ` nathan at gcc dot gnu dot org
  2004-08-29 20:22 ` gdr at integrable-solutions dot net
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: nathan at gcc dot gnu dot org @ 2004-08-29 16:46 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From nathan at gcc dot gnu dot org  2004-08-29 16:46 -------
A need not be a public base of the most derived object.  (In this
hierarchy) it needs to be a public base of a B object, which it is.
Therefore the dynamic cast succeeds and the assert fails.
[5.2.7]/8 first bullet. 'v' is the A base, 'T' is the B base.

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


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


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

* [Bug c++/16147] dynamic_cast fails to enforce accesssibility
  2004-06-22 22:58 [Bug c++/16147] New: dynamic_cast fails to enforce accesssibility gdr at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2004-08-29 16:46 ` nathan at gcc dot gnu dot org
@ 2004-08-29 20:22 ` gdr at integrable-solutions dot net
  2004-08-29 20:31 ` gdr at gcc dot gnu dot org
  2004-08-29 20:34 ` gdr at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: gdr at integrable-solutions dot net @ 2004-08-29 20:22 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From gdr at integrable-solutions dot net  2004-08-29 20:22 -------
Subject: Re:  dynamic_cast fails to enforce accesssibility

"nathan at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes:

| A need not be a public base of the most derived object.  (In this
| hierarchy) it needs to be a public base of a B object, which it is.
| Therefore the dynamic cast succeeds and the assert fails.
| [5.2.7]/8 first bullet. 'v' is the A base, 'T' is the B base.

I don't think that the first bullet saysthe dynamic cast should succeed.
The most derived object here is of type C, not B.

-- Gaby


-- 


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


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

* [Bug c++/16147] dynamic_cast fails to enforce accesssibility
  2004-06-22 22:58 [Bug c++/16147] New: dynamic_cast fails to enforce accesssibility gdr at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2004-08-29 20:22 ` gdr at integrable-solutions dot net
@ 2004-08-29 20:31 ` gdr at gcc dot gnu dot org
  2004-08-29 20:34 ` gdr at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: gdr at gcc dot gnu dot org @ 2004-08-29 20:31 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From gdr at gcc dot gnu dot org  2004-08-29 20:31 -------
See comment #4

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


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


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

* [Bug c++/16147] dynamic_cast fails to enforce accesssibility
  2004-06-22 22:58 [Bug c++/16147] New: dynamic_cast fails to enforce accesssibility gdr at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2004-08-29 20:31 ` gdr at gcc dot gnu dot org
@ 2004-08-29 20:34 ` gdr at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: gdr at gcc dot gnu dot org @ 2004-08-29 20:34 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From gdr at gcc dot gnu dot org  2004-08-29 20:34 -------
Sorry, Nathan is right.

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


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


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

end of thread, other threads:[~2004-08-29 20:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-22 22:58 [Bug c++/16147] New: dynamic_cast fails to enforce accesssibility gdr at gcc dot gnu dot org
2004-06-23 13:19 ` [Bug c++/16147] " bangerth at dealii dot org
2004-08-29 15:17 ` gdr at gcc dot gnu dot org
2004-08-29 16:46 ` nathan at gcc dot gnu dot org
2004-08-29 20:22 ` gdr at integrable-solutions dot net
2004-08-29 20:31 ` gdr at gcc dot gnu dot org
2004-08-29 20:34 ` gdr 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).