Skip to content

hash: keep the space after an operator of two characters - #755

Merged
danmar merged 1 commit into
masterfrom
fix-754
Nov 10, 2026
Merged

danmar merged 1 commit into
masterfrom
fix-754

Conversation

@danmar

@danmar danmar commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@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

I found no problems. When combineOperators() merges tokens, the PR now copies the whitespaceahead flag from the last merged token to the combined one. That covers every merge in the function: ..., float literals, exponents, compound assignments, &&, ||, ::, ->, <<, >>, <<=, >>=, ++ and --. With the PR, #x keeps the space after these operators, as gcc and clang do. The previous TODO_ASSERT_EQUALS in macro_c11_example4 is now a real assertion and passes. The change adds no cost to preprocessing and does not touch the API.

Testing

Build and test suites

  • make -j8 testrunner simplecpp CXXOPTS=-Werror in pr/ built with no warnings.
  • ./testrunner: 0 failed.
  • python3 run-tests.py: 176 tests, 21 skipped, 15 todos, 0 failed.
  • python3 -m pytest integration_test.py: 128 passed.
  • ./selfcheck.sh: exit code 0.

My own tests
I wrote stringification tests in /work/scratch and ran them through pr/simplecpp, base/simplecpp, gcc -E -P and clang -E -P. They covered:

  • s(a == b), s(a ==b), s(a<<= 2) and s(a >>== b)
  • s(1.5 f), s(.5 x), s(1.e x), s(1e+5 x) and s(0x1p+1 x)
  • s(x ... y), s(f(a ... )), s(a .. .b) and s(a+++ b)
  • s(a:: b), s(a&& b) and s(a-> b)
  • Operators followed by a comment, by a backslash-newline or by a newline inside the macro arguments
  • Arguments built by ##, nested macro expansion (str(P(a ->) b)) and #__VA_ARGS__

Results

  • The PR's output matches gcc and clang in all of these cases.
  • Base lost the space in many of them, for example "a ==b", "1.5f", "x ...y", "a ->b" and "a ==b , c ->d".
  • One mismatch is still there, and base gives the same result, so the PR did not cause it: s(1e+ 5) gives "1e+5", while gcc and clang give "1e+ 5".

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

@danmar
danmar merged commit fb8808b into master Nov 10, 2026
47 checks passed
@danmar
danmar deleted the fix-754 branch November 10, 2026 08:08
@danmar

danmar commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator Author

This fixed #754

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