Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-17823

Wrong resolution of dynamic downcast in struct

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Not Evaluated
    • Qt Creator 4.3.0-beta1
    • Qt Creator 4.2.1
    • Debugger
    • None
    • GDB
    • fb213b5826519fed277487b296fc3504bf44de76

    Description

      struct Base1
      {
          virtual ~Base1() {}
          int foo = 42;
      };
      
      struct Base2
      {
          virtual ~Base2() {}
          int bar = 43;
      };
      
      struct Derived : Base1, Base2
      {
          int baz = 84;
      };
      
      struct Container
      {
          Container(Base2 *b) : b2(b) {}
          Base2 *b2;
      };
      
      int main(int argc, char *argv[])
      {
          Derived d;
          Container c(&d); // c.b2 has wrong address
          Base2 *b2 = &d; // This has the right address
          return 0;
      }

      If I understand correctly, the container calls nativeDynamicType, which uses direct casting, while the other one doesn't reach there.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            hjk hjk
            orgads Orgad Shaneh
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes