@@ -1414,6 +1414,12 @@ class FormatWalker : public ASTWalker {
1414
1414
// interpolated string literal.
1415
1415
if (E->getArgs () == Args)
1416
1416
ContextLoc = getContextLocForArgs (SM, E);
1417
+ } else if (auto *D = Parent.getAsDecl ()) {
1418
+ if (auto *MED = dyn_cast<MacroExpansionDecl>(D)) {
1419
+ if (MED->getArgs () == Args) {
1420
+ ContextLoc = MED->getStartLoc ();
1421
+ }
1422
+ }
1417
1423
}
1418
1424
1419
1425
auto Action = HandlePre (Args, Args->isImplicit ());
@@ -2700,10 +2706,17 @@ class FormatWalker : public ASTWalker {
2700
2706
if (TrailingTarget)
2701
2707
return std::nullopt;
2702
2708
2703
- auto *ParentE = Parent.getAsExpr ();
2704
- assert (ParentE && " Trailing closures can only occur in expr contexts" );
2705
- return IndentContext{
2706
- ContextLoc, !OutdentChecker::hasOutdent (SM, ContextToEnd, ParentE)};
2709
+ bool hasOutdent;
2710
+ if (auto *ParentE = Parent.getAsExpr ()) {
2711
+ hasOutdent = OutdentChecker::hasOutdent (SM, ContextToEnd, ParentE);
2712
+ } else if (auto *ParentD = Parent.getAsDecl ()) {
2713
+ assert (isa<MacroExpansionDecl>(ParentD) && " Trailing closures in decls can only occur in macro expansions" );
2714
+ hasOutdent = OutdentChecker::hasOutdent (SM, ContextToEnd, ParentD);
2715
+ } else {
2716
+ assert (false && " Trailing closures can only occur in expr contexts and macro expansions" );
2717
+ return std::nullopt;
2718
+ }
2719
+ return IndentContext{ContextLoc, !hasOutdent};
2707
2720
}
2708
2721
2709
2722
std::optional<IndentContext>
0 commit comments