[clang] [Format] Configure ASSIGN_OR_RETURN macros for Google style (PR #169037)

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 20 04:33:55 PST 2026


================
@@ -1961,6 +1961,10 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) {
   GoogleStyle.PenaltyBreakBeforeFirstCallParameter = 1;
   GoogleStyle.PenaltyReturnTypeOnItsOwnLine = 200;
 
+  GoogleStyle.Macros.push_back("ASSIGN_OR_RETURN(a, b)=a = (b)");
+  GoogleStyle.Macros.push_back(
+      "ASSIGN_OR_RETURN(a, b, c)=a = (b); if (x) return c");
+
----------------
ilya-biryukov wrote:

This would cause the first argument to be formatted as an expression, but we want to allow declarator.

e.g. the test added below will turn from:
```cpp
ASSIGN_OR_RETURN(MySomewhatLongType* variable,\n"
```
to:
```cpp
ASSIGN_OR_RETURN(MySomewhatLongType * variable,\n"
```

and we don't want that.

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


More information about the cfe-commits mailing list