[clang] [clang-format] Keep compound literals stable in macro bodies (PR #173771)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Dec 28 18:43:08 PST 2025
================
@@ -528,7 +553,16 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
Tok->setBlockKind(BK_Block);
}
} else {
- Tok->setBlockKind(BK_Unknown);
+ // In macro bodies we try to keep compound literal expressions like
----------------
Lane0218 wrote:
Thanks for the suggestions!
I followed @owenca’s requested direction and switched to a smaller parser-side fix (in `parseParens`) rather than the loop/heuristic in `calculateBraceTypes`. I also added a `TokenAnnotatorTest` regression that checks the brace kind for `&(type){v}` is `BK_BracedInit`.
Thanks again — I agree a more general TokenAnnotator/MatchingParen-based approach could be a good follow-up refactor, but I’m trying to keep this PR minimal.
Tests: FormatTests
https://github.com/llvm/llvm-project/pull/173771
More information about the cfe-commits
mailing list