llvm-project
llvm-project copied to clipboard
[Clang-format 14] `WhitespaceSensitiveMacros` setting is broken
WhitespaceSensitiveMacros
used to completely disable formatting for the specified macros. Starting from Clang-format 14 it no longer does that. It still does something, but I'm not sure what exactly.
Here's a code sample: (C++)
#define FOO(x)
FOO(1+2)
.clang-format
:
WhitespaceSensitiveMacros:
- FOO
Code after formatting:
#define FOO(x)
FOO(1 + 2)
As you can see, formatting introduced a whitespace change despite the setting.
In our codebase, we also used this setting to disable formatting for long multiline macros calls that are not whitespace-sensitive but are uglified by Clang-format. Now we'd need to wrap all of them in // clang-format off
/on
.
@llvm/issue-subscribers-clang-format
We are also hitting this bug in clang-format 14 and I managed to identify the commit that introduces this regression via git bisect.
FYI @ksyx
We are also hitting this bug in clang-format 14 and I managed to identify the commit that introduces this regression via git bisect.
FYI @ksyx
Thanks for reporting! It seems the parser had changed T=UntouchableMacroFunc
to T=FunctionLikeOrFreestandingMacro
in this part of change. Adding a check before setting type
(either check T!=UntouchableMacroFunc
or T==Unknown
, and I only see this type as Untouchable in the type list) do helps, and I am wondering whether it is a good solution.
cc @mkurdej @mydeveloperday
We are also hitting this bug in clang-format 14 and I managed to identify the commit that introduces this regression via git bisect. FYI @ksyx
Thanks for reporting! It seems the parser had changed
T=UntouchableMacroFunc
toT=FunctionLikeOrFreestandingMacro
in this part of change. Adding a check before setting type (either checkT!=UntouchableMacroFunc
orT==Unknown
, and I only see this type as Untouchable in the type list) do helps, and I am wondering whether it is a good solution.cc @mkurdej @mydeveloperday
Another observation: If I add a semicolon after the macro call, things work as expected. In other words, the following won't be reformatted with WhiteSpaceSensitiveMacros
set to FOO
:
#define FOO(x)
FOO(1+2);
Interestingly, all tests for the WhiteSpaceSensitiveFormat
setting in clang/unittests/Format/FormatTest.cpp
use macro calls with semicolons, which is probably why this wasn't caught.
@llvm/issue-subscribers-bug
Revision URI: https://reviews.llvm.org/D123676
@ksyx, thanks for the analysis!
Reverted by 573a5b5.
Related to #57158.
The issue still exists in clang-format 15. Would be cool if the fix could get merged.
Unfortunately we are past the last 15.0.x release.
It would also be fine if this was fixed only in 16.0.0. Would that be feasible?
Yep! It’s in the main branch and will be included by default when the 16.x branch is created.