[clang] [clang-format] Allow open brace with trailing comment (no line break) (PR #89956)
via cfe-commits
cfe-commits at lists.llvm.org
Fri May 31 10:36:22 PDT 2024
================
@@ -1429,6 +1429,37 @@ TEST_F(FormatTestComments, CommentsInStaticInitializers) {
" 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // comment\n"
" 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // comment\n"
" 0x00, 0x00, 0x00, 0x00}; // comment");
+
+ // The usual 'open brace with trailing comment' behaviour is to forcibly
+ // break the trailing comment onto onto a new line -
+ FormatStyle Style = getLLVMStyle();
+ Style.AlignAfterOpenBracket = FormatStyle::BAS_BlockIndent;
+ StringRef Input = "int a[2][2] = {\n"
+ " { // a\n"
+ " 0, // x\n"
+ " 1,\n"
+ " },\n"
+ " {\n"
+ " 2,\n"
+ " 3, // y\n"
+ " }\n"
+ "};";
+ verifyFormat("int a[2][2] = {\n"
+ " {\n"
+ " // a\n"
+ " 0, // x\n"
+ " 1,\n"
+ " },\n"
+ " {\n"
+ " 2,\n"
+ " 3, // y\n"
+ " }\n"
+ "};",
+ Input, Style);
+ // But, especially for nested, multi-dimensional initialization, allowing
+ // open braces with trailing comments can be desirable -
----------------
mydeveloperday wrote:
extraneous - normally we end with a period (.)
https://github.com/llvm/llvm-project/pull/89956
More information about the cfe-commits
mailing list