Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. UB or not
Forum Updated to NodeBB v4.3 + New Features

UB or not

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 513 Views
  • 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.
  • D Offline
    D Offline
    DmitryTS
    wrote last edited by DmitryTS
    #1

    I had an interesting question and confusion in my head, const QList<qlonglong>& keys = storeTypeChat.keys(); (storeTypeChat - QList) why there will be no dangling reference?

    jsulmJ Christian EhrlicherC 2 Replies Last reply
    0
    • D DmitryTS

      I had an interesting question and confusion in my head, const QList<qlonglong>& keys = storeTypeChat.keys(); (storeTypeChat - QList) why there will be no dangling reference?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote last edited by
      #2

      @DmitryTS QList has no keys() method. Do you mean QMap/QHash?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 1 Reply Last reply
      1
      • D DmitryTS

        I had an interesting question and confusion in my head, const QList<qlonglong>& keys = storeTypeChat.keys(); (storeTypeChat - QList) why there will be no dangling reference?

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote last edited by
        #3

        @DmitryTS said in UB or not:

        why there will be no dangling reference?

        Because the function returns a value which gets destroyed when the constant ref gets destroyed.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        D 1 Reply Last reply
        2
        • jsulmJ jsulm

          @DmitryTS QList has no keys() method. Do you mean QMap/QHash?

          D Offline
          D Offline
          DmitryTS
          wrote last edited by
          #4

          @jsulm sorry, yes, storeTypeChat - QMap

          1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            @DmitryTS said in UB or not:

            why there will be no dangling reference?

            Because the function returns a value which gets destroyed when the constant ref gets destroyed.

            D Offline
            D Offline
            DmitryTS
            wrote last edited by
            #5

            @Christian-Ehrlicher then it turns out that this is still a dangling ref?

            JonBJ 1 Reply Last reply
            0
            • D DmitryTS

              @Christian-Ehrlicher then it turns out that this is still a dangling ref?

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote last edited by
              #6

              @DmitryTS
              Define exactly what you mean/think of "dangling reference" here.
              Given @Christian-Ehrlicher's response of

              Because the function returns a value which gets destroyed when the constant ref gets destroyed.

              D 1 Reply Last reply
              1
              • JonBJ JonB

                @DmitryTS
                Define exactly what you mean/think of "dangling reference" here.
                Given @Christian-Ehrlicher's response of

                Because the function returns a value which gets destroyed when the constant ref gets destroyed.

                D Offline
                D Offline
                DmitryTS
                wrote last edited by
                #7

                @JonB will a constant reference extend the life of this temporary object or not?

                Christian EhrlicherC 1 Reply Last reply
                0
                • JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote last edited by JonB
                  #8

                  You mean from the point of the function call till the end of the reference's/function's lifetime? Yes! Rather than my picking a reference for you, Googling c++ constant reference extend the life of this temporary object or not will give you various confirmatory links.

                  I believe you are using an lvalue here (const QList<qlonglong>& keys = ...), and for that you must use const for lifetime extension, apparently.

                  1 Reply Last reply
                  0
                  • D DmitryTS

                    @JonB will a constant reference extend the life of this temporary object or not?

                    Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote last edited by
                    #9

                    @DmitryTS said in UB or not:

                    a constant reference extend the life of this temporary object or not?

                    I already answered it...

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    1 Reply Last reply
                    1

                    • Login

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