Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
mstorsjo opened this issue Dec 1, 2023 · 4 comments
Assignees
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" duplicate Resolved as duplicate regression

Comments

@mstorsjo
Copy link
Member

mstorsjo commented Dec 1, 2023

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

@mstorsjo mstorsjo added clang:frontend Language frontend issues, e.g. anything involving "Sema" regression labels Dec 1, 2023
@llvmbot
Copy link
Member

llvmbot commented Dec 1, 2023

@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

@cor3ntin cor3ntin self-assigned this Dec 1, 2023
@cor3ntin
Copy link
Contributor

cor3ntin commented Dec 2, 2023

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
Copy link
Contributor

cor3ntin commented Dec 2, 2023

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

@cor3ntin
Copy link
Contributor

cor3ntin commented Dec 2, 2023

Lets keep the discussion in #73232

@EugeneZelenko EugeneZelenko added the duplicate Resolved as duplicate label Dec 2, 2023
@EugeneZelenko EugeneZelenko closed this as not planned Won't fix, can't repro, duplicate, stale Dec 2, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" duplicate Resolved as duplicate regression
Projects
None yet
Development

No branches or pull requests

4 participants