[PATCH] D145262: [clang-format] Treat AttributeMacros more like attribute macros

Jared Grubb via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 3 12:01:40 PST 2023


jaredgrubb created this revision.
jaredgrubb added reviewers: HazardyKnusperkeks, djasper, egorzhdan.
jaredgrubb added a project: clang-format.
Herald added a project: All.
jaredgrubb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

I noticed that clang-format was inserting some strange indentation whenever I used custom "attribute-like macros"
(things like `FOO_EXTERN` to wrap attribute-visible-default, or macros with parentheses like `NS_SWIFT_NAME(...)`).

There are two parts to this fix:

- tokenize the paren after an `AttributeMacro` as a `TT_AttributeParen`
- treat a `AttributeMacro`-without-paren the same as one with a paren (eg, the `FOO_EXTERN` case)

I added a new test-case to differentiate a macro that is or is-not a `AttributeMacro`; also handled whether the
`ColumnLimit` is set to infinite (0) or a finite value, as part of this patch is in `ContinuationIndenter`.

There may be other places that need to handle `TT_AttributeMacro` better, but this is at least a step in the right
direction.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145262

Files:
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/test/Format/objc-definitions.m

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145262.502209.patch
Type: text/x-patch
Size: 4335 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230303/aaf389f9/attachment.bin>


More information about the cfe-commits mailing list