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 b6f124f948b59..1c3050ec9cf95 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -4250,6 +4250,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 9bbb33cb14502..776267c3ae3ee 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -1276,6 +1276,7 @@ template <> struct MappingTraits { 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() {}