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

Clang 18, error: call to constructor of 'QDateTime' is ambiguous

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P1: Critical
    • 6.7.2, 6.8.0
    • 6.7.1
    • Core: Date/Time
    • None
    • 669f7e3b9723446732d31d48b653cd2bd9580f2d (qtbase/dev), dcc482cd01c138e4603a349986f5419b03583c96(qtbase/6.7)

    Description

      If you compile Qt 6.7.1 with Clang 18 in C++20 mode, you will see the following compilation error:

      In file included from /somewhere/qt-everywhere-src-6.7.1/qtbase/src/corelib/compat/removed_api.cpp:287:
      In file included from /somewhere/qt-build/qtbase/include/QtCore/qdir.h:1:
      In file included from /somewhere/qt-everywhere-src-6.7.1/qtbase/src/corelib/io/qdir.h:9:
      In file included from /somewhere/qt-build/qtbase/include/QtCore/qfileinfo.h:1:
      In file included from /somewhere/qt-everywhere-src-6.7.1/qtbase/src/corelib/io/qfileinfo.h:11:
      In file included from /somewhere/qt-build/qtbase/include/QtCore/qdatetime.h:1:
      /somewhere/qt-everywhere-src-6.7.1/qtbase/src/corelib/time/qdatetime.h:532:19: error: call to constructor of 'QDateTime' is ambiguous
        532 |         QDateTime result(QDate(1970, 1, 1), QTime(0, 0, 0));
            |                   ^      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      /somewhere/qt-everywhere-src-6.7.1/qtbase/src/corelib/time/qdatetime.h:359:5: note: candidate constructor
        359 |     QDateTime(QDate date, QTime time);
            |     ^
      /somewhere/qt-everywhere-src-6.7.1/qtbase/src/corelib/time/qdatetime.h:363:5: note: candidate constructor
        363 |     QDateTime(QDate date, QTime time,
            |     ^
      1 error generated.
      

      This is because qtbase/src/corelib/compat/removed_api.cpp defines QT_CORE_BUILD_REMOVED_API, which results in the following code after preprocessing:

          QDateTime(QDate date, QTime time);
          QDateTime(QDate date, QTime time,
                    TransitionResolution resolve = TransitionResolution::LegacyBehavior);
      

      It compiles with GCC only by chance because GCC is less thorough in checking code inside the templated function fromStdLocalTime:

          template <typename = void>
          static QDateTime fromStdLocalTime(const std::chrono::local_time<std::chrono::milliseconds> &time)
          {
              QDateTime result(QDate(1970, 1, 1), QTime(0, 0, 0));
              return result.addMSecs(time.time_since_epoch().count());
          }
      

      This godbolt fragment demonstrates the problem: https://godbolt.org/z/4f3x7zo9j

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              Eddy Edward Welbourne
              dreghor Pavel Baxtin
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes