llvm / llvm-project

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

clang-format: Incorrectly formats multiplication as if it was pointer dereference #110879

Open griffin2000 opened 1 day ago

griffin2000 commented 1 day ago

In the attached example (test.cpp.txt, renamed to .txt so it can be attached) using the attached .clang-format settings (clang-format.txt, also renamed to .txt and . prefix removed), the second line of the struct is formatted by clang-format (v 14.0.0) as if it was a pointer de-reference, and the space following the * is removed.

So this...


constexpr Thingy kConfig = {
    {
        (uint16_t)(kScale * kThing.width_pixels),
        (uint16_t)(kScale * kThing.height_pixels),
    },
};

Becomes:

constexpr Thingy kConfig = {
    {
        (uint16_t)(kScale * kThing.width_pixels),
        (uint16_t)(kScale *kThing.height_pixels),
    },
};

The expected behaviour is the space should be maintained, or added if it it is removed (if either the space before or after the * is removed on the previous line, it will be added back by clang-format)

EugeneZelenko commented 1 day ago

Could you please try 19 or main branch?

griffin2000 commented 1 day ago

Could you please try 19 or main branch?

Yup just verified with https://github.com/llvm/llvm-project/releases/download/llvmorg-19.1.0/clang+llvm-19.1.0-x86_64-pc-windows-msvc.tar.xz, same result

griffin2000 commented 10 hours ago

Wow! Quick turnaround. Thanks @owenca