llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-format Author: bhanuponguru (bhanuponguru) <details> <summary>Changes</summary> Created a new style "ReflowCommentsNoStar: true|false", to disable placing a star when blocked comments are split. Fixes #<!-- -->58710 --- Full diff: https://github.com/llvm/llvm-project/pull/167146.diff 7 Files Affected: - (modified) .clang-format (+3) - (modified) clang/include/clang/Format/Format.h (+13) - (modified) clang/lib/Format/BreakableToken.cpp (+2) - (modified) clang/lib/Format/Format.cpp (+1) - (added) clang/test/Format/ReflowCommentsNoStar.cpp (+2) - (added) clang/test/Format/ReflowCommentsNoStarExpected.cpp (+4) - (added) clang/test/Format/ReflowCommentsNoStarInput.cpp (+3) ``````````diff diff --git a/.clang-format b/.clang-format index ecb44bfabd9aa..609dc68c8cd98 100644 --- a/.clang-format +++ b/.clang-format @@ -1,2 +1,5 @@ BasedOnStyle: LLVM LineEnding: LF +ColumnLimit: 80 +ReflowComments: true +ReflowCommentsNoStar: true \ No newline at end of file diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h index f246defc1fe81..2167544c0bd98 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -4240,6 +4240,19 @@ struct FormatStyle { /// \version 3.8 ReflowCommentsStyle ReflowComments; + /// If reflow comments is enabled, dont include * in the formatted block comment. + /// \code + /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of + /// // information + /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of + /// information */ + /// /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of + /// information and a misaligned second line */ + /// \endcode + + /// \version 22 + bool ReflowCommentsNoStar; + /// Remove optional braces of control statements (``if``, ``else``, ``for``, /// and ``while``) in C++ according to the LLVM coding style. /// \warning diff --git a/clang/lib/Format/BreakableToken.cpp b/clang/lib/Format/BreakableToken.cpp index 994a427517ffc..677aa2026e272 100644 --- a/clang/lib/Format/BreakableToken.cpp +++ b/clang/lib/Format/BreakableToken.cpp @@ -506,6 +506,8 @@ BreakableBlockComment::BreakableBlockComment( } Decoration = "* "; + if (Style.ReflowCommentsNoStar) + Decoration = ""; if (Lines.size() == 1 && !FirstInLine) { // Comments for which FirstInLine is false can start on arbitrary column, // and available horizontal space can be too small to align consecutive diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index dd14fcd72922f..f0bfa60fd76b2 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -1275,6 +1275,7 @@ template <> struct MappingTraits<FormatStyle> { IO.mapOptional("RawStringFormats", Style.RawStringFormats); IO.mapOptional("ReferenceAlignment", Style.ReferenceAlignment); IO.mapOptional("ReflowComments", Style.ReflowComments); + IO.mapOptional("ReflowCommentsNoStar", Style.ReflowCommentsNoStar); IO.mapOptional("RemoveBracesLLVM", Style.RemoveBracesLLVM); IO.mapOptional("RemoveEmptyLinesInUnwrappedLines", Style.RemoveEmptyLinesInUnwrappedLines); diff --git a/clang/test/Format/ReflowCommentsNoStar.cpp b/clang/test/Format/ReflowCommentsNoStar.cpp new file mode 100644 index 0000000000000..d1ce8506c818f --- /dev/null +++ b/clang/test/Format/ReflowCommentsNoStar.cpp @@ -0,0 +1,2 @@ +// RUN: clang-format -style="{ColumnLimit: 80, ReflowComments: true, ReflowCommentsNoStar: true}" %S/ReflowCommentsNoStarInput.cpp > %t +// RUN: diff %t %S/ReflowCommentsNoStarExpected.cpp \ No newline at end of file diff --git a/clang/test/Format/ReflowCommentsNoStarExpected.cpp b/clang/test/Format/ReflowCommentsNoStarExpected.cpp new file mode 100644 index 0000000000000..35ba5e919f820 --- /dev/null +++ b/clang/test/Format/ReflowCommentsNoStarExpected.cpp @@ -0,0 +1,4 @@ +/* erfdfdfdfdfdfd fd fdfd fd fd fd fd fd fd fd fd fd fd fd fd fd fdf df df df df + df df df df df df df fd f */ + +void func() {} diff --git a/clang/test/Format/ReflowCommentsNoStarInput.cpp b/clang/test/Format/ReflowCommentsNoStarInput.cpp new file mode 100644 index 0000000000000..5ec0e32298337 --- /dev/null +++ b/clang/test/Format/ReflowCommentsNoStarInput.cpp @@ -0,0 +1,3 @@ +/* erfdfdfdfdfdfd fd fdfd fd fd fd fd fd fd fd fd fd fd fd fd fd fdf df df df df df df df df df df df fd f */ + +void func() {} `````````` </details> https://github.com/llvm/llvm-project/pull/167146 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
