GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Restructure the preprocessor to follow the standard's translation phases · Issue #708 · cppcheck-opensource/simplecpp

Restructure the preprocessor to follow the standard's translation phases #708

New issue
Copy link
New issue
Copy link
Open
Task
11 / 1411 of 14 issues completed
Open
Restructure the preprocessor to follow the standard's translation phases#708
Task
11 / 1411 of 14 issues completed
Copy link

Description

@danmar
danmar
opened on Nov 4, 2026
Issue body actions

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 that causes bugs.
Comparing with gcc -E shows these differences:

  • Line joining (phase 2) happens after tokenizing, so ab\<newline>cd becomes two tokens.
  • Tokenizing (phase 3) splits the input into single characters and joins them again in
    combineOperators(). Numbers like 0x1e+e and 1.2.3 are split, and <=>, ->*, .*
    and digraphs aren't supported.
  • #line is handled while the file is read. It takes effect inside #if 0 and does not
    expand macros.
  • #elif is evaluated even after an earlier group was taken.
  • #if arithmetic has no unsigned math (-1 > 0u is false) and no short-circuit
    (0 && (1/0) is an error). true is 0 in C++.
  • ## is checked against a hand-written list: valid <<=, -> and && are rejected,
    and invalid .. is accepted.
  • # escapes every backslash (str(\n) gives "\\n") and drops the space a comment
    stands for.
  • Macro expansion approximates the standard rescanning rules with an expanded-macro set
    and special cases, instead of hide sets.

Proposed steps, each one a separate PR:

  1. Small fixes: #line in the directive loop, skip #elif after a taken group, a new
    #if evaluator, fix # escaping.
  2. Do line joining in the character stream, and replace combineOperators() with a
    longest-match tokenizer.
  3. Move cppcheck-specific changes (raw-string conversion, &= split, #/## in plain
    text) to options applied to the output.
  4. Rewrite macro expansion using Prosser's hide-set algorithm.

The full report with test cases is attached (preprocessing-report.md).

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.

preprocessing-report.md

Activity

  1. danmar
    added the
    Task
    issue type on Nov 4, 2026
  2. danmar
    added sub-issues on Nov 8, 2026
    • #elif condition is evaluated after a previous group was taken #709
    • #if true evaluates to false in C++ and C23 #711
    • # operator escapes backslashes outside string literals #714
    • #if: && and || are evaluated with the same precedence #716
    • # operator drops the space that a comment stands for #718
    • #if: wrong macro usage for macros defined before the #if #720
    • #if: &&, || and ?: short-circuit #722
    • ##: valid token pastes are rejected #724
    • #line takes effect inside skipped groups and does not expand macros #734
    • Refactoring: split TokenList::readfile() into smaller functions #735
    • Refactoring: separate the cppcheck-specific &= handling from TokenList::combineOperators() #737
    • Add a lookahead buffer to TokenList::Stream #739
    • Handle line splicing (backslash-newline) in TokenList::Stream #741
    • Add a macro expander that uses hide sets #742
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Task

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.