Skip to content

clang-format does not always remove spaces on the first run when merging empty lines #57052

Closed as not planned
@dantrag

Description

@dantrag

I am running VS Code 1.64.2 on linux, and clang as a part of C/C++ ms-vscode extension (very standard, version 1.10.5, it uses clang 14.0.0 afaik). Using this .clang-format:

BasedOnStyle: Google
Language: Cpp
IndentWidth: 4

and this (reduced as much as possible) cpp file:

image

(note 4 spaces on line 4)

Upon formatting on save (the whole file, not just modified lines), this happens:

image

Line 4 is indented twice (8 spaces). Saving and formatting the file again fixes the indentation (4 spaces). This problem is hard to pinpoint, it disappears upon small changes, for example, empty line before private: is essential, so is the private: line itself. On the other hand, I discovered it in a complex piece of code, with several extra lines after the problematic snippet and the following private: section.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang-formatobsoleteIssues with old (unsupported) versions of LLVM

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions