[PATCH] D137181: [clang-format] Don't use 'PPIndentWidth' inside multi-line macros

Noah Goldstein via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 9 14:02:40 PST 2022


goldstein.w.n added a comment.

In D137181#3916605 <https://reviews.llvm.org/D137181#3916605>, @owenpan wrote:

> In D137181#3916558 <https://reviews.llvm.org/D137181#3916558>, @goldstein.w.n wrote:
>
>> In D137181#3916547 <https://reviews.llvm.org/D137181#3916547>, @owenpan wrote:
>>
>>> Yes, if there is a header guard. Otherwise, set `PPLevel` to `PPBranchLevel + 1`.
>>
>> That fails alot of the tests for me.
>>
>> maybe you did something different?
>
> Here is what I did:
>
>   $ git diff UnwrappedLineParser.cpp
>   diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
>   index 25d9018fa109..ab3b9c53ee54 100644
>   --- a/clang/lib/Format/UnwrappedLineParser.cpp
>   +++ b/clang/lib/Format/UnwrappedLineParser.cpp
>   @@ -197,6 +197,7 @@ public:
>        PreBlockLine = std::move(Parser.Line);
>        Parser.Line = std::make_unique<UnwrappedLine>();
>        Parser.Line->Level = PreBlockLine->Level;
>   +    Parser.Line->PPLevel = PreBlockLine->PPLevel;
>        Parser.Line->InPPDirective = PreBlockLine->InPPDirective;
>        Parser.Line->InMacroBody = PreBlockLine->InMacroBody;
>      }
>   @@ -1274,6 +1275,10 @@ void UnwrappedLineParser::parsePPDefine() {
>      addUnwrappedLine();
>      ++Line->Level;
>      Line->InMacroBody = true;
>   +  if (Style.IndentPPDirectives != FormatStyle::PPDIS_None) {
>   +    Line->PPLevel =
>   +        IncludeGuard == IG_Defined ? PPBranchLevel : PPBranchLevel + 1;
>   +  }
>    
>      // Errors during a preprocessor directive can only affect the layout of the
>      // preprocessor directive, and thus we ignore them. An alternative approach

You're right this works (but off by one). Updated patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137181/new/

https://reviews.llvm.org/D137181



More information about the cfe-commits mailing list