Author: Marek Kurdej Date: 2022-01-24T18:09:20+01:00 New Revision: 50999e82e8844615b1ae53edb9d56cdcace91b04
URL: https://github.com/llvm/llvm-project/commit/50999e82e8844615b1ae53edb9d56cdcace91b04 DIFF: https://github.com/llvm/llvm-project/commit/50999e82e8844615b1ae53edb9d56cdcace91b04.diff LOG: [clang-format] Space between attribute closing parenthesis and qualified type colon. Fixes https://github.com/llvm/llvm-project/issues/35711. Reviewed By: MyDeveloperDay, HazardyKnusperkeks, owenpan Differential Revision: https://reviews.llvm.org/D117894 Added: Modified: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index b9535f7965598..a8cd1e30f74e5 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -3339,6 +3339,9 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, if (Left.is(tok::ellipsis) && Right.is(tok::identifier) && Line.First->is(Keywords.kw_import)) return false; + // Space in __attribute__((attr)) ::type. + if (Left.is(TT_AttributeParen) && Right.is(tok::coloncolon)) + return true; if (Left.is(tok::kw_operator)) return Right.is(tok::coloncolon); diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 0ddbac48d716d..c4e0e14ce5bcd 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -10028,6 +10028,7 @@ TEST_F(FormatTest, UnderstandsAttributes) { verifyFormat("SomeType s __attribute__((unused)) (InitValue);"); verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa __attribute__((unused))\n" "aaaaaaaaaaaaaaaaaaaaaaa(int i);"); + verifyFormat("__attribute__((nodebug)) ::qualified_type f();"); FormatStyle AfterType = getLLVMStyle(); AfterType.AlwaysBreakAfterReturnType = FormatStyle::RTBS_All; verifyFormat("__attribute__((nodebug)) void\n" @@ -10131,6 +10132,7 @@ TEST_F(FormatTest, UnderstandsSquareAttributes) { verifyFormat("class [[nodiscard]] f {\npublic:\n f() {}\n}"); verifyFormat("class [[deprecated(\"so sorry\")]] f {\npublic:\n f() {}\n}"); verifyFormat("class [[gnu::unused]] f {\npublic:\n f() {}\n}"); + verifyFormat("[[nodiscard]] ::qualified_type f();"); // Make sure we do not mistake attributes for array subscripts. verifyFormat("int a() {}\n" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits