moc: don't include any std headers before user class headers

don't `#include <memory>` before including the header of the user's
class(es), because the user may want to configure certain aspects of
stl/crt before including any standard headers.

Change-Id: I58f13d3604358221e3375a309eb747efecf3f990
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Stefan Sichler 2022-11-29 14:39:55 +01:00
parent b6e30e9fee
commit f60d6f4ffa

View File

@ -1072,7 +1072,9 @@ void Moc::generate(FILE *out, FILE *jsonOutput)
fprintf(out, "** WARNING! All changes made in this file will be lost!\n"
"*****************************************************************************/\n\n");
fprintf(out, "#include <memory>\n"); // For std::addressof
// include header(s) of user class definitions at _first_ to allow
// for preprocessor definitions possibly affecting standard headers.
// see https://codereview.qt-project.org/c/qt/qtbase/+/445937
if (!noInclude) {
if (includePath.size() && !includePath.endsWith('/'))
includePath += '/';
@ -1108,6 +1110,8 @@ void Moc::generate(FILE *out, FILE *jsonOutput)
#endif
);
fprintf(out, "\n#include <memory>\n\n"); // For std::addressof
fprintf(out, "#if !defined(Q_MOC_OUTPUT_REVISION)\n"
"#error \"The header file '%s' doesn't include <QObject>.\"\n", fn.constData());
fprintf(out, "#elif Q_MOC_OUTPUT_REVISION != %d\n", mocOutputRevision);