qmltc: fix GCC13 warnings "class X is implicitly friend with itself"

This happens because the generated code contains

    class X {
        ~~~~
    private:
        friend class X; // warning here
    };

Says GCC13 (e.g.):

    tests/auto/qml/qmltc/QmltcTests/.qmltc/qmltc_test_module/inlinecomponents.h:421:18: warning: class ‘QmltcTests::inlineComponents_IC0’ is implicitly friends with itself
      421 |     friend class inlineComponents_IC0;
          |                  ^~~~~~~~~~~~~~~~~~~~

It seems the intended check for documentRoot doesn't work in all
cases, so do the check on the class-name level.

There appears to be no -W flag to control this warning, therefore no
apparent way to suppress it, so we need to fix it.

Amends either b89a92053e or
0990b892ca. I didn't dig into it
further.

Change-Id: I3fe653a398ea5b7a3e045fd3ea8dfb5d5c0f2e5c
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit a5377f32e1)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2023-08-01 17:32:25 +02:00 committed by Qt Cherry-pick Bot
parent 53472eb8d5
commit 53e10b8bf1
1 changed files with 2 additions and 1 deletions

View File

@ -186,7 +186,8 @@ void QmltcCompiler::compileType(
// make document root a friend to allow it to access init and endInit
const QString rootInternalName =
m_visitor->inlineComponent(type->enclosingInlineComponentName())->internalName();
current.otherCode << u"friend class %1;"_s.arg(rootInternalName);
if (rootInternalName != current.cppType) // avoid GCC13 warning on self-befriending
current.otherCode << "friend class %1;"_L1.arg(rootInternalName);
}
if (documentRoot || inlineComponent) {
auto name = type->inlineComponentName()