SUMMARY STEPS TO REPRODUCE Run the unneeded-cast check over the code: bool someCondition = ...; QLabel* label = ...; QLineEdit* edit = ...; QWidget* w = someCondition ? qobject_cast< QWidget* >( label ) : qobject_cast< QWidget* >( edit ); Clazy raises the "explicity casting to base is unnecessary" warning, yet the code will not compile if the casts are removed ("incompatible operand types QLabel* and QLineEdit*") OBSERVED RESULT EXPECTED RESULT SOFTWARE/OS VERSIONS Windows: macOS: Linux/KDE Plasma: (available in About System) KDE Plasma Version: KDE Frameworks Version: Qt Version: ADDITIONAL INFORMATION
it should still warn, as you should use static_cast instead in that case will fix the warning message
Git commit 4918d8efba9b20b273a15ab2dd215a768ff884f9 by Sergio Martins. Committed on 27/05/2019 at 13:12. Pushed by smartins into branch 'master'. unneeded-cast: Improve warning message for unneeded qobject_cast Instead of saying that no cast to base is needed, simply say that no qobject_cast is needed. Since a static_cast might still be needed. This is the case for the ternary operator. M +13 -3 src/checks/manuallevel/unneeded-cast.cpp M +1 -1 src/checks/manuallevel/unneeded-cast.h M +2 -2 tests/unneeded-cast/main.cpp https://commits.kde.org/clazy/4918d8efba9b20b273a15ab2dd215a768ff884f9