Skip to content

"Eagerly instantiate used constexpr function upon definition" broke compiling Qt #74069

@mstorsjo

Description

@mstorsjo
Member

Since 030047c, Qt (tested with 6.6) fails to compile, with errors like this:

In file included from /home/martin/code/qt/src-6.6/src/corelib/compat/removed_api.cpp:12:
In file included from include/QtCore/qmetatype.h:1:
include/QtCore/../../../src-6.6/src/corelib/kernel/qmetatype.h:2669:1: error: explicit specialization of 'QMetaTypeId<QtMetaTypePrivate::QPairVariantInterfaceImpl>' after instantiation
 2669 | QT_DECL_METATYPE_EXTERN_TAGGED(QtMetaTypePrivate::QPairVariantInterfaceImpl,
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 2670 |                                QPairVariantInterfaceImpl, Q_CORE_EXPORT)
      |                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/QtCore/../../../src-6.6/src/corelib/kernel/qmetatype.h:1361:5: note: expanded from macro 'QT_DECL_METATYPE_EXTERN_TAGGED'
 1361 |     Q_DECLARE_METATYPE(TYPE) \
      |     ^~~~~~~~~~~~~~~~~~~~~~~~
include/QtCore/../../../src-6.6/src/corelib/kernel/qmetatype.h:1504:34: note: expanded from macro 'Q_DECLARE_METATYPE'
 1504 | #define Q_DECLARE_METATYPE(TYPE) Q_DECLARE_METATYPE_IMPL(TYPE)
      |                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/QtCore/../../../src-6.6/src/corelib/kernel/qmetatype.h:1508:12: note: expanded from macro 'Q_DECLARE_METATYPE_IMPL'
 1508 |     struct QMetaTypeId< TYPE >                                          \
      |            ^~~~~~~~~~~~~~~~~~~
include/QtCore/../../../src-6.6/src/corelib/kernel/qmetatype.h:1220:22: note: implicit instantiation first required here
 1220 |     enum { Defined = QMetaTypeId<T>::Defined, IsBuiltIn=false };
      |                      ^
1 error generated.

Before this commit, this file built just fine. This can be reproduced with this attached preprocessed file,
qt-preproc.zip, compiled as clang -target armv7-w64-mingw32 -c qt-preproc.cpp.

CC @cor3ntin

Activity

llvmbot

llvmbot commented on Dec 1, 2023

@llvmbot
Member

@llvm/issue-subscribers-clang-frontend

Author: Martin Storsjö (mstorsjo)

Since 030047c, Qt (tested with 6.6) fails to compile, with errors like this: ``` In file included from /home/martin/code/qt/src-6.6/src/corelib/compat/removed_api.cpp:12: In file included from include/QtCore/qmetatype.h:1: include/QtCore/../../../src-6.6/src/corelib/kernel/qmetatype.h:2669:1: error: explicit specialization of 'QMetaTypeId<QtMetaTypePrivate::QPairVariantInterfaceImpl>' after instantiation 2669 | QT_DECL_METATYPE_EXTERN_TAGGED(QtMetaTypePrivate::QPairVariantInterfaceImpl, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2670 | QPairVariantInterfaceImpl, Q_CORE_EXPORT) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/QtCore/../../../src-6.6/src/corelib/kernel/qmetatype.h:1361:5: note: expanded from macro 'QT_DECL_METATYPE_EXTERN_TAGGED' 1361 | Q_DECLARE_METATYPE(TYPE) \ | ^~~~~~~~~~~~~~~~~~~~~~~~ include/QtCore/../../../src-6.6/src/corelib/kernel/qmetatype.h:1504:34: note: expanded from macro 'Q_DECLARE_METATYPE' 1504 | #define Q_DECLARE_METATYPE(TYPE) Q_DECLARE_METATYPE_IMPL(TYPE) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/QtCore/../../../src-6.6/src/corelib/kernel/qmetatype.h:1508:12: note: expanded from macro 'Q_DECLARE_METATYPE_IMPL' 1508 | struct QMetaTypeId< TYPE > \ | ^~~~~~~~~~~~~~~~~~~ include/QtCore/../../../src-6.6/src/corelib/kernel/qmetatype.h:1220:22: note: implicit instantiation first required here 1220 | enum { Defined = QMetaTypeId<T>::Defined, IsBuiltIn=false }; | ^ 1 error generated. ```

Before this commit, this file built just fine. This can be reproduced with this attached preprocessed file,
qt-preproc.zip, compiled as clang -target armv7-w64-mingw32 -c qt-preproc.cpp.

CC @cor3ntin

self-assigned this
on Dec 1, 2023
cor3ntin

cor3ntin commented on Dec 2, 2023

@cor3ntin
Contributor

Reduced to

template <typename> constexpr static void fromType();

void registerConverter() { fromType<int>(); }
template <typename> struct QMetaTypeId  {};
template <typename T> constexpr void fromType() {
  (void)QMetaTypeId<T>{};
}
template <> struct QMetaTypeId<int> {};

https://godbolt.org/z/KE8xP5KTz

cor3ntin

cor3ntin commented on Dec 2, 2023

@cor3ntin
Contributor

@zygoloid I'm not 100% sure but GCC does seem to do instantiations during evaluation https://godbolt.org/z/Wz5oMzdnP

cor3ntin

cor3ntin commented on Dec 2, 2023

@cor3ntin
Contributor

Lets keep the discussion in #73232

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

clang:frontendLanguage frontend issues, e.g. anything involving "Sema"duplicateResolved as duplicateregression

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @mstorsjo@cor3ntin@EugeneZelenko@llvmbot

      Issue actions

        "Eagerly instantiate used constexpr function upon definition" broke compiling Qt · Issue #74069 · llvm/llvm-project