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. Qt 6.2.3 w/MSVC2022 17.1 Preview 5 (v143) - Cannot set C++ standard to C++20
Forum Updated to NodeBB v4.3 + New Features

Qt 6.2.3 w/MSVC2022 17.1 Preview 5 (v143) - Cannot set C++ standard to C++20

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 5 Posters 2.4k 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.
  • oblivioncthO Offline
    oblivioncthO Offline
    oblivioncth
    wrote on last edited by oblivioncth
    #1

    Hello,

    Following up here after an IRC session before filing a bug report since I don't see anyone else complaining about this:

    The qmake doc's for Qt6 specify that the value of 'c++20' is supported for the variable CONFIG (assuming compiler compatibility) and that 'c++2a' is an obsolete alias, which is corroborated by this merge from about a year ago: https://codereview.qt-project.org/c/qt/qtbase/+/333702

    Yet, with the tools specified in the title I am unable to enable C++20 support in my Qt project with

    CONFIG += c++20
    

    There is no error, but c++20 features aren't enable and the compiler log shows the switch -std:c++17 being used.

    If I instead specify

    CONFIG += c++2a
    

    c++20 features are available, but upon inspecting the compiler output it turns out that -std:c++latest was actually used, instead of -std:c++20. This isn't ideal, as although in practice it will likely not make a difference as I don't plan to use experimental features, I'd like to be absolutely sure that my code confirms to the C++20 standard.

    Obviously this compiler does support the C++20 standard, so I'm not sure why it seems qmake falls back upon C++17 when I specify C++20.

    Additional Info:

    • This also happens with MSVC2019 16.11.3 (v142)
    • This happens with the 6.2.3 MSVC2019 distribution from the maintenance tool, as well as a self-built static version. I am about to test if it happens with a self-built static copy using MSVC2022
    • I was going to try building Qt itself with C++20, but that fails immediately as it seems that isn't possible when including experimental headers involving features that have been standardized in the target C++ version, which the source does since it was written with C++17 in mind (the build fails almost immediately with a message related to this)
    • Using Visual Studio 2019/2022 directly I am able to select the /std:c++20 flag and verify that C++20 features are available
    • I am not able to use QMAKE_CXXFLAGS to try and work around this as the -std:c++20 value I specify is appended to the compiler call commands before qmake automatically adds -std:c++17, resulting in it being ignored
    • Using Windows 10 SDK 19041 (though this should be irrelevant)

    Any clue as to what's going on?

    1 Reply Last reply
    0
    • oblivioncthO Offline
      oblivioncthO Offline
      oblivioncth
      wrote on last edited by
      #11

      Both changes merged:
      https://codereview.qt-project.org/c/qt/qtbase/+/394904
      https://codereview.qt-project.org/c/qt/qtbase/+/394907

      Enjoy using "c++20" with qmake from 6.2.4 forward :)

      1 Reply Last reply
      0
      • hskoglundH Offline
        hskoglundH Offline
        hskoglund
        wrote on last edited by
        #2

        Hi, I have more or less the same problem, and I solved it by patching line 103 in the msvc-version.conf file in C:\Qt\6.2.3\msvc2019_64\mkspecs\common directory.

        Original content:

        ...
        QMAKE_CXXFLAGS      += -Zc:__cplusplus
        QMAKE_CXXFLAGS_CXX14 = -std:c++14
        QMAKE_CXXFLAGS_CXX1Z = -std:c++17
        ...
        

        patched do:

        ...
        QMAKE_CXXFLAGS      += -Zc:__cplusplus
        QMAKE_CXXFLAGS_CXX14 = -std:c++14
        QMAKE_CXXFLAGS_CXX1Z = -std:c++20
        ...
        

        admittedly this is a bad/clumsy way of solving the problem :-(

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

          The patch you mentioned ( https://codereview.qt-project.org/c/qt/qtbase/+/333702 ) did not update qmake so I doubt c++-20 as config option will work unless you use cmake.
          Wrt compiling Qt with c++20 - support - what do you think will you gain? There are currently no c++20 - only - features so compiling Qt with c++20 will give you no advantages. You should also take a look here: https://bugreports.qt.io/browse/QTBUG-100072 - there seems to be a msvc compiler bug.

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

          oblivioncthO 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            The patch you mentioned ( https://codereview.qt-project.org/c/qt/qtbase/+/333702 ) did not update qmake so I doubt c++-20 as config option will work unless you use cmake.
            Wrt compiling Qt with c++20 - support - what do you think will you gain? There are currently no c++20 - only - features so compiling Qt with c++20 will give you no advantages. You should also take a look here: https://bugreports.qt.io/browse/QTBUG-100072 - there seems to be a msvc compiler bug.

            oblivioncthO Offline
            oblivioncthO Offline
            oblivioncth
            wrote on last edited by oblivioncth
            #4

            @Christian-Ehrlicher

            Nothing in particular, it was more so a shot in the dark for this issue in hopes that for some reason qmake would better detect a compile has C++20 support if it itself was compiled with C++20, despite me knowing this wouldn't be the case.

            As for the issue at hand: Oh... I was planning on updating my projects to CMake at some point, but wasn't ready to get used to that quite yet. The qmake docs for 6 mention C++20 as a valid value here: https://doc.qt.io/qt-6/qmake-variable-reference.html#config so I figured it should work, or is this just the result of some kind of miscommunication?

            EDIT:
            Looking closer at the actual merge changes, I see they updated the qmake docs, but yes only the cmake build system was actually touched. :/

            I know I'll have to move to CMake eventually anyway, in the end it isn't a huge deal if I rely on the 'lattest' flag till then.

            @hskoglund Well, its a decent temporary workaround at the very least.

            Christian EhrlicherC kkoehneK 2 Replies Last reply
            0
            • oblivioncthO oblivioncth

              @Christian-Ehrlicher

              Nothing in particular, it was more so a shot in the dark for this issue in hopes that for some reason qmake would better detect a compile has C++20 support if it itself was compiled with C++20, despite me knowing this wouldn't be the case.

              As for the issue at hand: Oh... I was planning on updating my projects to CMake at some point, but wasn't ready to get used to that quite yet. The qmake docs for 6 mention C++20 as a valid value here: https://doc.qt.io/qt-6/qmake-variable-reference.html#config so I figured it should work, or is this just the result of some kind of miscommunication?

              EDIT:
              Looking closer at the actual merge changes, I see they updated the qmake docs, but yes only the cmake build system was actually touched. :/

              I know I'll have to move to CMake eventually anyway, in the end it isn't a huge deal if I rely on the 'lattest' flag till then.

              @hskoglund Well, its a decent temporary workaround at the very least.

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

              @oblivioncth said in Qt 6.2.3 w/MSVC2022 17.1 Preview 5 (v143) - Cannot set C++ standard to C++20:

              Looking closer at the actual merge changes, I see they updated the qmake docs, but yes only the cmake build system was actually touched. :/

              Correct. Feel free to provide a patch, at least for the mkspecs. Or create a bug report but I doubt this will get much attention.

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

              oblivioncthO 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                @oblivioncth said in Qt 6.2.3 w/MSVC2022 17.1 Preview 5 (v143) - Cannot set C++ standard to C++20:

                Looking closer at the actual merge changes, I see they updated the qmake docs, but yes only the cmake build system was actually touched. :/

                Correct. Feel free to provide a patch, at least for the mkspecs. Or create a bug report but I doubt this will get much attention.

                oblivioncthO Offline
                oblivioncthO Offline
                oblivioncth
                wrote on last edited by
                #6

                @Christian-Ehrlicher Normally I would actually do that,
                but in this case it would be a patch that would soon become obsolete anyway, and so why spend time getting used to the mkspecs format when I can use this as an excuse to just get used to using CMake? :)

                SGaistS 1 Reply Last reply
                0
                • oblivioncthO oblivioncth

                  @Christian-Ehrlicher Normally I would actually do that,
                  but in this case it would be a patch that would soon become obsolete anyway, and so why spend time getting used to the mkspecs format when I can use this as an excuse to just get used to using CMake? :)

                  SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  @oblivioncth not necessarily, there are still lots of projects using qmake :-)

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  oblivioncthO 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    @oblivioncth not necessarily, there are still lots of projects using qmake :-)

                    oblivioncthO Offline
                    oblivioncthO Offline
                    oblivioncth
                    wrote on last edited by
                    #8

                    @SGaist Calling me to serve once again? Hahah, well maybe I'll take a crack at it if I can get around to it. I haven't looked at the mkspecs before and am a little confused as to how exactly the C++XX values specified in a given qmake config map to the handlers in each mkspecs file. It seems that at one point it used to reference a corresponding .prf file under the 'features' directory, though that is no longer the case.

                    Notepad++'s find-in-files features might elucidate things, but no promises.

                    1 Reply Last reply
                    0
                    • oblivioncthO oblivioncth

                      @Christian-Ehrlicher

                      Nothing in particular, it was more so a shot in the dark for this issue in hopes that for some reason qmake would better detect a compile has C++20 support if it itself was compiled with C++20, despite me knowing this wouldn't be the case.

                      As for the issue at hand: Oh... I was planning on updating my projects to CMake at some point, but wasn't ready to get used to that quite yet. The qmake docs for 6 mention C++20 as a valid value here: https://doc.qt.io/qt-6/qmake-variable-reference.html#config so I figured it should work, or is this just the result of some kind of miscommunication?

                      EDIT:
                      Looking closer at the actual merge changes, I see they updated the qmake docs, but yes only the cmake build system was actually touched. :/

                      I know I'll have to move to CMake eventually anyway, in the end it isn't a huge deal if I rely on the 'lattest' flag till then.

                      @hskoglund Well, its a decent temporary workaround at the very least.

                      kkoehneK Offline
                      kkoehneK Offline
                      kkoehne
                      Moderators
                      wrote on last edited by
                      #9

                      @oblivioncth said in Qt 6.2.3 w/MSVC2022 17.1 Preview 5 (v143) - Cannot set C++ standard to C++20:

                      Looking closer at the actual merge changes, I see they updated the qmake docs, but yes only the cmake build system was actually touched. :/

                      That was an oversight.

                      It should be enough to just add a

                      QMAKE_CXXFLAGS_CXX2A = -std:c++20

                      to msvc-version.conf . If defined, the value will be picked up automatically in default_post.prf.

                      Please let me know if you can upload a change, and add me to review. Otherwise I'll probably dig into it myself...

                      Director R&D, The Qt Company

                      oblivioncthO 1 Reply Last reply
                      0
                      • kkoehneK kkoehne

                        @oblivioncth said in Qt 6.2.3 w/MSVC2022 17.1 Preview 5 (v143) - Cannot set C++ standard to C++20:

                        Looking closer at the actual merge changes, I see they updated the qmake docs, but yes only the cmake build system was actually touched. :/

                        That was an oversight.

                        It should be enough to just add a

                        QMAKE_CXXFLAGS_CXX2A = -std:c++20

                        to msvc-version.conf . If defined, the value will be picked up automatically in default_post.prf.

                        Please let me know if you can upload a change, and add me to review. Otherwise I'll probably dig into it myself...

                        oblivioncthO Offline
                        oblivioncthO Offline
                        oblivioncth
                        wrote on last edited by oblivioncth
                        #10

                        @kkoehne Done.

                        I noted in a comment on the commit message that while the mkspecs change sets the correct QMAKE_CXXFLAGS_CXX2A when on VS2019 16.11.0 or above, it has no bearing on when qmake actually knows to use QMAKE_CXXFLAGS_CXX2A.

                        So CONFIG += C++2a now causes qmake to pass -std:C++20 when on the appropriate MSVC version, but CONFIG += C++20 still does not seemed to be recognized as valid despite being mentioned in the docs. I couldn't find the scripts/qmake source reading "QMAKE_CXXFLAGS_CXX2A" anywhere, so I'm unsure on where to make the changes for qmake so that C++20 becomes a valid alias for C++2a.

                        EDIT:
                        Figured it out (was literally one line haha). Added you as a reviewer on that patch as well.

                        1 Reply Last reply
                        0
                        • oblivioncthO Offline
                          oblivioncthO Offline
                          oblivioncth
                          wrote on last edited by
                          #11

                          Both changes merged:
                          https://codereview.qt-project.org/c/qt/qtbase/+/394904
                          https://codereview.qt-project.org/c/qt/qtbase/+/394907

                          Enjoy using "c++20" with qmake from 6.2.4 forward :)

                          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