[clang] Control spacing for attribute printing (PR #174197)

Vassil Vassilev via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 8 11:17:32 PST 2026


================
@@ -124,9 +125,11 @@ namespace {
     void printTemplateArguments(ArrayRef<TemplateArgumentLoc> Args,
                                 const TemplateParameterList *Params);
     enum class AttrPosAsWritten { Default = 0, Left, Right };
-    bool
-    prettyPrintAttributes(const Decl *D,
-                          AttrPosAsWritten Pos = AttrPosAsWritten::Default);
+    AttrVec
+    getPrintableAttributes(const Decl *D,
----------------
vgvassilev wrote:

> I tried to merge it into `prettyPrintAttributes`, but ended up having to pass in a `Prefix` and/or a `Suffix`, and it made it harder to understand what was being printed. Pushing the leading/trailing spaces to the calling code and always having `prettyPrintAttributes` print a space-separated sequence of attrs made it much more obvious to inject spaces or not before and after.

Isn't the prefix suffix determined by the position left/right? Maybe we can have just a single argument needsSpace and determine the rest based on the position?

https://github.com/llvm/llvm-project/pull/174197


More information about the cfe-commits mailing list