Skip to content

Fix #760 (record argument for integer constant macros) - #761

Merged
danmar merged 3 commits into
masterfrom
fix-760
Nov 19, 2026
Merged

danmar merged 3 commits into
masterfrom
fix-760

Conversation

@danmar

@danmar danmar commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

dmcppcheck and others added 2 commits November 16, 2026 09:18
Fixes clang-tidy readability-convert-member-functions-to-static.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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 crash, hang or regression. All test suites pass. I have two remarks:

  • INTMAX_C / UINTMAX_C are not handled. isIntegerConstantMacro() only accepts n = 8/16/32/64. The C standard (C11 7.20.4.2) also lists INTMAX_C and UINTMAX_C among the integer constant macros, and for those arg stays empty.
  • arg is not always the text as written. If the call is inside a macro body (for example #define X(a) UINT32_C(a)), arg holds the substituted text with macros already expanded. With X(R(7) /* c */ + 8) it is 7 + 8, not R ( 7 ) + 8. The comment in simplecpp.h says "as written in the call". Either the code or that comment should change.

This is the first review of the PR; comments.md is empty.

Testing

Build and test suites

  • make -j8 testrunner simplecpp CXXOPTS=-Werror in pr/ built cleanly.
  • ./testrunner passed with no failures.
  • python3 run-tests.py: 176 tests, 0 failed (21 skipped, 15 todo, the same as before).
  • python3 -m pytest integration_test.py: 128 passed.
  • ./selfcheck.sh exited with 0.

Own driver
I wrote a small driver, scratch/drv.cpp. It calls simplecpp::preprocess with a macroUsage list and prints name line:col [arg] for each entry. I ran it on these cases:

  • calls inside a define (#define X(a) UINT32_C(a), #define Q UINT32_C, #define Y UINT32_C(7))
  • a call nested in another macro's arguments (F(UINT32_C(9)))
  • a macro passed as an argument (V(UINT32_C))
  • arguments that span lines, both at top level and inside a multi-line outer call (R(\nUINT32_C(5\n+6)))
  • comments, with comments both removed and kept
  • an unterminated UINT32_C( at end of file

The arguments came out as expected and there was no crash or hang. The preprocessed output matched gcc -E.

Problems found

  1. INTMAX_C / UINTMAX_C get no argument:
#define INTMAX_C(x) x
#define UINTMAX_C(x) x
INTMAX_C(300) UINTMAX_C(1)

./drv t6.c prints:

INTMAX_C 3:1 []
UINTMAX_C 3:15 []
  1. Inside a macro body, the argument is the expanded text, not the written text:
#define UINT32_C(x) x
#define X(a) UINT32_C(a)
#define R(a) a
X(R(7) /* c */ + 8)

The driver prints UINT32_C 4:1 [7 + 8].


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

Comment thread simplecpp.cpp Resolved
Comment thread simplecpp.h 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

I found no new problems. The earlier review raised two points, and both are fixed in the current code. isIntegerConstantMacro() now accepts INTMAX_C and UINTMAX_C, which macroUsageArg7 covers. The doc comment of MacroUsage::arg in simplecpp.h now says that for a call inside a macro body the argument is the substituted and expanded text, and macroUsageArg6 tests that case. The build is clean with -Werror, all test suites pass, and my own cases gave the expected arg with no crash and no change to the preprocessed output compared with base.

Comments

# Comment By Where Status
1 INTMAX_C / UINTMAX_C are not handled AI review general ✅ Fixed
2 arg is not the written text when the call is in a macro body; the doc comment is wrong AI review general ✅ Fixed
3 isIntegerConstantMacro misses INTMAX_C / UINTMAX_C AI review simplecpp.cpp:2280 ✅ Fixed
4 the 'as written' doc comment is wrong for calls in a macro body; no test for it AI review simplecpp.h:468 ✅ Fixed

Testing

Build and test suites

  • make -j8 testrunner simplecpp CXXOPTS=-Werror in pr/: built cleanly.
  • ./testrunner: 0 failed (21 skipped, 15 todo).
  • python3 run-tests.py: no failures.
  • python3 -m pytest integration_test.py: 128 passed.
  • ./selfcheck.sh: exit code 0.

Own driver
I wrote scratch/drv.cpp, which calls simplecpp::preprocess with a macroUsage list and prints name line:col [arg] for each entry. I ran it on these cases:

  • a macro passed as an argument and then called inside the body (#define F(m) m(5) / F(UINT32_C)): gives [5]
  • a call formed after expansion (G(UINT32_C)(7+1)): gives [7 + 1]
  • an object-like macro that opens the call (#define H UINT32_C( / H 3)): gives [3]
  • the name and ( on different lines: gives [4]
  • calls in a macro body whose arguments span several lines (X(1\n+2), Y(\n3\n), Z(1,\n\n2)): gives [1 + 2], [3] and [9], [1 2]
  • nested integer constant macros together with a // comment: the outer call gives [INT8_C ( 1 ) + 2] and the inner one [1]
  • a call inside another macro's argument (W(UINT32_C(W(4)))): gives [W ( 4 )]
  • a stringified call (S(UINT32_C(3))): no usage is recorded
  • two calls in one object-like body: gives [1] and [2]
  • unterminated calls inside a define, including UINTMAX_C

There was no crash or hang. diff <(../base/simplecpp d.c) <(../pr/simplecpp d.c) showed no difference, so the PR does not change the preprocessed output.


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

@danmar
danmar merged commit e5cb618 into master Nov 19, 2026
58 of 59 checks passed
@danmar
danmar deleted the fix-760 branch November 19, 2026 10:53
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