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

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

Scheduled Pinned Locked Moved Solved General and Desktop
36 Posts 4 Posters 1.3k 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 Online
    Christian EhrlicherC Online
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote last edited by
    #6

    You should take a look from where excatly it comes as this part is for sure not unreachable. What exact MSVC version do you use?

    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
    • Christian EhrlicherC Christian Ehrlicher

      What MSVC version do you use? I don't get a warning there with /W4

          template<typename T>
      #ifndef Q_QDOC
          static inline auto fromValue(const T &value)
              noexcept(std::is_nothrow_copy_constructible_v<T> && Private::CanUseInternalSpace<T>)
              -> std::enable_if_t<std::is_copy_constructible_v<T> && std::is_destructible_v<T>, QVariant>
      #else
          static inline QVariant fromValue(const T &value)
      #endif
          {
              if constexpr (std::is_null_pointer_v<T>)
                  return QVariant(QMetaType::fromType<std::nullptr_t>());
              else if constexpr (std::is_same_v<T, QVariant>) <<-- this is line 740
                  return value;
              else if constexpr (std::is_same_v<T, std::monostate>)
                  return QVariant();
              return QVariant(QMetaType::fromType<T>(), std::addressof(value));
          }
      

      I don't see why the compiler should throw an error here.

      R Offline
      R Offline
      Robert Hairgrove
      wrote last edited by
      #7

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

      What MSVC version do you use?

      This happens using two different compiler versions:

      MSVC 2022 Community v17.14.25 - cl.exe version 19.44.35222 for x64
      

      and

      MSVC 2026 Community v18.2.1 - cl.exe version 19.50.35723 for x64
      

      Both are done in different instances of Oracle VirtualBox running on Linux Ubuntu 24.04 hosts with Windows 10 guests.

      It doesn't surprise me that you cannot duplicate the warning, because it appears that QVariant must be instantiated in a certain way in order for the warning to occur. 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, AFAICT.

      1 Reply Last reply
      0
      • Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote last edited by
        #8

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

        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 Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote last edited by
          #9

          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));
          

          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

            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 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 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 Online
                Christian EhrlicherC Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote 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 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 Online
                    Christian EhrlicherC Online
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote 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 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 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
                        • 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 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 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 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 Online
                                Christian EhrlicherC Online
                                Christian Ehrlicher
                                Lifetime Qt Champion
                                wrote 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 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 Online
                                    Christian EhrlicherC Online
                                    Christian Ehrlicher
                                    Lifetime Qt Champion
                                    wrote 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 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 Online
                                        Christian EhrlicherC Online
                                        Christian Ehrlicher
                                        Lifetime Qt Champion
                                        wrote 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 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

                                          • Login

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