summaryrefslogtreecommitdiffstats
path: root/src/tools/moc
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-06-27 07:24:47 +0200
committerMarc Mutz <marc.mutz@qt.io>2022-07-06 17:56:57 +0200
commit20a1526a23d23c32eca2bfd9b3194e30771902ac (patch)
tree30c49b4ef3bb99f08b6b5a1141bc86860f04ba15 /src/tools/moc
parent480a459f6543be2723c58b3eed711232e41f58b7 (diff)
moc: fix GCC -Wuseless-cast warnings
When being queried for QMetaObject::IndexOfMethod, qt_static_metacall would compare the argument with each of the class' methods' addresses. Taking the address of an overloaded function is ambiguous unless you cast to the right type, which the moc-generated code did using explicit static_cast<>s. If the function is not overloaded, GCC would warn about the static_cast<> being "useless", which isn't wrong. Fix by using an implicit cast to a local variable of the correct type instead of an explicit cast. Since there's no explicit cast anymore, GCC doesn't warn. Code before the change: using _t = void(Counter::*)(int ); if (*reinterpret_cast<_t*>(_a[1]) == static_cast<_t>(&Counter::valueChanged)) { ^-------------------------------------- -Wuseless-cast *result = 0; return; } After: using _t = void(Counter::*)(int ); if (_t _q_method = &Counter::valueChanged; *reinterpret_cast<_t*>(_a[1]) == _q_method) { *result = 0; return; } Since we're using a C++17 construct, we can't pick to 5.15. Pick-to: 6.4 6.3 6.2 Fixes: QTBUG-71938 Change-Id: If6ba4bf17b3bf7f64e9662ba9d085273882fb460 Reviewed-by: Mate Barany <mate.barany@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/tools/moc')
-rw-r--r--src/tools/moc/generator.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp
index 49cdf4a0ad..f030bc8918 100644
--- a/src/tools/moc/generator.cpp
+++ b/src/tools/moc/generator.cpp
@@ -1186,7 +1186,7 @@ void Generator::generateStaticMetacall()
fprintf(out, ") const;\n");
else
fprintf(out, ");\n");
- fprintf(out, " if (*reinterpret_cast<_t *>(_a[1]) == static_cast<_t>(&%s::%s)) {\n",
+ fprintf(out, " if (_t _q_method = &%s::%s; *reinterpret_cast<_t *>(_a[1]) == _q_method) {\n",
cdef->classname.constData(), f.name.constData());
fprintf(out, " *result = %d;\n", methodindex);
fprintf(out, " return;\n");