Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-106277

QProperty fails to compile on MSVC in C++20 mode

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 6.4.1, 6.5.0 Beta1
    • 6.3.0, 6.4.0
    • Core: Other
    • None
    • Windows MSVC 2019 and 2022 C++20
    • Windows
    • 7979665362 (qt/qtbase/dev) 7979665362 (qt/tqtc-qtbase/dev) 53edbb330d (qt/qtbase/6.4) 53edbb330d (qt/tqtc-qtbase/6.4) 53edbb330d (qt/tqtc-qtbase/6.4.1) 53edbb330d (qt/tqtc-qtbase/tqtc/qtinsight-6.4)

    Description

      A trivial QProperty example fails to compile on MSVC in C++20 mode, with different errors on 2019 and 2022.

      #include <QtCore/QProperty>
      int main(int argc, char* argv[]) {
          QProperty<int> p;
          QProperty<int> p2;
          p.setBinding([&]() { return p2.value(); });
          return 0;
      }
      

      Compiled with:

      cl.exe -Iinclude /Zc:__cplusplus -std:c++20 -DQT_CORE_LIB test.cpp lib\Qt6Core.lib
      

      On 2019 I get:

      Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30146 for x64
      Copyright (C) Microsoft Corporation.  All rights reserved.
      
      test.cpp
      C:\qt_install\include\QtCore\qproperty.h(423): error C7595: 'std::source_location::current': call to immediate function is not a constant expression
      

      On 2022 I get:

      Microsoft (R) C/C++ Optimizing Compiler Version 19.33.31629 for x64
      Copyright (C) Microsoft Corporation.  All rights reserved.test.cpp
      Microsoft (R) Incremental Linker Version 14.33.31629.0
      Copyright (C) Microsoft Corporation.  All rights reserved./out:test.exe
      test.obj
      lib\Qt6Core.lib
      test.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QPropertyBindingSourceLocation::QPropertyBindingSourceLocation(struct std::source_location const &)" (__imp_??0QPropertyBindingSourceLocation@@QEAA@AEBUsource_location@std@@@Z) referenced in function main
      test.exe : fatal error LNK1120: 1 unresolved externals
      

      Both of these can be fixed by changing the "constexpr" to "consteval" in the "constexpr QPropertyBindingSourceLocation(const QT_SOURCE_LOCATION_NAMESPACE::source_location &cppLocation)" constructor in qproperty.h.

      Attachments

        For Gerrit Dashboard: QTBUG-106277
        # Subject Branch Project Status CR V

        Activity

          People

            patstew Patrick Stewart
            patstew Patrick Stewart
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There is 1 open Gerrit change