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 7 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.

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.

2 participants