From 4dcd9145e74dfb8c59016cf0011987cdeb6b3576 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Sat, 23 Sep 2017 09:37:24 +0200 Subject: moc: don't use const_cast in qt_metacast generated code qt_metacast is not const so there is no need to use const_cast. This fixes a warning in generated code. Task-number: QTBUG-63352 Change-Id: I0c37442ac268a654316bc0e7e04f77fb51cae019 Reviewed-by: Thiago Macieira --- src/tools/moc/generator.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/tools') diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index c4184929ef..6795e3b2cf 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -561,14 +561,14 @@ void Generator::generateCode() fprintf(out, "\nvoid *%s::qt_metacast(const char *_clname)\n{\n", cdef->qualified.constData()); fprintf(out, " if (!_clname) return nullptr;\n"); fprintf(out, " if (!strcmp(_clname, qt_meta_stringdata_%s.stringdata0))\n" - " return static_cast(const_cast< %s*>(this));\n", - qualifiedClassNameIdentifier.constData(), cdef->classname.constData()); + " return static_cast(this);\n", + qualifiedClassNameIdentifier.constData()); for (int i = 1; i < cdef->superclassList.size(); ++i) { // for all superclasses but the first one if (cdef->superclassList.at(i).second == FunctionDef::Private) continue; const char *cname = cdef->superclassList.at(i).first.constData(); - fprintf(out, " if (!strcmp(_clname, \"%s\"))\n return static_cast< %s*>(const_cast< %s*>(this));\n", - cname, cname, cdef->classname.constData()); + fprintf(out, " if (!strcmp(_clname, \"%s\"))\n return static_cast< %s*>(this);\n", + cname, cname); } for (int i = 0; i < cdef->interfaceList.size(); ++i) { const QVector &iface = cdef->interfaceList.at(i); @@ -576,8 +576,7 @@ void Generator::generateCode() fprintf(out, " if (!strcmp(_clname, %s))\n return ", iface.at(j).interfaceId.constData()); for (int k = j; k >= 0; --k) fprintf(out, "static_cast< %s*>(", iface.at(k).className.constData()); - fprintf(out, "const_cast< %s*>(this)%s;\n", - cdef->classname.constData(), QByteArray(j+1, ')').constData()); + fprintf(out, "this%s;\n", QByteArray(j + 1, ')').constData()); } } if (!purestSuperClass.isEmpty() && !isQObject) { -- cgit v1.2.3 From 3d0fa4d4fb870450f6e77d7248db91984ddf8b50 Mon Sep 17 00:00:00 2001 From: Eric Lemanissier Date: Tue, 26 Sep 2017 11:45:56 +0200 Subject: moc: remove useless cast in qt_static_metacall generated code _a[1] was reinterpret_casted twice in a row, which triggers clang's warning undefined-reinterpret-cast: "dereference of type '_t *' (aka ...) that was reinterpret_cast from type 'void **' has undefined behavior " only the last reinterpret_cast is kept Change-Id: I71d52c5ff08c674003aec29f8a907c90905c0d4c Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/tools/moc/generator.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/tools') diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index 6795e3b2cf..7e1ec3522f 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -1237,7 +1237,6 @@ void Generator::generateStaticMetacall() Q_ASSERT(needElse); // if there is signal, there was method. fprintf(out, " else if (_c == QMetaObject::IndexOfMethod) {\n"); fprintf(out, " int *result = reinterpret_cast(_a[0]);\n"); - fprintf(out, " void **func = reinterpret_cast(_a[1]);\n"); bool anythingUsed = false; for (int methodindex = 0; methodindex < cdef->signalList.size(); ++methodindex) { const FunctionDef &f = cdef->signalList.at(methodindex); @@ -1263,14 +1262,14 @@ void Generator::generateStaticMetacall() fprintf(out, ") const;\n"); else fprintf(out, ");\n"); - fprintf(out, " if (*reinterpret_cast<_t *>(func) == static_cast<_t>(&%s::%s)) {\n", + fprintf(out, " if (*reinterpret_cast<_t *>(_a[1]) == static_cast<_t>(&%s::%s)) {\n", cdef->classname.constData(), f.name.constData()); fprintf(out, " *result = %d;\n", methodindex); fprintf(out, " return;\n"); fprintf(out, " }\n }\n"); } if (!anythingUsed) - fprintf(out, " Q_UNUSED(result);\n Q_UNUSED(func);\n"); + fprintf(out, " Q_UNUSED(result);\n"); fprintf(out, " }"); needElse = true; } -- cgit v1.2.3