cfg/qt.cfg - Change the Q_D definition to avoid false positives
Change the O_D macro definition by moving the 'const' qualifier to the front of the statement.
Without this change we get false positives "style: Variable 'd' can be declared as pointer to const [constVariablePointer]"
The current definition follows Qt correctly as we see this
define in the QtCore/qtclasshelpermacros.h file:
#define Q_D(Class) Class##Private * const d = d_func()
but apparently cppcheck doesn't properly recognize that as a const variable pointer.
Can you add a test in qt.cpp?
yes, I can add a test.
however, I think a larger problem is that cppcheck seems to not like FooPrivate * const d = d_func() whereas it seems ok with const FooPrivate *d = d_func() ? unless something else is happening.
however, I think a larger problem is that cppcheck seems to not like FooPrivate * const d = d_func() whereas it seems ok with const FooPrivate *d = d_func() ? unless something else is happening.
some simple sample code that demonstrate a problem would be nice. we should like the first code as far as I know.
I wrote a test here but it isn't showing any problems. must be something else is happening . I'll look closer.
in my test, I did run into a checkLibraryFunction issue for qGetPtrHelper from the Q_DECLARE_PRIVATE macro.
I'm not sure where to look or where to set qGetPtrHelper . can I get a hint?
I'm not sure where to look or where to set qGetPtrHelper . can I get a hint?
hmm.. you already identified that it's from Q_DECLARE_PRIVATE
if a simple configuration is provided like:
<function name="qGetPtrHelper">
<arg nr="1"/>
</function>
does it work better then?
That configuration is not ideal. Cppcheck can not know what value it returns then. However I am not sure that providing the template would help neither the type deduction can be too complex.
I am not 100% sure that providing the exact real replacement lists for various macros is always a great idea. Maybe sometimes it's preferable to simplify the code. If this applies to the Q_DECLARE_PRIVATE I don't know, I've never actually used that macro myself in my code.