Skip to content

cfg/qt.cfg - Change the Q_D definition to avoid false positives #7629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

winterz
Copy link
Contributor

@winterz winterz commented Jun 25, 2025

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.

winterz and others added 7 commits April 11, 2025 07:11
Add support for Qt macros Q_DECL_DEPRECATED and Q_DECL_DEPRECATED_X
for people use the Qt library.
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:
Q_D(Class) Class##Private * const d = d_func()

but apparently cppcheck doesn't properly recognize that
as a const variable pointer.
@chrchr-github
Copy link
Collaborator

Can you add a test in qt.cpp?

@winterz
Copy link
Contributor Author

winterz commented Jun 27, 2025

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.

@danmar
Copy link
Owner

danmar commented Jun 28, 2025

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.

ludviggunne and others added 16 commits June 30, 2025 15:25
Create new `QThread`s for each check, as well as for whole-program
analysis, instead of restarting finished threads which is undefined
behavior (see https://doc.qt.io/qt-6/qthread.html#create). Fixes Trac
#13852.
In cppcheck html report, points to libera.chat rather than freenode.net
)

Add the bool isValid() signature.
bool isValid(int, int, int) is already there.
also cleaned up some `externals` includes and the order.
@winterz
Copy link
Contributor Author

winterz commented Jul 1, 2025

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?

@danmar
Copy link
Owner

danmar commented Jul 2, 2025

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.

@danmar
Copy link
Owner

danmar commented Jul 2, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants