Skip to content

Commit

Permalink
[Format] Capture FormatStyle by value to avoid use-after-free.
Browse files Browse the repository at this point in the history
Fixes the test failure in 240e29c, reported on the D140058 review thread.
  • Loading branch information
rupprecht committed Dec 16, 2022
1 parent 240e29c commit 5a06334
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions clang/lib/Format/Format.cpp
Expand Up @@ -3404,23 +3404,23 @@ reformat(const FormatStyle &Style, StringRef Code,
if (Style.InsertBraces) {
FormatStyle S = Expanded;
S.InsertBraces = true;
Passes.emplace_back([&](const Environment &Env) {
Passes.emplace_back([&, S](const Environment &Env) {
return BracesInserter(Env, S).process(/*SkipAnnotation=*/true);
});
}

if (Style.RemoveBracesLLVM) {
FormatStyle S = Expanded;
S.RemoveBracesLLVM = true;
Passes.emplace_back([&](const Environment &Env) {
Passes.emplace_back([&, S](const Environment &Env) {
return BracesRemover(Env, S).process(/*SkipAnnotation=*/true);
});
}

if (Style.RemoveSemicolon) {
FormatStyle S = Expanded;
S.RemoveSemicolon = true;
Passes.emplace_back([&](const Environment &Env) {
Passes.emplace_back([&, S](const Environment &Env) {
return SemiRemover(Env, S).process(/*SkipAnnotation=*/true);
});
}
Expand Down

0 comments on commit 5a06334

Please sign in to comment.