Skip to content

Refactoring: separate the cppcheck-specific &= handling from TokenList::combineOperators() #737

Closed

Description

@danmar

TokenList::combineOperators() joins single-character tokens into operators (& = → &=). It also contains a heuristic for
cppcheck: in a function declaration with an unnamed reference parameter that has a default value, &= is not joined.

void f(x&=2);          // simplecpp: void f ( x & = 2 ) ;
f(x&=2);               // simplecpp: f ( x &= 2 ) ;

This is not part of preprocessing. Compilers tokenize &= as one operator here (g++: expected ',' or '...' before '&=' token). To
decide, the heuristic tracks whether the code is inside a function body (executableScope) and looks back for a function
declaration. That is C++ parsing.

Before combineOperators() is replaced by a longest-match tokenizer (step 2 of #708), move this code into separate functions with
clear names, so that it can be kept as its own step:

  • tracking of { / } to know if the current code is in a function body
  • detection of "&= in the parameter list of a function declaration"

This is a pure refactoring, so behaviour does not change. The existing tests in combineOperators_andequal keep passing unchanged.

Activity

  1. added a commit that references this issue on Nov 9, 2026
    178e71d
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

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions