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

~unique_ptr() static assertion failure due to incomplete type T (C++23)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 6.6.2, 6.7.0 Beta2, 6.8.0 FF
    • 6.6.1, 6.6.2, 6.6.3
    • Core: Other
    • None
    • Seen on Linux, macOS, Windows. Clang 15 and 16 but this should get triggered under other compilers too.
    • All
    • c8db469fd (dev), 7d12cf673 (6.7), 8da0980ae (6.6)

    Description

      The problem code is in corelib/mimetypes/qmimeprovider.cpp.

      From https://github.com/llvm/llvm-project/issues/74963#issuecomment-1850834221:

      "~unique_ptr() became constexpr in C++23 and thus gets instantiated more eagerly – at the point of first reference rather than at end of TU."

      Fix:

      Make the definition of QMimeBinaryProvider::CacheFile precede the definition of QMimeBinaryProvider::QMimeBinaryProvider() because the unique_ptr<QMimeBinaryProvider::CacheFile> QMimeBinaryProvider::m_cacheFile will be instantiated at this point and thus also ~unique_ptr<QMimeBinaryProvider::CacheFile>() which needs the definition of QMimeBinaryProvider::CacheFile to be visible.

      Compiler command line (summarised, obviously):

      clang++ -Wall -O3 -std=c++2b
      -Wno-unqualified-std-cast-call -finput-charset=UTF-8
      -o build/QtCore/mimetypes/qmimeprovider.dylib.o
      -c -x c++ src/QtCore/mimetypes/qmimeprovider.cpp 

      Error message:

      In file included from /src/QtCore/mimetypes/qmimeprovider.cpp:6:
      In file included from /src/QtCore/private/QtCore/private/qmimeprovider_p.h:19:
      In file included from /src/QtCore/private/QtCore/private/qmimedatabase_p.h:19:
      In file included from /src/QtCore/qmimedatabase.h:8:
      In file included from /src/QtCore/qmimetype.h:12:
      In file included from /src/QtCore/qobjectdefs.h:13:
      In file included from /src/QtCore/qobjectdefs_impl.h:17:
      In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/memory:898:
      In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/shared_ptr.h:31:
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/unique_ptr.h:63:19: error: invalid application of 'sizeof' to an incomplete type 'QMimeBinaryProvider::CacheFile'
          static_assert(sizeof(_Tp) >= 0, "cannot delete an incomplete type");
                        ^~~~~~~~~~~
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/unique_ptr.h:297:7: note: in instantiation of member function 'std::default_delete<QMimeBinaryProvider::CacheFile>::operator()' requested here
            __ptr_.second()(__tmp);
            ^
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/unique_ptr.h:263:75: note: in instantiation of member function 'std::unique_ptr<QMimeBinaryProvider::CacheFile>::reset' requested here
        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 ~unique_ptr() { reset(); }
                                                                                ^
      /src/QtCore/mimetypes/qmimeprovider.cpp:66:22: note: in instantiation of member function 'std::unique_ptr<QMimeBinaryProvider::CacheFile>::~unique_ptr' requested here
      QMimeBinaryProvider::QMimeBinaryProvider(QMimeDatabasePrivate *db, const QString &directory)
                           ^
      /src/QtCore/private/QtCore/private/qmimeprovider_p.h:112:12: note: forward declaration of 'QMimeBinaryProvider::CacheFile'
          struct CacheFile;
      

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            francoisk777 Francois Kritzinger
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes