Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Warning: overrides a destructor but is not marked 'override'
Qt 6.11 is out! See what's new in the release blog

Warning: overrides a destructor but is not marked 'override'

Scheduled Pinned Locked Moved Solved C++ Gurus
11 Posts 4 Posters 10.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    saurabh162
    wrote on last edited by saurabh162
    #1

    Dear developers,

    I have derived SlaveThread class from QThread class and defined destructor of SlaveThread Class as follows:

    SlaveThread::~SlaveThread()
    {
        m_mutex.lock();
        m_quit = true;
        m_mutex.unlock();
        wait();
    }
    

    After compiling Qt code I get following error.

    '~SlaveThread()' overrides a destructor but is not marked 'override'
    

    Can you please inform me what can be reason and solution for above problem?

    Thank you very much :)

    J.HilkJ JonBJ 2 Replies Last reply
    0
    • S saurabh162

      Dear developers,

      I have derived SlaveThread class from QThread class and defined destructor of SlaveThread Class as follows:

      SlaveThread::~SlaveThread()
      {
          m_mutex.lock();
          m_quit = true;
          m_mutex.unlock();
          wait();
      }
      

      After compiling Qt code I get following error.

      '~SlaveThread()' overrides a destructor but is not marked 'override'
      

      Can you please inform me what can be reason and solution for above problem?

      Thank you very much :)

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @saurabh162 said in Warning: overrides a destructor but is not marked 'override':

      Can you please inform me what can be reason and solution for above problem?

      reason:
      https://www.geeksforgeeks.org/virtual-function-cpp/

      solution:

      public:
      ....
           ~SlaveThread() override;
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      5
      • S saurabh162

        Dear developers,

        I have derived SlaveThread class from QThread class and defined destructor of SlaveThread Class as follows:

        SlaveThread::~SlaveThread()
        {
            m_mutex.lock();
            m_quit = true;
            m_mutex.unlock();
            wait();
        }
        

        After compiling Qt code I get following error.

        '~SlaveThread()' overrides a destructor but is not marked 'override'
        

        Can you please inform me what can be reason and solution for above problem?

        Thank you very much :)

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @saurabh162
        https://stackoverflow.com/questions/17923370/override-identifier-after-destructor-in-c11

        And solution as @J-Hilk has just posted.

        1 Reply Last reply
        2
        • K Offline
          K Offline
          Konstantin Tokarev
          wrote on last edited by
          #4

          -Wno-inconsistent-missing-destructor-override

          JonBJ 1 Reply Last reply
          2
          • K Konstantin Tokarev

            -Wno-inconsistent-missing-destructor-override

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @Konstantin-Tokarev
            Good spot, and https://stackoverflow.com/questions/51612041/disable-a-specific-warning-in-qtcreator/51621828 even shows OP where to put it in Qt Creator :)

            1 Reply Last reply
            1
            • S Offline
              S Offline
              saurabh162
              wrote on last edited by saurabh162
              #6

              Hallo @J-Hilk ,@JonB , @Konstantin-Tokarev,

              Thank you very much for your help.

              Now I understand main reason of this problem. Additionally in this post I see two possible solution to remove this warning.

              1. Using override keyword
              2. Suppress warning related to override function in Clang code model using ```
                "-Wno-inconsistent-missing-destructor-override"
              
              Can you please inform me which one above is more in direction of clean coding guidelines? 
              
              According to me, using keyword "override" is right approach to solve this problem. Whether I am right ? 
              
              
              Many thanks :)
              JonBJ J.HilkJ 2 Replies Last reply
              0
              • S saurabh162

                Hallo @J-Hilk ,@JonB , @Konstantin-Tokarev,

                Thank you very much for your help.

                Now I understand main reason of this problem. Additionally in this post I see two possible solution to remove this warning.

                1. Using override keyword
                2. Suppress warning related to override function in Clang code model using ```
                  "-Wno-inconsistent-missing-destructor-override"
                
                Can you please inform me which one above is more in direction of clean coding guidelines? 
                
                According to me, using keyword "override" is right approach to solve this problem. Whether I am right ? 
                
                
                Many thanks :)
                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @saurabh162
                The warning is there because it's a warning! So (I would have thought) for choice you should put in the override rather than suppress the warning. However, that requires code edits. Sounds like that is OK for you, but for others it might not be, so the warning suppression is for them.

                1 Reply Last reply
                1
                • S Offline
                  S Offline
                  saurabh162
                  wrote on last edited by
                  #8

                  Hello @JonB

                  Thank you for quick feedback

                  Kind Regards

                  Saurabh Jain

                  1 Reply Last reply
                  0
                  • S saurabh162

                    Hallo @J-Hilk ,@JonB , @Konstantin-Tokarev,

                    Thank you very much for your help.

                    Now I understand main reason of this problem. Additionally in this post I see two possible solution to remove this warning.

                    1. Using override keyword
                    2. Suppress warning related to override function in Clang code model using ```
                      "-Wno-inconsistent-missing-destructor-override"
                    
                    Can you please inform me which one above is more in direction of clean coding guidelines? 
                    
                    According to me, using keyword "override" is right approach to solve this problem. Whether I am right ? 
                    
                    
                    Many thanks :)
                    J.HilkJ Offline
                    J.HilkJ Offline
                    J.Hilk
                    Moderators
                    wrote on last edited by
                    #9

                    @saurabh162 it's a warning for you the developer.

                    The override keyword can help avoiding bugs, by producing a compilation error when the intended override isn't technically an override.
                    E.g. that the function type isn't exactly like the base class function. Or that a maintenance of the base class changes that function's type (adding a defaulted argument for example)

                    As long as the base class has the destructor marked as virtual, all derived class destructors will call the basal destructor correctly.

                    In your case it doesn't matter much. But just in case you're actually using virtual functions yourself in your other classes, you should stick with the override keyword.


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    1 Reply Last reply
                    2
                    • K Offline
                      K Offline
                      Konstantin Tokarev
                      wrote on last edited by
                      #10

                      For destructor override keyword can only matter if it's the only one virtual function in the class that is overridden, and this case is covered by -Wdelete-non-virtual-dtor

                      1 Reply Last reply
                      2
                      • S Offline
                        S Offline
                        saurabh162
                        wrote on last edited by
                        #11

                        Hello @JonB, @J-Hilk, @Konstantin-Tokarev,

                        Once again thank you very much for your help.

                        Now I have understood it correctly.

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved