diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -3832,6 +3832,10 @@ Style.AllowShortBlocksOnASingleLine == FormatStyle::SBS_Never) return true; + // Ensure wrapping after __attribute__((XX)) and @interface etc. + if (Left.is(TT_AttributeParen) && Right.is(TT_ObjCDecl)) + return true; + if (Left.is(TT_LambdaLBrace)) { if (IsFunctionArgument(Left) && Style.AllowShortLambdasOnASingleLine == FormatStyle::SLS_Inline) diff --git a/clang/unittests/Format/FormatTestObjC.cpp b/clang/unittests/Format/FormatTestObjC.cpp --- a/clang/unittests/Format/FormatTestObjC.cpp +++ b/clang/unittests/Format/FormatTestObjC.cpp @@ -1526,6 +1526,18 @@ " [obj func:arg2];"); } +TEST_F(FormatTestObjC, Attributes) { + verifyFormat("__attribute__((objc_subclassing_restricted))\n" + "@interface Foo\n" + "@end"); + verifyFormat("__attribute__((objc_subclassing_restricted))\n" + "@protocol Foo\n" + "@end"); + verifyFormat("__attribute__((objc_subclassing_restricted))\n" + "@implementation Foo\n" + "@end"); +} + } // end namespace } // end namespace format } // end namespace clang