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. qvariant.h:710: warning: C4702: unreachable code
Qt 6.11 is out! See what's new in the release blog

qvariant.h:710: warning: C4702: unreachable code

Scheduled Pinned Locked Moved Solved General and Desktop
36 Posts 4 Posters 1.8k Views 2 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.
  • Christian EhrlicherC Christian Ehrlicher

    You maybe can wrap the return with an else

            else if constexpr (std::is_same_v<T, std::monostate>)
                return QVariant();
            else
                return QVariant(QMetaType::fromType<T>(), std::addressof(value));
    
    R Offline
    R Offline
    Robert Hairgrove
    wrote on last edited by
    #10

    @Christian-Ehrlicher said in qvariant.h:710: warning: C4702: unreachable code:

    You maybe can wrap the return with an else

            else if constexpr (std::is_same_v<T, std::monostate>)
                return QVariant();
            else
                return QVariant(QMetaType::fromType<T>(), std::addressof(value));
    

    I do not want to change the Qt source code! 😲

    BTW, since in my project the symbol Q_QDOC is not defined, the elsebranch is grayed out ...

    1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      So you should show use your testcase where it fails ...

      R Offline
      R Offline
      Robert Hairgrove
      wrote on last edited by
      #11

      @Christian-Ehrlicher I will repeat what I just wrote:

      And that is my problem here because the diagnostic MSVC gives me does not show where in my own code that this is being triggered

      If I knew where, I could show you.

      Christian EhrlicherC 1 Reply Last reply
      0
      • R Robert Hairgrove

        @Christian-Ehrlicher I will repeat what I just wrote:

        And that is my problem here because the diagnostic MSVC gives me does not show where in my own code that this is being triggered

        If I knew where, I could show you.

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

        @Robert-Hairgrove said in qvariant.h:710: warning: C4702: unreachable code:

        If I knew where, I could show you.

        That's the life of a developer...

        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
        0
        • R Offline
          R Offline
          Robert Hairgrove
          wrote on last edited by
          #13

          I neglected to say that I am building with std:c++17, if that makes any difference.

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #14

            Did you try my proposed change?

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

            R 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              Did you try my proposed change?

              R Offline
              R Offline
              Robert Hairgrove
              wrote on last edited by
              #15

              @Christian-Ehrlicher said in qvariant.h:710: warning: C4702: unreachable code:

              Did you try my proposed change?

              No, because I do not want to start hacking the Qt source code.

              Christian EhrlicherC 1 Reply Last reply
              0
              • R Offline
                R Offline
                Robert Hairgrove
                wrote on last edited by
                #16

                In the meantime, I was able to narrow things down by doing make clean and compiling each source file individually. I found one file which makes heavy use of QVariant, and I was able to disable the warning in that file only. Now I have to run a full build to see if there are other places where the warning is triggered. But since I only get one warning, I think this might be the only place.

                If that is the case, I will come back and mark the thread as "SOLVED".

                JonBJ 1 Reply Last reply
                0
                • R Robert Hairgrove has marked this topic as solved on
                • R Robert Hairgrove

                  In the meantime, I was able to narrow things down by doing make clean and compiling each source file individually. I found one file which makes heavy use of QVariant, and I was able to disable the warning in that file only. Now I have to run a full build to see if there are other places where the warning is triggered. But since I only get one warning, I think this might be the only place.

                  If that is the case, I will come back and mark the thread as "SOLVED".

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

                  @Robert-Hairgrove
                  Isn't your error Wrong C4702 unreachable code in templated early if constexpr return

                  This is reduced from the Qt 6.8.3 system header QVariant.

                  ?

                  And assuming it is, as i understand it it is a MSVC not a Qt issue. For which there appears to be a fix release/patch:

                  A fix for this issue has been released! Install the most recent release from https://visualstudio.microsoft.com/downloads/. Thank you for providing valuable feedback which has helped improve the product.

                  That was in answer to someone using

                  cl /std:c++20 Project1.cpp

                  Microsoft (R) C/C++ Optimizing Compiler Version 19.44.35207.1 for x64

                  R Christian EhrlicherC 3 Replies Last reply
                  0
                  • JonBJ JonB

                    @Robert-Hairgrove
                    Isn't your error Wrong C4702 unreachable code in templated early if constexpr return

                    This is reduced from the Qt 6.8.3 system header QVariant.

                    ?

                    And assuming it is, as i understand it it is a MSVC not a Qt issue. For which there appears to be a fix release/patch:

                    A fix for this issue has been released! Install the most recent release from https://visualstudio.microsoft.com/downloads/. Thank you for providing valuable feedback which has helped improve the product.

                    That was in answer to someone using

                    cl /std:c++20 Project1.cpp

                    Microsoft (R) C/C++ Optimizing Compiler Version 19.44.35207.1 for x64

                    R Offline
                    R Offline
                    Robert Hairgrove
                    wrote on last edited by
                    #18
                    This post is deleted!
                    1 Reply Last reply
                    0
                    • JonBJ JonB

                      @Robert-Hairgrove
                      Isn't your error Wrong C4702 unreachable code in templated early if constexpr return

                      This is reduced from the Qt 6.8.3 system header QVariant.

                      ?

                      And assuming it is, as i understand it it is a MSVC not a Qt issue. For which there appears to be a fix release/patch:

                      A fix for this issue has been released! Install the most recent release from https://visualstudio.microsoft.com/downloads/. Thank you for providing valuable feedback which has helped improve the product.

                      That was in answer to someone using

                      cl /std:c++20 Project1.cpp

                      Microsoft (R) C/C++ Optimizing Compiler Version 19.44.35207.1 for x64

                      R Offline
                      R Offline
                      Robert Hairgrove
                      wrote on last edited by
                      #19

                      @JonB Thanks for the feedback. It is exactly like the first link, which was reported in October 2025 after the fix for the other issue appeared in March 2025.

                      The two issues are not related. The later issue, which is what I have, is still under investigation.

                      JonBJ 1 Reply Last reply
                      0
                      • R Robert Hairgrove

                        @Christian-Ehrlicher said in qvariant.h:710: warning: C4702: unreachable code:

                        Did you try my proposed change?

                        No, because I do not want to start hacking the Qt source code.

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

                        @Robert-Hairgrove said in qvariant.h:710: warning: C4702: unreachable code:

                        No, because I do not want to start hacking the Qt source code.

                        This is stupid - you should not hack the source code but just try it out so we can change the code if it works.
                        So you have to life with the hack - but stop complaining about Qt not fixing your stuff.

                        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
                        0
                        • R Robert Hairgrove

                          @JonB Thanks for the feedback. It is exactly like the first link, which was reported in October 2025 after the fix for the other issue appeared in March 2025.

                          The two issues are not related. The later issue, which is what I have, is still under investigation.

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

                          @Robert-Hairgrove said in qvariant.h:710: warning: C4702: unreachable code:

                          The later issue, which is what I have, is still under investigation.

                          OIC :(

                          1 Reply Last reply
                          0
                          • JonBJ JonB

                            @Robert-Hairgrove
                            Isn't your error Wrong C4702 unreachable code in templated early if constexpr return

                            This is reduced from the Qt 6.8.3 system header QVariant.

                            ?

                            And assuming it is, as i understand it it is a MSVC not a Qt issue. For which there appears to be a fix release/patch:

                            A fix for this issue has been released! Install the most recent release from https://visualstudio.microsoft.com/downloads/. Thank you for providing valuable feedback which has helped improve the product.

                            That was in answer to someone using

                            cl /std:c++20 Project1.cpp

                            Microsoft (R) C/C++ Optimizing Compiler Version 19.44.35207.1 for x64

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

                            @JonB said in qvariant.h:710: warning: C4702: unreachable code:

                            Isn't your error Wrong C4702 unreachable code in templated early if constexpr return

                            This is reduced from the Qt 6.8.3 system header QVariant.
                            

                            ?

                            And assuming it is, as i understand it it is a MSVC not a Qt issue. For which there appears to be a fix release/patch:

                            Yes, it is fixed in the current MSVC version. Thx for the investigation.

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

                            R 1 Reply Last reply
                            0
                            • Christian EhrlicherC Christian Ehrlicher

                              @JonB said in qvariant.h:710: warning: C4702: unreachable code:

                              Isn't your error Wrong C4702 unreachable code in templated early if constexpr return

                              This is reduced from the Qt 6.8.3 system header QVariant.
                              

                              ?

                              And assuming it is, as i understand it it is a MSVC not a Qt issue. For which there appears to be a fix release/patch:

                              Yes, it is fixed in the current MSVC version. Thx for the investigation.

                              R Offline
                              R Offline
                              Robert Hairgrove
                              wrote on last edited by Robert Hairgrove
                              #23

                              @Christian-Ehrlicher said in qvariant.h:710: warning: C4702: unreachable code:

                              Yes, it is fixed in the current MSVC version.

                              Which one? It still happens in the ones I quoted above which I use (MSVC 2022 and MSVC 2026, both Community versions). They are both very recent, although I might have missed an update.

                              Reading the links that @JonB posted, it is the "internal compiler error" which was fixed in March, 2025. The OTHER link, which was reported in October of 2025, is newer, and there is no mention of a fix.

                              Christian EhrlicherC 1 Reply Last reply
                              0
                              • R Robert Hairgrove

                                @Christian-Ehrlicher said in qvariant.h:710: warning: C4702: unreachable code:

                                Yes, it is fixed in the current MSVC version.

                                Which one? It still happens in the ones I quoted above which I use (MSVC 2022 and MSVC 2026, both Community versions). They are both very recent, although I might have missed an update.

                                Reading the links that @JonB posted, it is the "internal compiler error" which was fixed in March, 2025. The OTHER link, which was reported in October of 2025, is newer, and there is no mention of a fix.

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

                                @Robert-Hairgrove said in qvariant.h:710: warning: C4702: unreachable code:

                                Which one?

                                The latest - 17.14.26 with cl.exe version 19.44.35222 which was released four days ago right after the fix was added (according the link it was fixed at Jan 30, 2026

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

                                R 1 Reply Last reply
                                0
                                • Christian EhrlicherC Christian Ehrlicher

                                  @Robert-Hairgrove said in qvariant.h:710: warning: C4702: unreachable code:

                                  Which one?

                                  The latest - 17.14.26 with cl.exe version 19.44.35222 which was released four days ago right after the fix was added (according the link it was fixed at Jan 30, 2026

                                  R Offline
                                  R Offline
                                  Robert Hairgrove
                                  wrote on last edited by
                                  #25

                                  @Christian-Ehrlicher said in qvariant.h:710: warning: C4702: unreachable code:

                                  @Robert-Hairgrove said in qvariant.h:710: warning: C4702: unreachable code:

                                  Which one?

                                  The latest - 17.14.26 with cl.exe version 19.44.35222 which was released four days ago right after the fix was added (according the link it was fixed at Jan 30, 2026

                                  OK, now this is useful information. I am one update behind, it looks like.

                                  I hope you realize, of course, that hacking into the source of qvariant.h would have been totally useless (and indeed stupid, IMHO)?

                                  Christian EhrlicherC 1 Reply Last reply
                                  0
                                  • R Robert Hairgrove

                                    @Christian-Ehrlicher said in qvariant.h:710: warning: C4702: unreachable code:

                                    @Robert-Hairgrove said in qvariant.h:710: warning: C4702: unreachable code:

                                    Which one?

                                    The latest - 17.14.26 with cl.exe version 19.44.35222 which was released four days ago right after the fix was added (according the link it was fixed at Jan 30, 2026

                                    OK, now this is useful information. I am one update behind, it looks like.

                                    I hope you realize, of course, that hacking into the source of qvariant.h would have been totally useless (and indeed stupid, IMHO)?

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

                                    @Robert-Hairgrove said in qvariant.h:710: warning: C4702: unreachable code:

                                    hope you realize, of course, that hacking into the source of qvariant.h would have been totally useless (and indeed stupid, IMHO)?

                                    No - if it would have worked I would created a patch to fix Qt to not hit the compiler error...

                                    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
                                    0
                                    • R Offline
                                      R Offline
                                      Robert Hairgrove
                                      wrote on last edited by
                                      #27

                                      I'm sorry, but this warning is still there even after I applied the latest MSVC update. 😠

                                      It does not appear when building with Qt 6.5.3, but it appears with Qt 6.7.3 and (presumably) all later versions up to and including 6.11.0 beta. However, the line numbers of qvariant.h are different; but the code appears to be exactly the same.

                                      Once again, this is with std:c++17.

                                      And with GCC 13.3.0 on Linux, there never was any error. I think the code in qvariant.h is probably correct, and MSVC is wrong.

                                      1 Reply Last reply
                                      0
                                      • R Offline
                                        R Offline
                                        Robert Hairgrove
                                        wrote on last edited by
                                        #28

                                        Can we close this now? Ich habe wirklich keine Lust mehr...

                                        1 Reply Last reply
                                        0
                                        • Christian EhrlicherC Offline
                                          Christian EhrlicherC Offline
                                          Christian Ehrlicher
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #29

                                          You can close this since you're too lazy to add one line in the Qt header for a fix...

                                          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
                                          0
                                          • R Robert Hairgrove deleted this topic on
                                          • R Robert Hairgrove restored this topic on

                                          • Login

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