Repository navigation
Fix #15239 (Update simplecpp to 1.10.2) - #9048
Conversation
|
Tests may be missing |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- 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>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dmcppcheck
left a comment
There was a problem hiding this comment.
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.csupp.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.hincluded fromsh.c); // cppcheck-suppress simplecppPortabilityStringifyaboveS(\), where#define S(x) #x.
--suppress=simplecppPortabilityNoEofNewline on the command line works.
Other checks that showed no problem:
simplecppPortabilityNoEofNewlineis reported for.cfiles and for headers included from C files, but not for.cppfiles or their headers.- When a header is used in several configurations, its warning is printed only once.
- The dump's
macro-usagesection now keeps usages of macros that are later#undef'd or redefined.defined(X),defined X,#ifdef Xand a function-like macro without(in#ifare all recorded. Theargattribute is correct forINT8_C/UINT64_C, including when the call is nested in another macro and when the argument needs XML escaping. #elifafter a group that was already taken is no longer evaluated, and neither is a nested#ifin a skipped group. With-DA, an#if 1/0nested inside#ifdef Ais still reported.#define Afollowed by#if A(and-DA=with#if A) now givessyntaxError"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.
dmcppcheck
left a comment
There was a problem hiding this comment.
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 newtest_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.cno longer reports the warning or an unmatched suppression. - Each new message is reported:
simplecppPortabilityBackslashfor a backslash followed by a space and a newline.simplecppPortabilityStringifyforS(\), where#define S(x) #x.simplecppPortabilityLineDirectivefor#line 0and for#line 3000000000, also with--std=c89.simplecppPortabilityNoEofNewlinefor C files, including C headers. It is not reported for.cppfiles.
--check-configand-j2both 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.
No description provided.