https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64077

            Bug ID: 64077
           Summary: dynamic_cast incorrectly rejected for private base
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc at dixie dot net.nz

I believe this is rejects-valid:

class Base { public: virtual ~Base () {} };
class Derived: virtual Base { public: virtual ~Derived() {} };
class D2: virtual public Base, public Derived { public: D2() {} ~D2() {} };

#include <cassert>
int main ()
{
        Derived *p = new D2;
        assert(dynamic_cast<Base *>(p)); // unexpected error: ‘Base’ is an
inaccessible base of ‘Derived’
}


The following lookup_base call should not issue errors.  Also it should do
access checks at global scope, not using friendship or access rights granted by
the local scope.

--- orig/gcc/cp/rtti.c     2014-06-13 08:47:08.000000000 +1200
+++ new/gcc/cp/rtti.c       2014-11-25 19:13:06.656252034 +1300
@@ -626,8 +626,8 @@ build_dynamic_cast_1 (tree type, tree ex
      convert statically.  */
   {
     tree binfo = lookup_base (TREE_TYPE (exprtype), TREE_TYPE (type),
-                             ba_check, NULL, complain);
-    if (binfo)
+                             ba_check | ba_ignore_scope, NULL, 0);
+    if (binfo && binfo != error_mark_node)
       return build_static_cast (type, expr, complain);
   }

Reply via email to