Skip to content

Fix #15239 (Update simplecpp to 1.10.2) - #9048

Merged
danmar merged 12 commits into
cppcheck-opensource:mainfrom
cppchecksolutions:fix-15239
Nov 21, 2026
Merged

danmar merged 12 commits into
cppcheck-opensource:mainfrom
cppchecksolutions:fix-15239

Conversation

@danmar

@danmar danmar commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@dmcppcheck

Copy link
Copy Markdown
Contributor

Tests may be missing

@danmar danmar changed the title Fix #15239 (Update simplecpp to 1.10.0) Fix #15239 (Update simplecpp to 1.10.1) Nov 20, 2026
danmar and others added 2 commits November 20, 2026 15:48
- Regenerate Makefile with dmake (preprocessor.h now includes errortypes.h)
- Add trailing newlines to test inputs, since simplecpp now reports
  simplecppPortabilityNoEofNewline for C files
- misra-test.c: simplecpp no longer evaluates #elif after a true #if, so
  restructure the 20.8 test so that the #elif is evaluated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@danmar danmar changed the title Fix #15239 (Update simplecpp to 1.10.1) Fix #15239 (Update simplecpp to 1.10.2) Nov 21, 2026

@dmcppcheck dmcppcheck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review

The PR now reports the simplecpp portability messages, but inline suppressions do not work for the ones that come from tokenizing the main source file: simplecppPortabilityNoEofNewline, simplecppPortabilityBackslash and simplecppPortabilityLineDirective. Those messages go out through reportOutput() in CppCheck::checkInternal before preprocessor.inlineSuppressions() has read the comments. So // cppcheck-suppress simplecppPortabilityNoEofNewline does not hide the warning, and cppcheck then also reports that suppression as unmatched. The same suppression works when the message is in an included header, and simplecppPortabilityStringify can be suppressed inline too, because both of those are reported later, during preprocessing. No test covers the new portability reporting through the CLI, and none covers inline suppression of these ids.

I found no other problems. The #elif/#if evaluation fix, macro usage tracking across #undef/redefinition, and the new arg attribute in the dump all behaved correctly in my tests.

Comments

# Comment By Where Status
1 Main-file portability messages are reported before inline suppressions are parsed, so they cannot be suppressed inline AI review lib/preprocessor.cpp:954 🆕 New

@danmar, please fix, resolve or reply to the open and new comments: #1.

Testing

Build: make -j8 cppcheck testrunner in pr/ succeeded. I also built cppcheck in base/ to compare results.

Tests run:

  • ./testrunner TestPreprocessor TestSuppressions TestCppcheck: 271 tests, 0 failed.
  • test/cli/other_test.py -k "progress or addon_suppr or analyzerinfo or ipc_hash": 10 passed.
  • PYTHONPATH=addons pytest addons/test/misra_test.py: 17 passed.

Problem reproduced: inline suppression of a portability message in the main file does not work

printf '// cppcheck-suppress simplecppPortabilityNoEofNewline\nint x;' > supp.c
./cppcheck -q --enable=portability,information --inline-suppr supp.c
supp.c:2:7: portability: No newline at end of file is undefined behavior in C. [simplecppPortabilityNoEofNewline]
supp.c:2:1: information: Unmatched suppression: simplecppPortabilityNoEofNewline [unmatchedSuppression]

The same thing happens with simplecppPortabilityBackslash: #define A 1 \ (backslash, space, newline) under a // cppcheck-suppress simplecppPortabilityBackslash comment is still reported. For comparison, these do get suppressed:

  • the same suppression comment in an included header with no trailing newline (sh.h included from sh.c);
  • // cppcheck-suppress simplecppPortabilityStringify above S(\), where #define S(x) #x.

--suppress=simplecppPortabilityNoEofNewline on the command line works.

Other checks that showed no problem:

  • simplecppPortabilityNoEofNewline is reported for .c files and for headers included from C files, but not for .cpp files or their headers.
  • When a header is used in several configurations, its warning is printed only once.
  • The dump's macro-usage section now keeps usages of macros that are later #undef'd or redefined. defined(X), defined X, #ifdef X and a function-like macro without ( in #if are all recorded. The arg attribute is correct for INT8_C/UINT64_C, including when the call is nested in another macro and when the argument needs XML escaping.
  • #elif after a group that was already taken is no longer evaluated, and neither is a nested #if in a skipped group. With -DA, an #if 1/0 nested inside #ifdef A is still reported.
  • #define A followed by #if A (and -DA= with #if A) now gives syntaxError "invalid expression", where base said nothing. GCC rejects this too ("#if with no expression"), so I am not reporting it as a problem.

Automated review of 69895d9 by Claude. The pull request was built and tested locally.

Comment thread lib/preprocessor.cpp Resolved

@dmcppcheck dmcppcheck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review

The problem from the earlier review is fixed: CppCheck::checkInternal now reports the simplecpp portability messages of the main file after preprocessor.inlineSuppressions(), so inline suppressions of simplecppPortabilityNoEofNewline and the other new ids work in the main file as well as in headers. I found no new problems.

Comments

# Comment By Where Status
1 Main-file portability messages are reported before inline suppressions are parsed, so they cannot be suppressed inline AI review lib/preprocessor.cpp:954 ✅ Fixed
2 Tests may be missing @dmcppcheck general ✅ Fixed

Testing

Build: make -j8 cppcheck testrunner in pr/ succeeded.

Tests run:

  • ./testrunner TestPreprocessor TestSuppressions TestCppcheck: 0 failed.
  • pytest test/cli/other_test.py -k "portability or progress or addon_suppr or analyzerinfo or ipc_hash": 14 passed, including the new test_simplecpp_portability_header* tests.

Checked by hand with the PR's cppcheck:

  • Inline suppression in the main file, the case from the earlier review: printf '// cppcheck-suppress simplecppPortabilityNoEofNewline\nint x;' > supp.c; ./cppcheck -q --enable=portability,information --inline-suppr supp.c no longer reports the warning or an unmatched suppression.
  • Each new message is reported:
    • simplecppPortabilityBackslash for a backslash followed by a space and a newline.
    • simplecppPortabilityStringify for S(\), where #define S(x) #x.
    • simplecppPortabilityLineDirective for #line 0 and for #line 3000000000, also with --std=c89.
    • simplecppPortabilityNoEofNewline for C files, including C headers. It is not reported for .cpp files.
  • --check-config and -j2 both report the messages correctly.
  • --cppcheck-build-dir: I ran a main file with no final newline and a C file including a header with no final newline. On the second, cached run the message is still printed, exactly once.
  • With portability disabled, nothing is reported.

Not tested: I did not build base/ to compare results, and I did not run the misra addon tests or the full test suite.


Automated review of d2987e8 by Claude. The pull request was built and tested locally.

@danmar
danmar merged commit 3074865 into cppcheck-opensource:main Nov 21, 2026
74 checks passed
@danmar
danmar deleted the fix-15239 branch November 22, 2026 09:43
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