Skip to content

Code style: don't patch expressions/statements with preprocessor - #1243

Open
elizarov wants to merge 1 commit into
userver-framework:developfrom
elizarov:preprocessor_code_style
Open

Code style: don't patch expressions/statements with preprocessor#1243
elizarov wants to merge 1 commit into
userver-framework:developfrom
elizarov:preprocessor_code_style

Conversation

@elizarov

@elizarov elizarov commented Jun 3, 2026

Copy link
Copy Markdown

This pull request establishes the following code style discipline: conditional directives are not allowed below the supported item boundary, such as inside an expression, declaration, or statement header.

Conditional compilation is allowed:

  • When each branch contributes complete grammar items at the surrounding level: complete declarations, complete statements, field or method declarations, enum entries, macro definitions, or includes.
  • For complete items in comma-separated lists, such as function arguments, braced initializer items, subscript items, declaration parameters, template arguments, template parameters, and enum entries.
  • For conditional right-hand sides after = in assignment statements, alias declarations, and concept definitions.
  • For conditional declaration-prefix modifiers.

This discipline keeps the code easier to read for humans and easier to parse, highlight, and format with tools. Code-analysis tools do not need to reason about partial expressions or statement headers across all conditional-compilation branches.

P.S. There's an ongoing work in https://github.com/elizarov/strictfmt to implement a rule-based source code formatter that correctly parses and formats all the source code when these restrictions are met.

@elizarov
elizarov force-pushed the preprocessor_code_style branch 3 times, most recently from 9b54d57 to 9e51b55 Compare June 11, 2026 08:01
@elizarov
elizarov force-pushed the preprocessor_code_style branch from 9e51b55 to b016a6b Compare August 13, 2026 12:59
@elizarov
elizarov marked this pull request as ready for review August 13, 2026 13:06
@elizarov
elizarov requested a review from kpavlov00 as a code owner August 13, 2026 13:06
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.

1 participant