llvm / llvm-project

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

clang-format mis-annotates pointer/reference in range-based `for` loops #109358

Open owenca opened 2 hours ago

owenca commented 2 hours ago

This is split from #60146 and reported by @jeremyong.

I'm seeing this also with an even simpler repro:

for (int i = 0; Foo& foo : foos)

turns into

for (int i = 0; Foo & foo : foos)

even with PointerAlignment: Left. I am assuming that in the presence of scoped declaration statements, subsequent & operators are parsed as bitwise-and operators.

llvmbot commented 2 hours ago

@llvm/issue-subscribers-clang-format

Author: Owen Pan (owenca)

This is split from #60146 and reported by @jeremyong. > I'm seeing this also with an even simpler repro: > > ```c++ > for (int i = 0; Foo& foo : foos) > ``` > > turns into > > ```c++ > for (int i = 0; Foo & foo : foos) > ``` > > even with `PointerAlignment: Left`. I am assuming that in the presence of scoped declaration statements, subsequent `&` operators are parsed as bitwise-and operators.