Author: mydeveloperday Date: 2021-10-20T09:09:31+01:00 New Revision: 57e00810edd7c4359e3de9242bcbd8874d58dc64
URL: https://github.com/llvm/llvm-project/commit/57e00810edd7c4359e3de9242bcbd8874d58dc64 DIFF: https://github.com/llvm/llvm-project/commit/57e00810edd7c4359e3de9242bcbd8874d58dc64.diff LOG: [clang-format] [PR52015] clang-format should put __attribute__((foo)) on its own line before @interface / @implementation / @protocol https://bugs.llvm.org/show_bug.cgi?id=52015 A newline should be place between attribute and @ for objectivec Reviewed By: benhamilton, HazardyKnusperkeks Differential Revision: https://reviews.llvm.org/D111975 Added: Modified: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTestObjC.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 29580ebe5ebf..e6be3a918034 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -3832,6 +3832,10 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line, 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 index 78be44e7a3f2..e421082796c5 100644 --- a/clang/unittests/Format/FormatTestObjC.cpp +++ b/clang/unittests/Format/FormatTestObjC.cpp @@ -1526,6 +1526,18 @@ TEST_F(FormatTestObjC, IfNotUnlikely) { " [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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits