Repository navigation
Fix #774 (#define: stringizing a parameter named error or warning swallows the rest of the line) - #775
Fix #774 (#define: stringizing a parameter named error or warning swallows the rest of the line)#775wjakobsson wants to merge 2 commits into
Conversation
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
I found no problems. The fix handles #774 correctly: the rest of the line after #error/#warning is now read as message text only when that # is the first token on the line. Comments are not counted when finding the first token. The check isLastLinePreprocessor(2) == ppTok looks back at most two tokens, so it costs almost nothing on the hot path of readfile. It does not change the API or C++11 compatibility. The new test error9 covers both #error and #warning used as stringizing operators. No earlier comments to check.
Testing
make -j8 testrunner simplecpp CXXOPTS=-Werrorin pr/ built cleanly. I also built base/ to compare../testrunner: 0 failed.python3 run-tests.py: 176 tests, 0 failed (21 skipped, 14 todo, same as before).python3 -m pytest integration_test.py: 128 passed../selfcheck.sh: exit code 0.- I compared these inputs between pr/, base/ and
gcc -E:#define A(error) f(#error); break/A(e1): base givesf ( "e1" ); break(the rest of the line is swallowed as one token, which is the bug). pr givesf ( "e1" ) ; break, which matches gcc.#define S(warning) #warning, x y: base keepsx yas raw text. pr tokenizes it as gcc does.- The stringizing
#at the start of a continuation line inside a#define(f(\then#error); breakon the next line, with and without a space after#): fixed, and the output matches gcc. - Real directives still produce the diagnostic as before:
/*c*/ # /*d*/ error hello world,# warning hi there // c, and#\followed byerror ...on the next line. #errorinside#if 0, andint a; # error foo barin the middle of a line: same output as base.
Automated review of e3af2f5 by Claude. The pull request was built and tested locally.
|
What about other directives? E.g. |
They aren't affected. All other directives are tokenized as ordinary, only #warning and #error are exceptions, as their message is free text, and my not be valid tokens. (line1070) |
No description provided.