Skip to content

Fix #13970 cfg/qt.cfg - add definition for QDate::isValid()#7630

Merged
chrchr-github merged 1 commit intocppcheck-opensource:mainfrom
winterz:work/winterz/cfg_qdate_isvalid
Jun 28, 2025
Merged

Fix #13970 cfg/qt.cfg - add definition for QDate::isValid()#7630
chrchr-github merged 1 commit intocppcheck-opensource:mainfrom
winterz:work/winterz/cfg_qdate_isvalid

Conversation

@winterz
Copy link
Copy Markdown
Contributor

@winterz winterz commented Jun 26, 2025

Add the bool isValid() signature.
bool isValid(int, int, int) is already there.

@chrchr-github
Copy link
Copy Markdown
Collaborator

Does this solve an issue for you? The existing definition already claims to handle both overloads via the default arguments.

@winterz
Copy link
Copy Markdown
Contributor Author

winterz commented Jun 27, 2025

with the current definition the following code snippet gives a false positive assertWithSideEffect

int IncidenceRecurrence::weekdayCountForMonth(const QDate &date) const
{
    /* cppcheck-suppress assertWithSideEffect */
    Q_ASSERT(date.isValid());

QDate::isValid() doesn't muck with date so it shouldn't cause any side effects, right?

@chrchr-github
Copy link
Copy Markdown
Collaborator

Then you should add <const/> to the existing definition, and a test case in qt.cpp.

@chrchr-github
Copy link
Copy Markdown
Collaborator

chrchr-github commented Jun 27, 2025

Side note: The attribute <const/> indicates a constant function, not just member-constness, which seems to be correct in this case. But we might not always interpret this consistently as far as I remember. See #6385

@winterz winterz force-pushed the work/winterz/cfg_qdate_isvalid branch from 1041a92 to a61995c Compare June 28, 2025 20:06
to solve a false positive:
```
 QDate date;
 Q_ASSERT(date.isValid());
```

reports assertWithSideEffect
@winterz winterz force-pushed the work/winterz/cfg_qdate_isvalid branch from a61995c to 2c56f9f Compare June 28, 2025 20:07
@chrchr-github chrchr-github changed the title cfg/qt.cfg - add definition for QDate::isValid() Fix #13970 cfg/qt.cfg - add definition for QDate::isValid() Jun 28, 2025
@chrchr-github chrchr-github merged commit ca83f56 into cppcheck-opensource:main Jun 28, 2025
53 of 54 checks passed
winterz added a commit to winterz/cppcheck that referenced this pull request Jun 30, 2025
…-opensource#7630)

Add the bool isValid() signature.
bool isValid(int, int, int) is already there.
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