llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.92k stars 11.52k forks source link

Clang format fails to indent on newline if `__attribute__((...))` is present between a variable's type and its name #74784

Open alanzhao1 opened 9 months ago

alanzhao1 commented 9 months ago

Originally reported on https://crbug.com/1462405

Style: Chromium

clang-format version:

~/src/depot_tools/clang-format --version
clang-format version 18.0.0 (https://chromium.googlesource.com/a/external/github.com/llvm/llvm-project 10664813fca8d5ccbfd90bae9e791b7062dabd7c

clang-format would wrap

RenderWidgetHostViewCocoa* __attribute__((objc_precise_lifetime)) keepSelfAlive = self;

as

RenderWidgetHostViewCocoa* __attribute__((objc_precise_lifetime))
keepSelfAlive = self;

without indenting the second line. This makes it look like the two lines are separate and that keepSelfAlive is being assigned.

Ideally, clang-format should return something like

RenderWidgetHostViewCocoa*
  __attribute__((objc_precise_lifetime)) keepSelfAlive = self;

This reproduces for C++ files as well, not just Objective-C.

llvmbot commented 9 months ago

@llvm/issue-subscribers-clang-format

Author: Alan Zhao (alanzhao1)

Originally reported on https://crbug.com/1462405 Style: Chromium clang-format version: ```sh ~/src/depot_tools/clang-format --version clang-format version 18.0.0 (https://chromium.googlesource.com/a/external/github.com/llvm/llvm-project 10664813fca8d5ccbfd90bae9e791b7062dabd7c ``` clang-format would wrap ```objc RenderWidgetHostViewCocoa* __attribute__((objc_precise_lifetime)) keepSelfAlive = self; ``` as ```objc RenderWidgetHostViewCocoa* __attribute__((objc_precise_lifetime)) keepSelfAlive = self; ``` without indenting the second line. This makes it look like the two lines are separate and that `keepSelfAlive` is being assigned. Ideally, clang-format should return something like ```objc RenderWidgetHostViewCocoa* __attribute__((objc_precise_lifetime)) keepSelfAlive = self; ``` This reproduces for C++ files as well, not just Objective-C.