Title: Restructure the preprocessor to follow the standard's translation phases · Issue #708 · cppcheck-opensource/simplecpp · GitHub
Open Graph Title: Restructure the preprocessor to follow the standard's translation phases · Issue #708 · cppcheck-opensource/simplecpp
X Title: Restructure the preprocessor to follow the standard's translation phases · Issue #708 · cppcheck-opensource/simplecpp
Description: simplecpp's output is correct for most code, and it passes nearly all the macro examples from C11 §6.10.3.5 and the C23/C++20 __VA_OPT__ examples. But the code doesn't follow the translation phases in C §5.1.1.2 and C++ [lex.phases], and...
Open Graph Description: simplecpp's output is correct for most code, and it passes nearly all the macro examples from C11 §6.10.3.5 and the C23/C++20 __VA_OPT__ examples. But the code doesn't follow the translation phases...
X Description: simplecpp's output is correct for most code, and it passes nearly all the macro examples from C11 §6.10.3.5 and the C23/C++20 __VA_OPT__ examples. But the code doesn't follow the translatio...
Opengraph URL: https://github.com/cppcheck-opensource/simplecpp/issues/708
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Restructure the preprocessor to follow the standard's translation phases","articleBody":" simplecpp's output is correct for most code, and it passes nearly all the macro examples\n from C11 §6.10.3.5 and the C23/C++20 `__VA_OPT__` examples. But the code doesn't follow\n the translation phases in C §5.1.1.2 and C++ [lex.phases], and that causes bugs.\n Comparing with `gcc -E` shows these differences:\n\n - **Line joining (phase 2)** happens after tokenizing, so `ab\\\u003cnewline>cd` becomes two tokens.\n - **Tokenizing (phase 3)** splits the input into single characters and joins them again in\n `combineOperators()`. Numbers like `0x1e+e` and `1.2.3` are split, and `\u003c=>`, `->*`, `.*`\n and digraphs aren't supported.\n - **`#line`** is handled while the file is read. It takes effect inside `#if 0` and does not\n expand macros.\n - **`#elif`** is evaluated even after an earlier group was taken.\n - **`#if` arithmetic** has no unsigned math (`-1 > 0u` is false) and no short-circuit\n (`0 && (1/0)` is an error). `true` is 0 in C++.\n - **`##`** is checked against a hand-written list: valid `\u003c\u003c=`, `->` and `&&` are rejected,\n and invalid `..` is accepted.\n - **`#`** escapes every backslash (`str(\\n)` gives `\"\\\\n\"`) and drops the space a comment\n stands for.\n - **Macro expansion** approximates the standard rescanning rules with an expanded-macro set\n and special cases, instead of hide sets.\n\n Proposed steps, each one a separate PR:\n 1. Small fixes: `#line` in the directive loop, skip `#elif` after a taken group, a new\n `#if` evaluator, fix `#` escaping.\n 2. Do line joining in the character stream, and replace `combineOperators()` with a\n longest-match tokenizer.\n 3. Move cppcheck-specific changes (raw-string conversion, `&=` split, `#`/`##` in plain\n text) to options applied to the output.\n 4. Rewrite macro expansion using Prosser's hide-set algorithm.\n\n The full report with test cases is attached (`preprocessing-report.md`).\n\n You may want to split it into one main issue for the restructure and separate small issues for the step 1 bugs (#line, #elif, #if arithmetic). Each of those can be fixed on its own.\n\n[preprocessing-report.md](https://github.com/user-attachments/files/34372683/preprocessing-report.md)","author":{"url":"https://github.com/danmar","@type":"Person","name":"danmar"},"datePublished":"2026-11-04T12:56:15Z","url":"https://github.com/cppcheck-opensource/simplecpp/issues/708"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a02bf1be-8104-8913-83d4-c83145d0d45a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ADEC:27C34C:1B7ADF:2763EA:6AFC4AC0 |
| html-safe-nonce | 58b3ffce2ec1b1cc839cae2d20cd67160ce9c041bbb179f1ce4f625af18fca52 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBREVDOjI3QzM0QzoxQjdBREY6Mjc2M0VBOjZBRkM0QUMwIiwidmlzaXRvcl9pZCI6IjcxOTg1ODQxMDAwNzkwMjg5MjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 5e085ef8accffba8abfb91b84c970162232c28cf55ca49913a6c6f7b311d11ce |
| hovercard-subject-tag | issue:6203149193 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/cppcheck-opensource/simplecpp/708/issue_layout |
| twitter:image | https://opengraph.githubassets.com/285d99ca7989d61fa6d4d756441f2de46147bfa6e19d0fff4c3d138ebf322269/cppcheck-opensource/simplecpp/issues/708 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/285d99ca7989d61fa6d4d756441f2de46147bfa6e19d0fff4c3d138ebf322269/cppcheck-opensource/simplecpp/issues/708 |
| og:image:alt | simplecpp's output is correct for most code, and it passes nearly all the macro examples from C11 §6.10.3.5 and the C23/C++20 __VA_OPT__ examples. But the code doesn't follow the translation phases... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | danmar |
| hostname | github.com |
| expected-hostname | github.com |
| None | 20dfdada12bc00bbf8065dc10dfe3ff3711b85db5cc117f83296f8074e861960 |
| turbo-cache-control | no-preview |
| go-import | github.com/cppcheck-opensource/simplecpp git https://github.com/cppcheck-opensource/simplecpp.git |
| octolytics-dimension-user_id | 278097703 |
| octolytics-dimension-user_login | cppcheck-opensource |
| octolytics-dimension-repository_id | 33434464 |
| octolytics-dimension-repository_nwo | cppcheck-opensource/simplecpp |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 33434464 |
| octolytics-dimension-repository_network_root_nwo | cppcheck-opensource/simplecpp |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 041909865f220ab51714e7efdc276dd349a99ade |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width