From f60d6f4ffa66f77ecfa925355b3762951ee5171e Mon Sep 17 00:00:00 2001 From: Stefan Sichler Date: Tue, 29 Nov 2022 14:39:55 +0100 Subject: [PATCH] moc: don't include any std headers before user class headers don't `#include ` 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 --- src/tools/moc/moc.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index 0fbadfc061..cc6e1b59e5 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -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 \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 \n\n"); // For std::addressof + fprintf(out, "#if !defined(Q_MOC_OUTPUT_REVISION)\n" "#error \"The header file '%s' doesn't include .\"\n", fn.constData()); fprintf(out, "#elif Q_MOC_OUTPUT_REVISION != %d\n", mocOutputRevision);