Skip to content

Fix #14607: MISRA: make rule 10.3 warn on bool <- 0/1 in C99 and later#8340

Merged
danmar merged 1 commit intodanmar:mainfrom
varshneydevansh:misra
Mar 27, 2026
Merged

Fix #14607: MISRA: make rule 10.3 warn on bool <- 0/1 in C99 and later#8340
danmar merged 1 commit intodanmar:mainfrom
varshneydevansh:misra

Conversation

@varshneydevansh
Copy link
Copy Markdown
Contributor

@varshneydevansh varshneydevansh commented Mar 15, 2026

Fix #14607.

This updates MISRA rule 10.3 in addons/misra.py so that assignments of integer literals 0 and 1 to bool are only exempted in C89.

Behavior after this change:

  • C89: keep the existing behavior and allow bool <- 0/1
  • C99/C11/C17/C18/C23: report MISRA 10.3 for bool <- 0/1

The motivation is that in C99 and later, bool/true/false are available, so the current unconditional exemption for 0 and 1 causes a MISRA 10.3 false negative.

Changes:

  • update addons/misra.py rule 10.3 to make the bool <- 0/1 exemption standard-dependent
  • add C89-side coverage in addons/test/misra/misra-test.c
  • add C11-side coverage in addons/test/misra/misra-test-c11.c
  • add a release notes entry

Related Context:

@varshneydevansh
Copy link
Copy Markdown
Contributor Author

varshneydevansh commented Mar 15, 2026

Trac ticket is now filed: https://trac.cppcheck.net/ticket/14607

Local verification passed:

  • misra.py -verify for misra-test.c with --std=c89
  • misra.py -verify for misra-test-c11.c with --std=c11
  • PYTHONPATH=./addons .venv/bin/python -m pytest addons/test/misra_test.py

@sonarqubecloud
Copy link
Copy Markdown

@varshneydevansh varshneydevansh changed the title feat: misra: make rule 10.3 warn on bool <- 0/1 in C99 and later Fix #14607: MISRA: make rule 10.3 warn on bool <- 0/1 in C99 and later Mar 17, 2026
@danmar danmar merged commit b70e34d into danmar:main Mar 27, 2026
72 checks passed
@danmar
Copy link
Copy Markdown
Owner

danmar commented Mar 27, 2026

@varshneydevansh thanks for your contribution. what name would you like that I add in the AUTHORS file?

@varshneydevansh
Copy link
Copy Markdown
Contributor Author

Let's add the name Devansh Varshney :)

Thanks Daniel.

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