Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-83242

Strange behavior with QSharedPointer

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P1: Critical
    • None
    • 5.9.5
    • Core: Other
    • None
    • Ubuntu 18.04.2 LTS
    • Linux/Other display system

    Description

      Qt version 5.9.5 on Ubuntu 18.04.2 LTS, compiling with g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0

       

      The following code, using std::shared_ptr, works:

      template<typename T> class ABase { };
      template<typename T> class BDerived : public ABase<T> { };
      
      class A
      {
      public:
          template<typename T>
          void f(std::shared_ptr<ABase<T>> x)
          {
              auto y = std::static_pointer_cast<BDerived<T>>(x);
          }
      };
      

       
      The same code, using QSharedPointer, does not compile:

      template<typename T> class ABase { };
      template<typename T> class BDerived : public ABase<T> { };
      
      class A
      {
      public:
          template<typename T>
          void f(QSharedPointer<ABase<T>> x)
          {
              auto y = x.staticCast<BDerived<T>>();
          }
      };
      

      It fails with:

      In member function 'void A::f(QSharedPointer<ABase<T> >)':
      
      error: expected primary-expression before '>' token
      
      auto y = x.staticCast<BDerived<T>>();;
      
      error: expected primary-expression before ')' token
      
      auto y = x.staticCast<BDerived<T>>();
      

       

      When function f() is rewritten as:

          void f(QSharedPointer<ABase<int>> x)
          {
              auto y = x.staticCast<BDerived<int>>();
          }
      

      It does compile fine.

       

       

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            nohup Tom Wimmenhove
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes