[clang] [Clang][Docs] use CommonOptionsParser::create instead of protected constructor (NFC) (PR #70427)

2023-10-27 Thread Kohei Asano via cfe-commits

https://github.com/khei4 created https://github.com/llvm/llvm-project/pull/70427

This patch fixes the code example on CommonOptionParser on 
https://intel.github.io/llvm-docs/clang/LibTooling.html

CommonOptionParser's constructor is protected and we can use 
`CommonOptionParser::create` instead of that.

I'm still not so sure whether other old examples are around there.

>From 5b781734df6d3c49a6c387374c980693392fcabf Mon Sep 17 00:00:00 2001
From: khei4 
Date: Fri, 27 Oct 2023 17:46:34 +0900
Subject: [PATCH] use: create instead of protected Constructor

---
 clang/docs/LibTooling.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/LibTooling.rst b/clang/docs/LibTooling.rst
index df50dcebf9b83c7..cf0e0d005f45e16 100644
--- a/clang/docs/LibTooling.rst
+++ b/clang/docs/LibTooling.rst
@@ -71,7 +71,7 @@ and automatic location of the compilation database using 
source files paths.
   int main(int argc, const char **argv) {
 // CommonOptionsParser constructor will parse arguments and create a
 // CompilationDatabase.  In case of error it will terminate the program.
-CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
+auto OptionsParser = CommonOptionsParser::create(argc, argv, 
MyToolCategory);
 
 // Use OptionsParser.getCompilations() and 
OptionsParser.getSourcePathList()
 // to retrieve CompilationDatabase and the list of input file paths.

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Docs] use CommonOptionsParser::create instead of protected constructor (NFC) (PR #70427)

2023-10-27 Thread Kohei Asano via cfe-commits

https://github.com/khei4 converted_to_draft 
https://github.com/llvm/llvm-project/pull/70427
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Docs] use CommonOptionsParser::create instead of protected constructor (NFC) (PR #70427)

2023-10-27 Thread Kohei Asano via cfe-commits

https://github.com/khei4 updated https://github.com/llvm/llvm-project/pull/70427

>From 1ae7edddc79a0e96fd4b142d09b0752aa3d9ff85 Mon Sep 17 00:00:00 2001
From: khei4 
Date: Fri, 27 Oct 2023 17:46:34 +0900
Subject: [PATCH] use: create instead of protected Constructor

handle: expected
---
 clang/docs/LibTooling.rst | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/docs/LibTooling.rst b/clang/docs/LibTooling.rst
index df50dcebf9b83c7..73f7deb2dd87627 100644
--- a/clang/docs/LibTooling.rst
+++ b/clang/docs/LibTooling.rst
@@ -69,9 +69,16 @@ and automatic location of the compilation database using 
source files paths.
   static llvm::cl::OptionCategory MyToolCategory("my-tool options");
 
   int main(int argc, const char **argv) {
-// CommonOptionsParser constructor will parse arguments and create a
-// CompilationDatabase.  In case of error it will terminate the program.
-CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
+// CommonOptionsParser::create will parse arguments and create a
+// CompilationDatabase. In case of error it will terminate the program.
+llvm::Expected Expected =
+CommonOptionsParser::create(argc, argv, MyToolCategory);
+if (!Expected)
+{
+  llvm::errs() << Expected.takeError();
+  return 1;
+}
+CommonOptionsParser &OptionsParser = Expected.get();
 
 // Use OptionsParser.getCompilations() and 
OptionsParser.getSourcePathList()
 // to retrieve CompilationDatabase and the list of input file paths.

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Docs] use CommonOptionsParser::create instead of protected constructor (NFC) (PR #70427)

2023-10-27 Thread Kohei Asano via cfe-commits

https://github.com/khei4 updated https://github.com/llvm/llvm-project/pull/70427

>From f9f61fd520727d1e03269af4b5c1e40119d7524e Mon Sep 17 00:00:00 2001
From: khei4 
Date: Fri, 27 Oct 2023 17:46:34 +0900
Subject: [PATCH] use: create instead of protected Constructor

handle: expected

fix: later example also
---
 clang/docs/LibTooling.rst | 22 ++
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/clang/docs/LibTooling.rst b/clang/docs/LibTooling.rst
index df50dcebf9b83c7..2f60b8cab70c5a3 100644
--- a/clang/docs/LibTooling.rst
+++ b/clang/docs/LibTooling.rst
@@ -69,9 +69,16 @@ and automatic location of the compilation database using 
source files paths.
   static llvm::cl::OptionCategory MyToolCategory("my-tool options");
 
   int main(int argc, const char **argv) {
-// CommonOptionsParser constructor will parse arguments and create a
-// CompilationDatabase.  In case of error it will terminate the program.
-CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
+// CommonOptionsParser::create will parse arguments and create a
+// CompilationDatabase. In case of error it will terminate the program.
+llvm::Expected Expected =
+CommonOptionsParser::create(argc, argv, MyToolCategory);
+if (!Expected)
+{
+  llvm::errs() << Expected.takeError();
+  return 1;
+}
+CommonOptionsParser &OptionsParser = Expected.get();
 
 // Use OptionsParser.getCompilations() and 
OptionsParser.getSourcePathList()
 // to retrieve CompilationDatabase and the list of input file paths.
@@ -133,7 +140,14 @@ version of this example tool is also checked into the 
clang tree at
   static cl::extrahelp MoreHelp("\nMore help text...\n");
 
   int main(int argc, const char **argv) {
-CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
+Expected Expected =
+CommonOptionsParser::create(argc, argv, MyToolCategory);
+if (!Expected)
+{
+  errs() << Expected.takeError();
+  return 1;
+}
+CommonOptionsParser &OptionsParser = Expected.get();
 ClangTool Tool(OptionsParser.getCompilations(),
OptionsParser.getSourcePathList());
 return Tool.run(newFrontendActionFactory().get());

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Docs] use CommonOptionsParser::create instead of protected constructor (NFC) (PR #70427)

2023-10-27 Thread Kohei Asano via cfe-commits

https://github.com/khei4 updated https://github.com/llvm/llvm-project/pull/70427

>From 166f580fda7a7cf4b87b167be03777d28638feff Mon Sep 17 00:00:00 2001
From: khei4 
Date: Fri, 27 Oct 2023 17:46:34 +0900
Subject: [PATCH] use create instead of protected Constructor

---
 clang/docs/LibTooling.rst | 25 -
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/clang/docs/LibTooling.rst b/clang/docs/LibTooling.rst
index df50dcebf9b83c7..0bb293be9d3c952 100644
--- a/clang/docs/LibTooling.rst
+++ b/clang/docs/LibTooling.rst
@@ -63,15 +63,23 @@ and automatic location of the compilation database using 
source files paths.
   #include "llvm/Support/CommandLine.h"
 
   using namespace clang::tooling;
+  using namespace llvm;
 
   // Apply a custom category to all command-line options so that they are the
   // only ones displayed.
-  static llvm::cl::OptionCategory MyToolCategory("my-tool options");
+  static cl::OptionCategory MyToolCategory("my-tool options");
 
   int main(int argc, const char **argv) {
-// CommonOptionsParser constructor will parse arguments and create a
-// CompilationDatabase.  In case of error it will terminate the program.
-CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
+// CommonOptionsParser::create will parse arguments and create a
+// CompilationDatabase. In case of error it will terminate the program.
+Expected Expected =
+CommonOptionsParser::create(argc, argv, MyToolCategory);
+if (!Expected)
+{
+  errs() << Expected.takeError();
+  return 1;
+}
+CommonOptionsParser &OptionsParser = Expected.get();
 
 // Use OptionsParser.getCompilations() and 
OptionsParser.getSourcePathList()
 // to retrieve CompilationDatabase and the list of input file paths.
@@ -133,7 +141,14 @@ version of this example tool is also checked into the 
clang tree at
   static cl::extrahelp MoreHelp("\nMore help text...\n");
 
   int main(int argc, const char **argv) {
-CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
+Expected Expected =
+CommonOptionsParser::create(argc, argv, MyToolCategory);
+if (!Expected)
+{
+  errs() << Expected.takeError();
+  return 1;
+}
+CommonOptionsParser &OptionsParser = Expected.get();
 ClangTool Tool(OptionsParser.getCompilations(),
OptionsParser.getSourcePathList());
 return Tool.run(newFrontendActionFactory().get());

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Docs] use CommonOptionsParser::create instead of protected constructor on libTooling tutorial (NFC) (PR #70427)

2023-10-27 Thread Kohei Asano via cfe-commits

https://github.com/khei4 edited https://github.com/llvm/llvm-project/pull/70427
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Docs] use CommonOptionsParser::create instead of protected constructor on libTooling tutorial (NFC) (PR #70427)

2023-10-27 Thread Kohei Asano via cfe-commits

https://github.com/khei4 updated https://github.com/llvm/llvm-project/pull/70427

>From 166f580fda7a7cf4b87b167be03777d28638feff Mon Sep 17 00:00:00 2001
From: khei4 
Date: Fri, 27 Oct 2023 17:46:34 +0900
Subject: [PATCH 1/2] use create instead of protected Constructor

---
 clang/docs/LibTooling.rst | 25 -
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/clang/docs/LibTooling.rst b/clang/docs/LibTooling.rst
index df50dcebf9b83c7..0bb293be9d3c952 100644
--- a/clang/docs/LibTooling.rst
+++ b/clang/docs/LibTooling.rst
@@ -63,15 +63,23 @@ and automatic location of the compilation database using 
source files paths.
   #include "llvm/Support/CommandLine.h"
 
   using namespace clang::tooling;
+  using namespace llvm;
 
   // Apply a custom category to all command-line options so that they are the
   // only ones displayed.
-  static llvm::cl::OptionCategory MyToolCategory("my-tool options");
+  static cl::OptionCategory MyToolCategory("my-tool options");
 
   int main(int argc, const char **argv) {
-// CommonOptionsParser constructor will parse arguments and create a
-// CompilationDatabase.  In case of error it will terminate the program.
-CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
+// CommonOptionsParser::create will parse arguments and create a
+// CompilationDatabase. In case of error it will terminate the program.
+Expected Expected =
+CommonOptionsParser::create(argc, argv, MyToolCategory);
+if (!Expected)
+{
+  errs() << Expected.takeError();
+  return 1;
+}
+CommonOptionsParser &OptionsParser = Expected.get();
 
 // Use OptionsParser.getCompilations() and 
OptionsParser.getSourcePathList()
 // to retrieve CompilationDatabase and the list of input file paths.
@@ -133,7 +141,14 @@ version of this example tool is also checked into the 
clang tree at
   static cl::extrahelp MoreHelp("\nMore help text...\n");
 
   int main(int argc, const char **argv) {
-CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
+Expected Expected =
+CommonOptionsParser::create(argc, argv, MyToolCategory);
+if (!Expected)
+{
+  errs() << Expected.takeError();
+  return 1;
+}
+CommonOptionsParser &OptionsParser = Expected.get();
 ClangTool Tool(OptionsParser.getCompilations(),
OptionsParser.getSourcePathList());
 return Tool.run(newFrontendActionFactory().get());

>From d54e38952171b69310a0068318e2484c719e0658 Mon Sep 17 00:00:00 2001
From: khei4 
Date: Fri, 27 Oct 2023 19:14:18 +0900
Subject: [PATCH 2/2] adjust: notations to example on LibASTMatchersTutorial

---
 clang/docs/LibTooling.rst | 21 +
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/clang/docs/LibTooling.rst b/clang/docs/LibTooling.rst
index 0bb293be9d3c952..8ef59da67417ba3 100644
--- a/clang/docs/LibTooling.rst
+++ b/clang/docs/LibTooling.rst
@@ -72,14 +72,13 @@ and automatic location of the compilation database using 
source files paths.
   int main(int argc, const char **argv) {
 // CommonOptionsParser::create will parse arguments and create a
 // CompilationDatabase. In case of error it will terminate the program.
-Expected Expected =
-CommonOptionsParser::create(argc, argv, MyToolCategory);
-if (!Expected)
-{
-  errs() << Expected.takeError();
+auto ExpectedParser = CommonOptionsParser::create(argc, argv, 
MyToolCategory);
+if (!ExpectedParser) {
+  // Fail gracefully for unsupported options.
+  llvm::errs() << ExpectedParser.takeError();
   return 1;
 }
-CommonOptionsParser &OptionsParser = Expected.get();
+CommonOptionsParser& OptionsParser = ExpectedParser.get();
 
 // Use OptionsParser.getCompilations() and 
OptionsParser.getSourcePathList()
 // to retrieve CompilationDatabase and the list of input file paths.
@@ -141,14 +140,12 @@ version of this example tool is also checked into the 
clang tree at
   static cl::extrahelp MoreHelp("\nMore help text...\n");
 
   int main(int argc, const char **argv) {
-Expected Expected =
-CommonOptionsParser::create(argc, argv, MyToolCategory);
-if (!Expected)
-{
-  errs() << Expected.takeError();
+auto ExpectedParser = CommonOptionsParser::create(argc, argv, 
MyToolCategory);
+if (!ExpectedParser) {
+  llvm::errs() << ExpectedParser.takeError();
   return 1;
 }
-CommonOptionsParser &OptionsParser = Expected.get();
+CommonOptionsParser& OptionsParser = ExpectedParser.get();
 ClangTool Tool(OptionsParser.getCompilations(),
OptionsParser.getSourcePathList());
 return Tool.run(newFrontendActionFactory().get());

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Docs] use CommonOptionsParser::create instead of protected constructor on libTooling tutorial (NFC) (PR #70427)

2023-10-27 Thread Kohei Asano via cfe-commits

https://github.com/khei4 edited https://github.com/llvm/llvm-project/pull/70427
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Docs] use CommonOptionsParser::create instead of protected constructor on libTooling tutorial (NFC) (PR #70427)

2023-10-27 Thread Kohei Asano via cfe-commits

https://github.com/khei4 updated https://github.com/llvm/llvm-project/pull/70427

>From 12e29c46366e93c98c96e7561258bc83f66755c1 Mon Sep 17 00:00:00 2001
From: khei4 
Date: Fri, 27 Oct 2023 17:46:34 +0900
Subject: [PATCH] use create instead of protected Constructor

---
 clang/docs/LibTooling.rst | 22 +-
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/clang/docs/LibTooling.rst b/clang/docs/LibTooling.rst
index df50dcebf9b83c7..8ef59da67417ba3 100644
--- a/clang/docs/LibTooling.rst
+++ b/clang/docs/LibTooling.rst
@@ -63,15 +63,22 @@ and automatic location of the compilation database using 
source files paths.
   #include "llvm/Support/CommandLine.h"
 
   using namespace clang::tooling;
+  using namespace llvm;
 
   // Apply a custom category to all command-line options so that they are the
   // only ones displayed.
-  static llvm::cl::OptionCategory MyToolCategory("my-tool options");
+  static cl::OptionCategory MyToolCategory("my-tool options");
 
   int main(int argc, const char **argv) {
-// CommonOptionsParser constructor will parse arguments and create a
-// CompilationDatabase.  In case of error it will terminate the program.
-CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
+// CommonOptionsParser::create will parse arguments and create a
+// CompilationDatabase. In case of error it will terminate the program.
+auto ExpectedParser = CommonOptionsParser::create(argc, argv, 
MyToolCategory);
+if (!ExpectedParser) {
+  // Fail gracefully for unsupported options.
+  llvm::errs() << ExpectedParser.takeError();
+  return 1;
+}
+CommonOptionsParser& OptionsParser = ExpectedParser.get();
 
 // Use OptionsParser.getCompilations() and 
OptionsParser.getSourcePathList()
 // to retrieve CompilationDatabase and the list of input file paths.
@@ -133,7 +140,12 @@ version of this example tool is also checked into the 
clang tree at
   static cl::extrahelp MoreHelp("\nMore help text...\n");
 
   int main(int argc, const char **argv) {
-CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
+auto ExpectedParser = CommonOptionsParser::create(argc, argv, 
MyToolCategory);
+if (!ExpectedParser) {
+  llvm::errs() << ExpectedParser.takeError();
+  return 1;
+}
+CommonOptionsParser& OptionsParser = ExpectedParser.get();
 ClangTool Tool(OptionsParser.getCompilations(),
OptionsParser.getSourcePathList());
 return Tool.run(newFrontendActionFactory().get());

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Docs] use CommonOptionsParser::create instead of protected constructor on libTooling tutorial (NFC) (PR #70427)

2023-10-27 Thread Kohei Asano via cfe-commits

https://github.com/khei4 ready_for_review 
https://github.com/llvm/llvm-project/pull/70427
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-05 Thread Kohei Asano via cfe-commits

https://github.com/khei4 updated https://github.com/llvm/llvm-project/pull/93634

>From c0138dfe4f2cf3d9925fac46b3ba7d9a9963820a Mon Sep 17 00:00:00 2001
From: Kohei Asano 
Date: Mon, 3 Jun 2024 09:15:44 +0900
Subject: [PATCH] [clang-format] add an option to insert a space only for empty
 braces

---
 clang/docs/ClangFormatStyleOptions.rst  |  97 -
 clang/include/clang/Format/Format.h | 112 ++--
 clang/lib/Format/Format.cpp |  40 ++-
 clang/lib/Format/TokenAnnotator.cpp |  19 +++-
 clang/lib/Format/UnwrappedLineFormatter.cpp |  12 ++-
 clang/unittests/Format/ConfigParseTest.cpp  |   9 +-
 clang/unittests/Format/FormatTest.cpp   |  99 -
 7 files changed, 368 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index bb00c20922d36..9879d122f8d57 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6036,12 +6036,103 @@ the configuration (without a prefix: ``Auto``).
 
 **SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ 
`
   If ``true``, spaces will be inserted into ``{}``.
+  This option is **deprecated**. The previous behavior is preserved by using
+  ``SpaceInEmptyBraces`` with ``Custom`` and by setting ``Block`` in
+  ``SpaceInEmptyBracesOptions`` to ``true``.
+
+.. _SpaceInEmptyBraces:
+
+**SpaceInEmptyBraces** (``SpaceInEmptyBracesStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Defines in which cases spaces will be inserted in empty braces.
+
+  Possible values:
+
+  * ``SIEBO_Never`` (in configuration: ``Never``)
+Never put a space in empty braces.
+
+.. code-block:: c++
+
+   void f() {}
+   T x{};
+   while (true) {}
+   struct U1 {};
+   union U2 {};
+   class U3 {};
+   enum U4 {};
+
+  * ``SIEBO_Custom`` (in configuration: ``Custom``)
+Configure each individual space in empty braces in
+`SpacesInEmptyBracesOptions`.
+
+
+
+.. _SpaceInEmptyBracesOptions:
+
+**SpaceInEmptyBracesOptions** (``SpaceInEmptyBracesCustom``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Control of individual spaces in empty braces.
+
+  If ``SpaceInEmptyBraces`` is set to ``Custom``, use this to specify
+  how each individual space in empty braces case should be handled.
+  Otherwise, this is ignored.
+
+  .. code-block:: yaml
+
+# Example of usage:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Function: true
+  Record: false
+  InitList: true
+  Block: false
+
+  Nested configuration flags:
+
+  Precise control over the spacing in empty braces.
 
   .. code-block:: c++
 
- true:false:
- void f() { }   vs.   void f() {}
- while (true) { } while (true) {}
+# Should be declared this way:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Function: true
+  Record: false
+  InitList: true
+  Block: false
+
+  * ``bool Function`` Put a space in empty braces of function definition.
+
+.. code-block:: c++
+
+   true:  false:
+   void f() { }   vs. void f() {}
+
+  * ``bool Record`` Put a space in empty braces of record/struct definition.
+
+.. code-block:: c++
+
+   true:  false:
+   struct U1 { }; vs. struct U1 {};
+   union U2 { };  union U2 {};
+   class U3 { };  class U3 {};
+   enum U4 { };   enum U4 {};
+
+  * ``bool InitList`` Put a space in empty braces of initializer list.
+
+.. code-block:: c++
+
+   true:  false:
+   T x{ };vs. T x{};
+
+  * ``bool Block`` Put a space in empty braces of other blocks, including 
functions and
+record, compatible with ``SpaceInEmptyBlock``.
+
+.. code-block:: c++
+
+   true:  false:
+   void f() { }   vs. void f() {}
+   enum Unit { }; enum Unit {};
+   while (true) { }   while (true) {}
+
 
 .. _SpaceInEmptyParentheses:
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 4fd6e013df25b..a6d8700ad9aa3 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4493,13 +4493,11 @@ struct FormatStyle {
   bool SpaceBeforeRangeBasedForLoopColon;
 
   /// If ``true``, spaces will be inserted into ``{}``.
-  /// \code
-  ///true:false:
-  ///void f() { }   vs.   void f() {}
-  ///while (true) { } while (true) {}
-  /// \endcode
+  /// This option is **deprecated**. The previous behavior is preserved by 

[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-05 Thread Kohei Asano via cfe-commits

https://github.com/khei4 updated https://github.com/llvm/llvm-project/pull/93634

>From 1a953e35c2996e31c526e0caf0bbbecaf13c1c63 Mon Sep 17 00:00:00 2001
From: Kohei Asano 
Date: Mon, 3 Jun 2024 09:15:44 +0900
Subject: [PATCH] [clang-format] add an option to insert a space only for empty
 braces

---
 clang/docs/ClangFormatStyleOptions.rst  |  97 -
 clang/include/clang/Format/Format.h | 112 ++--
 clang/lib/Format/Format.cpp |  40 ++-
 clang/lib/Format/TokenAnnotator.cpp |  19 +++-
 clang/lib/Format/UnwrappedLineFormatter.cpp |  13 ++-
 clang/unittests/Format/ConfigParseTest.cpp  |   9 +-
 clang/unittests/Format/FormatTest.cpp   |  99 -
 7 files changed, 369 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index bb00c20922d36..9879d122f8d57 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6036,12 +6036,103 @@ the configuration (without a prefix: ``Auto``).
 
 **SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ 
`
   If ``true``, spaces will be inserted into ``{}``.
+  This option is **deprecated**. The previous behavior is preserved by using
+  ``SpaceInEmptyBraces`` with ``Custom`` and by setting ``Block`` in
+  ``SpaceInEmptyBracesOptions`` to ``true``.
+
+.. _SpaceInEmptyBraces:
+
+**SpaceInEmptyBraces** (``SpaceInEmptyBracesStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Defines in which cases spaces will be inserted in empty braces.
+
+  Possible values:
+
+  * ``SIEBO_Never`` (in configuration: ``Never``)
+Never put a space in empty braces.
+
+.. code-block:: c++
+
+   void f() {}
+   T x{};
+   while (true) {}
+   struct U1 {};
+   union U2 {};
+   class U3 {};
+   enum U4 {};
+
+  * ``SIEBO_Custom`` (in configuration: ``Custom``)
+Configure each individual space in empty braces in
+`SpacesInEmptyBracesOptions`.
+
+
+
+.. _SpaceInEmptyBracesOptions:
+
+**SpaceInEmptyBracesOptions** (``SpaceInEmptyBracesCustom``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Control of individual spaces in empty braces.
+
+  If ``SpaceInEmptyBraces`` is set to ``Custom``, use this to specify
+  how each individual space in empty braces case should be handled.
+  Otherwise, this is ignored.
+
+  .. code-block:: yaml
+
+# Example of usage:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Function: true
+  Record: false
+  InitList: true
+  Block: false
+
+  Nested configuration flags:
+
+  Precise control over the spacing in empty braces.
 
   .. code-block:: c++
 
- true:false:
- void f() { }   vs.   void f() {}
- while (true) { } while (true) {}
+# Should be declared this way:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Function: true
+  Record: false
+  InitList: true
+  Block: false
+
+  * ``bool Function`` Put a space in empty braces of function definition.
+
+.. code-block:: c++
+
+   true:  false:
+   void f() { }   vs. void f() {}
+
+  * ``bool Record`` Put a space in empty braces of record/struct definition.
+
+.. code-block:: c++
+
+   true:  false:
+   struct U1 { }; vs. struct U1 {};
+   union U2 { };  union U2 {};
+   class U3 { };  class U3 {};
+   enum U4 { };   enum U4 {};
+
+  * ``bool InitList`` Put a space in empty braces of initializer list.
+
+.. code-block:: c++
+
+   true:  false:
+   T x{ };vs. T x{};
+
+  * ``bool Block`` Put a space in empty braces of other blocks, including 
functions and
+record, compatible with ``SpaceInEmptyBlock``.
+
+.. code-block:: c++
+
+   true:  false:
+   void f() { }   vs. void f() {}
+   enum Unit { }; enum Unit {};
+   while (true) { }   while (true) {}
+
 
 .. _SpaceInEmptyParentheses:
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 4fd6e013df25b..a6d8700ad9aa3 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4493,13 +4493,11 @@ struct FormatStyle {
   bool SpaceBeforeRangeBasedForLoopColon;
 
   /// If ``true``, spaces will be inserted into ``{}``.
-  /// \code
-  ///true:false:
-  ///void f() { }   vs.   void f() {}
-  ///while (true) { } while (true) {}
-  /// \endcode
+  /// This option is **deprecated**. The previous behavior is preserved by 

[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-05 Thread Kohei Asano via cfe-commits

https://github.com/khei4 updated https://github.com/llvm/llvm-project/pull/93634

>From 4cdd7bd2a916740f886939d1ec0395b5915eb3c2 Mon Sep 17 00:00:00 2001
From: Kohei Asano 
Date: Mon, 3 Jun 2024 09:15:44 +0900
Subject: [PATCH] [clang-format] add an option to insert a space only for empty
 braces

---
 clang/docs/ClangFormatStyleOptions.rst  |  97 -
 clang/include/clang/Format/Format.h | 112 ++--
 clang/lib/Format/Format.cpp |  40 ++-
 clang/lib/Format/TokenAnnotator.cpp |  18 +++-
 clang/lib/Format/UnwrappedLineFormatter.cpp |  13 ++-
 clang/unittests/Format/ConfigParseTest.cpp  |   9 +-
 clang/unittests/Format/FormatTest.cpp   |  99 -
 7 files changed, 368 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index bb00c20922d36..9879d122f8d57 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6036,12 +6036,103 @@ the configuration (without a prefix: ``Auto``).
 
 **SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ 
`
   If ``true``, spaces will be inserted into ``{}``.
+  This option is **deprecated**. The previous behavior is preserved by using
+  ``SpaceInEmptyBraces`` with ``Custom`` and by setting ``Block`` in
+  ``SpaceInEmptyBracesOptions`` to ``true``.
+
+.. _SpaceInEmptyBraces:
+
+**SpaceInEmptyBraces** (``SpaceInEmptyBracesStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Defines in which cases spaces will be inserted in empty braces.
+
+  Possible values:
+
+  * ``SIEBO_Never`` (in configuration: ``Never``)
+Never put a space in empty braces.
+
+.. code-block:: c++
+
+   void f() {}
+   T x{};
+   while (true) {}
+   struct U1 {};
+   union U2 {};
+   class U3 {};
+   enum U4 {};
+
+  * ``SIEBO_Custom`` (in configuration: ``Custom``)
+Configure each individual space in empty braces in
+`SpacesInEmptyBracesOptions`.
+
+
+
+.. _SpaceInEmptyBracesOptions:
+
+**SpaceInEmptyBracesOptions** (``SpaceInEmptyBracesCustom``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Control of individual spaces in empty braces.
+
+  If ``SpaceInEmptyBraces`` is set to ``Custom``, use this to specify
+  how each individual space in empty braces case should be handled.
+  Otherwise, this is ignored.
+
+  .. code-block:: yaml
+
+# Example of usage:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Function: true
+  Record: false
+  InitList: true
+  Block: false
+
+  Nested configuration flags:
+
+  Precise control over the spacing in empty braces.
 
   .. code-block:: c++
 
- true:false:
- void f() { }   vs.   void f() {}
- while (true) { } while (true) {}
+# Should be declared this way:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Function: true
+  Record: false
+  InitList: true
+  Block: false
+
+  * ``bool Function`` Put a space in empty braces of function definition.
+
+.. code-block:: c++
+
+   true:  false:
+   void f() { }   vs. void f() {}
+
+  * ``bool Record`` Put a space in empty braces of record/struct definition.
+
+.. code-block:: c++
+
+   true:  false:
+   struct U1 { }; vs. struct U1 {};
+   union U2 { };  union U2 {};
+   class U3 { };  class U3 {};
+   enum U4 { };   enum U4 {};
+
+  * ``bool InitList`` Put a space in empty braces of initializer list.
+
+.. code-block:: c++
+
+   true:  false:
+   T x{ };vs. T x{};
+
+  * ``bool Block`` Put a space in empty braces of other blocks, including 
functions and
+record, compatible with ``SpaceInEmptyBlock``.
+
+.. code-block:: c++
+
+   true:  false:
+   void f() { }   vs. void f() {}
+   enum Unit { }; enum Unit {};
+   while (true) { }   while (true) {}
+
 
 .. _SpaceInEmptyParentheses:
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 4fd6e013df25b..a6d8700ad9aa3 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4493,13 +4493,11 @@ struct FormatStyle {
   bool SpaceBeforeRangeBasedForLoopColon;
 
   /// If ``true``, spaces will be inserted into ``{}``.
-  /// \code
-  ///true:false:
-  ///void f() { }   vs.   void f() {}
-  ///while (true) { } while (true) {}
-  /// \endcode
+  /// This option is **deprecated**. The previous behavior is preserved by 

[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-05 Thread Kohei Asano via cfe-commits

https://github.com/khei4 ready_for_review 
https://github.com/llvm/llvm-project/pull/93634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-05 Thread Kohei Asano via cfe-commits

khei4 wrote:

I added more coarse braces options. I'm grad if you take a look ;)

https://github.com/llvm/llvm-project/pull/93634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-06 Thread Kohei Asano via cfe-commits

https://github.com/khei4 updated https://github.com/llvm/llvm-project/pull/93634

>From 4cdd7bd2a916740f886939d1ec0395b5915eb3c2 Mon Sep 17 00:00:00 2001
From: Kohei Asano 
Date: Mon, 3 Jun 2024 09:15:44 +0900
Subject: [PATCH 1/2] [clang-format] add an option to insert a space only for
 empty braces

---
 clang/docs/ClangFormatStyleOptions.rst  |  97 -
 clang/include/clang/Format/Format.h | 112 ++--
 clang/lib/Format/Format.cpp |  40 ++-
 clang/lib/Format/TokenAnnotator.cpp |  18 +++-
 clang/lib/Format/UnwrappedLineFormatter.cpp |  13 ++-
 clang/unittests/Format/ConfigParseTest.cpp  |   9 +-
 clang/unittests/Format/FormatTest.cpp   |  99 -
 7 files changed, 368 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index bb00c20922d36..9879d122f8d57 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6036,12 +6036,103 @@ the configuration (without a prefix: ``Auto``).
 
 **SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ 
`
   If ``true``, spaces will be inserted into ``{}``.
+  This option is **deprecated**. The previous behavior is preserved by using
+  ``SpaceInEmptyBraces`` with ``Custom`` and by setting ``Block`` in
+  ``SpaceInEmptyBracesOptions`` to ``true``.
+
+.. _SpaceInEmptyBraces:
+
+**SpaceInEmptyBraces** (``SpaceInEmptyBracesStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Defines in which cases spaces will be inserted in empty braces.
+
+  Possible values:
+
+  * ``SIEBO_Never`` (in configuration: ``Never``)
+Never put a space in empty braces.
+
+.. code-block:: c++
+
+   void f() {}
+   T x{};
+   while (true) {}
+   struct U1 {};
+   union U2 {};
+   class U3 {};
+   enum U4 {};
+
+  * ``SIEBO_Custom`` (in configuration: ``Custom``)
+Configure each individual space in empty braces in
+`SpacesInEmptyBracesOptions`.
+
+
+
+.. _SpaceInEmptyBracesOptions:
+
+**SpaceInEmptyBracesOptions** (``SpaceInEmptyBracesCustom``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Control of individual spaces in empty braces.
+
+  If ``SpaceInEmptyBraces`` is set to ``Custom``, use this to specify
+  how each individual space in empty braces case should be handled.
+  Otherwise, this is ignored.
+
+  .. code-block:: yaml
+
+# Example of usage:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Function: true
+  Record: false
+  InitList: true
+  Block: false
+
+  Nested configuration flags:
+
+  Precise control over the spacing in empty braces.
 
   .. code-block:: c++
 
- true:false:
- void f() { }   vs.   void f() {}
- while (true) { } while (true) {}
+# Should be declared this way:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Function: true
+  Record: false
+  InitList: true
+  Block: false
+
+  * ``bool Function`` Put a space in empty braces of function definition.
+
+.. code-block:: c++
+
+   true:  false:
+   void f() { }   vs. void f() {}
+
+  * ``bool Record`` Put a space in empty braces of record/struct definition.
+
+.. code-block:: c++
+
+   true:  false:
+   struct U1 { }; vs. struct U1 {};
+   union U2 { };  union U2 {};
+   class U3 { };  class U3 {};
+   enum U4 { };   enum U4 {};
+
+  * ``bool InitList`` Put a space in empty braces of initializer list.
+
+.. code-block:: c++
+
+   true:  false:
+   T x{ };vs. T x{};
+
+  * ``bool Block`` Put a space in empty braces of other blocks, including 
functions and
+record, compatible with ``SpaceInEmptyBlock``.
+
+.. code-block:: c++
+
+   true:  false:
+   void f() { }   vs. void f() {}
+   enum Unit { }; enum Unit {};
+   while (true) { }   while (true) {}
+
 
 .. _SpaceInEmptyParentheses:
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 4fd6e013df25b..a6d8700ad9aa3 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4493,13 +4493,11 @@ struct FormatStyle {
   bool SpaceBeforeRangeBasedForLoopColon;
 
   /// If ``true``, spaces will be inserted into ``{}``.
-  /// \code
-  ///true:false:
-  ///void f() { }   vs.   void f() {}
-  ///while (true) { } while (true) {}
-  /// \endcode
+  /// This option is **deprecated**. The previous behavior is preserved

[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-06 Thread Kohei Asano via cfe-commits


@@ -187,7 +187,6 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
   CHECK_PARSE_BOOL(RemoveSemicolon);
   CHECK_PARSE_BOOL(SkipMacroDefinitionBody);
   CHECK_PARSE_BOOL(SpacesInSquareBrackets);
-  CHECK_PARSE_BOOL(SpaceInEmptyBlock);

khei4 wrote:

Yeah, it's same with 
[SpaceInEmptyParentheses](https://clang.llvm.org/docs/ClangFormatStyleOptions.html#spaceinemptyparentheses),
 currently I checked only 
[here](https://github.com/llvm/llvm-project/pull/93634/files#diff-6b5b06a9a335ec5939905df81f1def72c3f869e24c758a8dd7dc1706873a77f0R643-R646).

https://github.com/llvm/llvm-project/pull/93634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-06 Thread Kohei Asano via cfe-commits


@@ -1864,7 +1894,11 @@ FormatStyle getWebKitStyle() {
   Style.ObjCSpaceAfterProperty = true;
   Style.PointerAlignment = FormatStyle::PAS_Left;
   Style.SpaceBeforeCpp11BracedList = true;
-  Style.SpaceInEmptyBlock = true;
+  Style.SpaceInEmptyBraces = FormatStyle::SIEBO_Custom;
+  Style.SpaceInEmptyBracesOptions.Block = true;
+  Style.SpaceInEmptyBracesOptions.InitList = true;
+  Style.SpacesInParensOptions.InEmptyParentheses = false;

khei4 wrote:

I believe this matches, but it might be miss-leading, [check-webkit-style 
](https://github.com/WebKit/WebKit/blob/b6db305ef703967e6727c0120b7e46305b02b008/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py#L2384-L2386)script
 seems like to check whatever empty braces have space. To double check, I will 
ask in WebKit slack also.

https://github.com/llvm/llvm-project/pull/93634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-06 Thread Kohei Asano via cfe-commits

https://github.com/khei4 edited https://github.com/llvm/llvm-project/pull/93634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-06 Thread Kohei Asano via cfe-commits

https://github.com/khei4 edited https://github.com/llvm/llvm-project/pull/93634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-06 Thread Kohei Asano via cfe-commits

https://github.com/khei4 edited https://github.com/llvm/llvm-project/pull/93634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-08 Thread Kohei Asano via cfe-commits

https://github.com/khei4 converted_to_draft 
https://github.com/llvm/llvm-project/pull/93634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-12 Thread Kohei Asano via cfe-commits

https://github.com/khei4 updated https://github.com/llvm/llvm-project/pull/93634

>From 447e0e46620281b2a6604ed7a79b473105f8ebe1 Mon Sep 17 00:00:00 2001
From: Kohei Asano 
Date: Mon, 3 Jun 2024 09:15:44 +0900
Subject: [PATCH] [clang-format] add an option to insert a space only for empty
 braces

---
 clang/docs/ClangFormatStyleOptions.rst  |  97 +++-
 clang/include/clang/Format/Format.h | 114 +--
 clang/lib/Format/Format.cpp |  40 ++-
 clang/lib/Format/TokenAnnotator.cpp |  29 -
 clang/lib/Format/UnwrappedLineFormatter.cpp |  21 +++-
 clang/unittests/Format/ConfigParseTest.cpp  |   9 +-
 clang/unittests/Format/FormatTest.cpp   | 120 +++-
 7 files changed, 405 insertions(+), 25 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index bb00c20922d36..9879d122f8d57 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6036,12 +6036,103 @@ the configuration (without a prefix: ``Auto``).
 
 **SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ 
`
   If ``true``, spaces will be inserted into ``{}``.
+  This option is **deprecated**. The previous behavior is preserved by using
+  ``SpaceInEmptyBraces`` with ``Custom`` and by setting ``Block`` in
+  ``SpaceInEmptyBracesOptions`` to ``true``.
+
+.. _SpaceInEmptyBraces:
+
+**SpaceInEmptyBraces** (``SpaceInEmptyBracesStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Defines in which cases spaces will be inserted in empty braces.
+
+  Possible values:
+
+  * ``SIEBO_Never`` (in configuration: ``Never``)
+Never put a space in empty braces.
+
+.. code-block:: c++
+
+   void f() {}
+   T x{};
+   while (true) {}
+   struct U1 {};
+   union U2 {};
+   class U3 {};
+   enum U4 {};
+
+  * ``SIEBO_Custom`` (in configuration: ``Custom``)
+Configure each individual space in empty braces in
+`SpacesInEmptyBracesOptions`.
+
+
+
+.. _SpaceInEmptyBracesOptions:
+
+**SpaceInEmptyBracesOptions** (``SpaceInEmptyBracesCustom``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Control of individual spaces in empty braces.
+
+  If ``SpaceInEmptyBraces`` is set to ``Custom``, use this to specify
+  how each individual space in empty braces case should be handled.
+  Otherwise, this is ignored.
+
+  .. code-block:: yaml
+
+# Example of usage:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Function: true
+  Record: false
+  InitList: true
+  Block: false
+
+  Nested configuration flags:
+
+  Precise control over the spacing in empty braces.
 
   .. code-block:: c++
 
- true:false:
- void f() { }   vs.   void f() {}
- while (true) { } while (true) {}
+# Should be declared this way:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Function: true
+  Record: false
+  InitList: true
+  Block: false
+
+  * ``bool Function`` Put a space in empty braces of function definition.
+
+.. code-block:: c++
+
+   true:  false:
+   void f() { }   vs. void f() {}
+
+  * ``bool Record`` Put a space in empty braces of record/struct definition.
+
+.. code-block:: c++
+
+   true:  false:
+   struct U1 { }; vs. struct U1 {};
+   union U2 { };  union U2 {};
+   class U3 { };  class U3 {};
+   enum U4 { };   enum U4 {};
+
+  * ``bool InitList`` Put a space in empty braces of initializer list.
+
+.. code-block:: c++
+
+   true:  false:
+   T x{ };vs. T x{};
+
+  * ``bool Block`` Put a space in empty braces of other blocks, including 
functions and
+record, compatible with ``SpaceInEmptyBlock``.
+
+.. code-block:: c++
+
+   true:  false:
+   void f() { }   vs. void f() {}
+   enum Unit { }; enum Unit {};
+   while (true) { }   while (true) {}
+
 
 .. _SpaceInEmptyParentheses:
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 4fd6e013df25b..661147a454694 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4493,13 +4493,11 @@ struct FormatStyle {
   bool SpaceBeforeRangeBasedForLoopColon;
 
   /// If ``true``, spaces will be inserted into ``{}``.
-  /// \code
-  ///true:false:
-  ///void f() { }   vs.   void f() {}
-  ///while (true) { } while (true) {}
-  /// \endcode
+  /// This option is **deprecated**. The previous behavior is preserved 

[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-12 Thread Kohei Asano via cfe-commits

https://github.com/khei4 updated https://github.com/llvm/llvm-project/pull/93634

>From 64e557f1b5e6dcf3b0ac78c83d4bef3d6cd8f7ba Mon Sep 17 00:00:00 2001
From: Kohei Asano 
Date: Mon, 3 Jun 2024 09:15:44 +0900
Subject: [PATCH] [clang-format] add an option to insert a space only for empty
 braces

---
 clang/docs/ClangFormatStyleOptions.rst  |  97 +++-
 clang/include/clang/Format/Format.h | 114 +--
 clang/lib/Format/Format.cpp |  40 ++-
 clang/lib/Format/TokenAnnotator.cpp |  27 -
 clang/lib/Format/UnwrappedLineFormatter.cpp |  23 +++-
 clang/unittests/Format/ConfigParseTest.cpp  |   9 +-
 clang/unittests/Format/FormatTest.cpp   | 119 +++-
 7 files changed, 405 insertions(+), 24 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index bb00c20922d36..9879d122f8d57 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6036,12 +6036,103 @@ the configuration (without a prefix: ``Auto``).
 
 **SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ 
`
   If ``true``, spaces will be inserted into ``{}``.
+  This option is **deprecated**. The previous behavior is preserved by using
+  ``SpaceInEmptyBraces`` with ``Custom`` and by setting ``Block`` in
+  ``SpaceInEmptyBracesOptions`` to ``true``.
+
+.. _SpaceInEmptyBraces:
+
+**SpaceInEmptyBraces** (``SpaceInEmptyBracesStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Defines in which cases spaces will be inserted in empty braces.
+
+  Possible values:
+
+  * ``SIEBO_Never`` (in configuration: ``Never``)
+Never put a space in empty braces.
+
+.. code-block:: c++
+
+   void f() {}
+   T x{};
+   while (true) {}
+   struct U1 {};
+   union U2 {};
+   class U3 {};
+   enum U4 {};
+
+  * ``SIEBO_Custom`` (in configuration: ``Custom``)
+Configure each individual space in empty braces in
+`SpacesInEmptyBracesOptions`.
+
+
+
+.. _SpaceInEmptyBracesOptions:
+
+**SpaceInEmptyBracesOptions** (``SpaceInEmptyBracesCustom``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Control of individual spaces in empty braces.
+
+  If ``SpaceInEmptyBraces`` is set to ``Custom``, use this to specify
+  how each individual space in empty braces case should be handled.
+  Otherwise, this is ignored.
+
+  .. code-block:: yaml
+
+# Example of usage:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Function: true
+  Record: false
+  InitList: true
+  Block: false
+
+  Nested configuration flags:
+
+  Precise control over the spacing in empty braces.
 
   .. code-block:: c++
 
- true:false:
- void f() { }   vs.   void f() {}
- while (true) { } while (true) {}
+# Should be declared this way:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Function: true
+  Record: false
+  InitList: true
+  Block: false
+
+  * ``bool Function`` Put a space in empty braces of function definition.
+
+.. code-block:: c++
+
+   true:  false:
+   void f() { }   vs. void f() {}
+
+  * ``bool Record`` Put a space in empty braces of record/struct definition.
+
+.. code-block:: c++
+
+   true:  false:
+   struct U1 { }; vs. struct U1 {};
+   union U2 { };  union U2 {};
+   class U3 { };  class U3 {};
+   enum U4 { };   enum U4 {};
+
+  * ``bool InitList`` Put a space in empty braces of initializer list.
+
+.. code-block:: c++
+
+   true:  false:
+   T x{ };vs. T x{};
+
+  * ``bool Block`` Put a space in empty braces of other blocks, including 
functions and
+record, compatible with ``SpaceInEmptyBlock``.
+
+.. code-block:: c++
+
+   true:  false:
+   void f() { }   vs. void f() {}
+   enum Unit { }; enum Unit {};
+   while (true) { }   while (true) {}
+
 
 .. _SpaceInEmptyParentheses:
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 4fd6e013df25b..661147a454694 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4493,13 +4493,11 @@ struct FormatStyle {
   bool SpaceBeforeRangeBasedForLoopColon;
 
   /// If ``true``, spaces will be inserted into ``{}``.
-  /// \code
-  ///true:false:
-  ///void f() { }   vs.   void f() {}
-  ///while (true) { } while (true) {}
-  /// \endcode
+  /// This option is **deprecated**. The previous behavior is preserved 

[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-12 Thread Kohei Asano via cfe-commits

https://github.com/khei4 updated https://github.com/llvm/llvm-project/pull/93634

>From 4f25089286e85682d79f78b3168138d7d2450142 Mon Sep 17 00:00:00 2001
From: Kohei Asano 
Date: Mon, 3 Jun 2024 09:15:44 +0900
Subject: [PATCH] [clang-format] add an option to insert a space only for empty
 braces

---
 clang/docs/ClangFormatStyleOptions.rst  |  97 +++-
 clang/include/clang/Format/Format.h | 114 +--
 clang/lib/Format/Format.cpp |  40 ++-
 clang/lib/Format/TokenAnnotator.cpp |  27 -
 clang/lib/Format/UnwrappedLineFormatter.cpp |  23 +++-
 clang/unittests/Format/ConfigParseTest.cpp  |   9 +-
 clang/unittests/Format/FormatTest.cpp   | 119 +++-
 7 files changed, 405 insertions(+), 24 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index bb00c20922d36..9879d122f8d57 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6036,12 +6036,103 @@ the configuration (without a prefix: ``Auto``).
 
 **SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ 
`
   If ``true``, spaces will be inserted into ``{}``.
+  This option is **deprecated**. The previous behavior is preserved by using
+  ``SpaceInEmptyBraces`` with ``Custom`` and by setting ``Block`` in
+  ``SpaceInEmptyBracesOptions`` to ``true``.
+
+.. _SpaceInEmptyBraces:
+
+**SpaceInEmptyBraces** (``SpaceInEmptyBracesStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Defines in which cases spaces will be inserted in empty braces.
+
+  Possible values:
+
+  * ``SIEBO_Never`` (in configuration: ``Never``)
+Never put a space in empty braces.
+
+.. code-block:: c++
+
+   void f() {}
+   T x{};
+   while (true) {}
+   struct U1 {};
+   union U2 {};
+   class U3 {};
+   enum U4 {};
+
+  * ``SIEBO_Custom`` (in configuration: ``Custom``)
+Configure each individual space in empty braces in
+`SpacesInEmptyBracesOptions`.
+
+
+
+.. _SpaceInEmptyBracesOptions:
+
+**SpaceInEmptyBracesOptions** (``SpaceInEmptyBracesCustom``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Control of individual spaces in empty braces.
+
+  If ``SpaceInEmptyBraces`` is set to ``Custom``, use this to specify
+  how each individual space in empty braces case should be handled.
+  Otherwise, this is ignored.
+
+  .. code-block:: yaml
+
+# Example of usage:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Function: true
+  Record: false
+  InitList: true
+  Block: false
+
+  Nested configuration flags:
+
+  Precise control over the spacing in empty braces.
 
   .. code-block:: c++
 
- true:false:
- void f() { }   vs.   void f() {}
- while (true) { } while (true) {}
+# Should be declared this way:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Function: true
+  Record: false
+  InitList: true
+  Block: false
+
+  * ``bool Function`` Put a space in empty braces of function definition.
+
+.. code-block:: c++
+
+   true:  false:
+   void f() { }   vs. void f() {}
+
+  * ``bool Record`` Put a space in empty braces of record/struct definition.
+
+.. code-block:: c++
+
+   true:  false:
+   struct U1 { }; vs. struct U1 {};
+   union U2 { };  union U2 {};
+   class U3 { };  class U3 {};
+   enum U4 { };   enum U4 {};
+
+  * ``bool InitList`` Put a space in empty braces of initializer list.
+
+.. code-block:: c++
+
+   true:  false:
+   T x{ };vs. T x{};
+
+  * ``bool Block`` Put a space in empty braces of other blocks, including 
functions and
+record, compatible with ``SpaceInEmptyBlock``.
+
+.. code-block:: c++
+
+   true:  false:
+   void f() { }   vs. void f() {}
+   enum Unit { }; enum Unit {};
+   while (true) { }   while (true) {}
+
 
 .. _SpaceInEmptyParentheses:
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 4fd6e013df25b..661147a454694 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4493,13 +4493,11 @@ struct FormatStyle {
   bool SpaceBeforeRangeBasedForLoopColon;
 
   /// If ``true``, spaces will be inserted into ``{}``.
-  /// \code
-  ///true:false:
-  ///void f() { }   vs.   void f() {}
-  ///while (true) { } while (true) {}
-  /// \endcode
+  /// This option is **deprecated**. The previous behavior is preserved 

[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-13 Thread Kohei Asano via cfe-commits


@@ -1864,7 +1894,11 @@ FormatStyle getWebKitStyle() {
   Style.ObjCSpaceAfterProperty = true;
   Style.PointerAlignment = FormatStyle::PAS_Left;
   Style.SpaceBeforeCpp11BracedList = true;
-  Style.SpaceInEmptyBlock = true;
+  Style.SpaceInEmptyBraces = FormatStyle::SIEBO_Custom;
+  Style.SpaceInEmptyBracesOptions.Block = true;
+  Style.SpaceInEmptyBracesOptions.InitList = true;
+  Style.SpacesInParensOptions.InEmptyParentheses = false;

khei4 wrote:

@owenca 
Thank you. I found there are no entries about empty braces. I will consult on 
the WebKit mailing list about the inconsistency between Code Style Guideline 
and check-webkit-style script. I think it’s good to separate the WebKit Style 
fixes and empty braces options addition on this patch. Although I can’t still 
find how much this kind of inconsistency are there, I will file an issue if 
it’s necessary. :)

https://github.com/llvm/llvm-project/pull/93634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-14 Thread Kohei Asano via cfe-commits

https://github.com/khei4 edited https://github.com/llvm/llvm-project/pull/93634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-14 Thread Kohei Asano via cfe-commits

https://github.com/khei4 updated https://github.com/llvm/llvm-project/pull/93634

>From 02b4de5799efe104f352d3f586e8779c5cd4 Mon Sep 17 00:00:00 2001
From: Kohei Asano 
Date: Mon, 3 Jun 2024 09:15:44 +0900
Subject: [PATCH] [clang-format] add an option to insert a space only for empty
 braces

---
 clang/docs/ClangFormatStyleOptions.rst  |  97 ++-
 clang/include/clang/Format/Format.h | 114 --
 clang/lib/Format/Format.cpp |  40 ++-
 clang/lib/Format/TokenAnnotator.cpp |  27 -
 clang/lib/Format/UnwrappedLineFormatter.cpp |  23 +++-
 clang/unittests/Format/ConfigParseTest.cpp  |   9 +-
 clang/unittests/Format/FormatTest.cpp   | 126 +++-
 7 files changed, 412 insertions(+), 24 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index bb00c20922d36..9879d122f8d57 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6036,12 +6036,103 @@ the configuration (without a prefix: ``Auto``).
 
 **SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ 
`
   If ``true``, spaces will be inserted into ``{}``.
+  This option is **deprecated**. The previous behavior is preserved by using
+  ``SpaceInEmptyBraces`` with ``Custom`` and by setting ``Block`` in
+  ``SpaceInEmptyBracesOptions`` to ``true``.
+
+.. _SpaceInEmptyBraces:
+
+**SpaceInEmptyBraces** (``SpaceInEmptyBracesStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Defines in which cases spaces will be inserted in empty braces.
+
+  Possible values:
+
+  * ``SIEBO_Never`` (in configuration: ``Never``)
+Never put a space in empty braces.
+
+.. code-block:: c++
+
+   void f() {}
+   T x{};
+   while (true) {}
+   struct U1 {};
+   union U2 {};
+   class U3 {};
+   enum U4 {};
+
+  * ``SIEBO_Custom`` (in configuration: ``Custom``)
+Configure each individual space in empty braces in
+`SpacesInEmptyBracesOptions`.
+
+
+
+.. _SpaceInEmptyBracesOptions:
+
+**SpaceInEmptyBracesOptions** (``SpaceInEmptyBracesCustom``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Control of individual spaces in empty braces.
+
+  If ``SpaceInEmptyBraces`` is set to ``Custom``, use this to specify
+  how each individual space in empty braces case should be handled.
+  Otherwise, this is ignored.
+
+  .. code-block:: yaml
+
+# Example of usage:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Function: true
+  Record: false
+  InitList: true
+  Block: false
+
+  Nested configuration flags:
+
+  Precise control over the spacing in empty braces.
 
   .. code-block:: c++
 
- true:false:
- void f() { }   vs.   void f() {}
- while (true) { } while (true) {}
+# Should be declared this way:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Function: true
+  Record: false
+  InitList: true
+  Block: false
+
+  * ``bool Function`` Put a space in empty braces of function definition.
+
+.. code-block:: c++
+
+   true:  false:
+   void f() { }   vs. void f() {}
+
+  * ``bool Record`` Put a space in empty braces of record/struct definition.
+
+.. code-block:: c++
+
+   true:  false:
+   struct U1 { }; vs. struct U1 {};
+   union U2 { };  union U2 {};
+   class U3 { };  class U3 {};
+   enum U4 { };   enum U4 {};
+
+  * ``bool InitList`` Put a space in empty braces of initializer list.
+
+.. code-block:: c++
+
+   true:  false:
+   T x{ };vs. T x{};
+
+  * ``bool Block`` Put a space in empty braces of other blocks, including 
functions and
+record, compatible with ``SpaceInEmptyBlock``.
+
+.. code-block:: c++
+
+   true:  false:
+   void f() { }   vs. void f() {}
+   enum Unit { }; enum Unit {};
+   while (true) { }   while (true) {}
+
 
 .. _SpaceInEmptyParentheses:
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 4fd6e013df25b..661147a454694 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4493,13 +4493,11 @@ struct FormatStyle {
   bool SpaceBeforeRangeBasedForLoopColon;
 
   /// If ``true``, spaces will be inserted into ``{}``.
-  /// \code
-  ///true:false:
-  ///void f() { }   vs.   void f() {}
-  ///while (true) { } while (true) {}
-  /// \endcode
+  /// This option is **deprecated**. The previous behavior is preserved by

[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-14 Thread Kohei Asano via cfe-commits

khei4 wrote:

@owenca Thank you for the review! 

> @khei4 maybe an enum for SpaceInEmptyBraces with Always, Never, and Custom. 
> (IMO Leave doesn't make sense.)

I make those variants. How do you think the behavior of config, which has only 
`  SpaceInEmptyBraces.SpacesInParensOptions.InEmptyParentheses = true;` should 
be after this patch? I make `Never` default value now, so 
`SpacesInParensOptions.InEmptyParentheses` wouldn't insert a space into empty 
braces after this patch if it's without enabling `SpaceInEmptyBraces`

> I would implement all that make sense or are applicable to WebKit.

TBH, I'm not sure how much braces are classified on config, I will consult 
concretely, but `WebKit` style may be `SpaceInEmptyBraces: Always`. Can I leave 
them to you? Thank you! 

https://github.com/llvm/llvm-project/pull/93634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-14 Thread Kohei Asano via cfe-commits

https://github.com/khei4 ready_for_review 
https://github.com/llvm/llvm-project/pull/93634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-19 Thread Kohei Asano via cfe-commits

https://github.com/khei4 updated https://github.com/llvm/llvm-project/pull/93634

>From 8018dafc9878bcf3ad5f041dc90d9908b816925f Mon Sep 17 00:00:00 2001
From: Kohei Asano 
Date: Mon, 3 Jun 2024 09:15:44 +0900
Subject: [PATCH] [clang-format] add an option to insert a space only for empty
 braces

---
 clang/docs/ClangFormatStyleOptions.rst  |  97 ++-
 clang/include/clang/Format/Format.h | 114 --
 clang/lib/Format/Format.cpp |  39 +-
 clang/lib/Format/TokenAnnotator.cpp |  27 -
 clang/lib/Format/UnwrappedLineFormatter.cpp |  23 +++-
 clang/unittests/Format/ConfigParseTest.cpp  |   9 +-
 clang/unittests/Format/FormatTest.cpp   | 126 +++-
 7 files changed, 411 insertions(+), 24 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index bb00c20922d36..9879d122f8d57 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6036,12 +6036,103 @@ the configuration (without a prefix: ``Auto``).
 
 **SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ 
`
   If ``true``, spaces will be inserted into ``{}``.
+  This option is **deprecated**. The previous behavior is preserved by using
+  ``SpaceInEmptyBraces`` with ``Custom`` and by setting ``Block`` in
+  ``SpaceInEmptyBracesOptions`` to ``true``.
+
+.. _SpaceInEmptyBraces:
+
+**SpaceInEmptyBraces** (``SpaceInEmptyBracesStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Defines in which cases spaces will be inserted in empty braces.
+
+  Possible values:
+
+  * ``SIEBO_Never`` (in configuration: ``Never``)
+Never put a space in empty braces.
+
+.. code-block:: c++
+
+   void f() {}
+   T x{};
+   while (true) {}
+   struct U1 {};
+   union U2 {};
+   class U3 {};
+   enum U4 {};
+
+  * ``SIEBO_Custom`` (in configuration: ``Custom``)
+Configure each individual space in empty braces in
+`SpacesInEmptyBracesOptions`.
+
+
+
+.. _SpaceInEmptyBracesOptions:
+
+**SpaceInEmptyBracesOptions** (``SpaceInEmptyBracesCustom``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Control of individual spaces in empty braces.
+
+  If ``SpaceInEmptyBraces`` is set to ``Custom``, use this to specify
+  how each individual space in empty braces case should be handled.
+  Otherwise, this is ignored.
+
+  .. code-block:: yaml
+
+# Example of usage:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Function: true
+  Record: false
+  InitList: true
+  Block: false
+
+  Nested configuration flags:
+
+  Precise control over the spacing in empty braces.
 
   .. code-block:: c++
 
- true:false:
- void f() { }   vs.   void f() {}
- while (true) { } while (true) {}
+# Should be declared this way:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Function: true
+  Record: false
+  InitList: true
+  Block: false
+
+  * ``bool Function`` Put a space in empty braces of function definition.
+
+.. code-block:: c++
+
+   true:  false:
+   void f() { }   vs. void f() {}
+
+  * ``bool Record`` Put a space in empty braces of record/struct definition.
+
+.. code-block:: c++
+
+   true:  false:
+   struct U1 { }; vs. struct U1 {};
+   union U2 { };  union U2 {};
+   class U3 { };  class U3 {};
+   enum U4 { };   enum U4 {};
+
+  * ``bool InitList`` Put a space in empty braces of initializer list.
+
+.. code-block:: c++
+
+   true:  false:
+   T x{ };vs. T x{};
+
+  * ``bool Block`` Put a space in empty braces of other blocks, including 
functions and
+record, compatible with ``SpaceInEmptyBlock``.
+
+.. code-block:: c++
+
+   true:  false:
+   void f() { }   vs. void f() {}
+   enum Unit { }; enum Unit {};
+   while (true) { }   while (true) {}
+
 
 .. _SpaceInEmptyParentheses:
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 4fd6e013df25b..661147a454694 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4493,13 +4493,11 @@ struct FormatStyle {
   bool SpaceBeforeRangeBasedForLoopColon;
 
   /// If ``true``, spaces will be inserted into ``{}``.
-  /// \code
-  ///true:false:
-  ///void f() { }   vs.   void f() {}
-  ///while (true) { } while (true) {}
-  /// \endcode
+  /// This option is **deprecated**. The previous behavior is preserved by 

[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-19 Thread Kohei Asano via cfe-commits

https://github.com/khei4 updated https://github.com/llvm/llvm-project/pull/93634

>From c4932b225fefc6adc0bfe158e4ccba5f249baf94 Mon Sep 17 00:00:00 2001
From: Kohei Asano 
Date: Mon, 3 Jun 2024 09:15:44 +0900
Subject: [PATCH] [clang-format] add an option to insert a space only for empty
 braces

---
 clang/docs/ClangFormatStyleOptions.rst  | 100 +++-
 clang/include/clang/Format/Format.h | 114 --
 clang/lib/Format/Format.cpp |  39 +-
 clang/lib/Format/TokenAnnotator.cpp |  27 -
 clang/lib/Format/UnwrappedLineFormatter.cpp |  23 +++-
 clang/unittests/Format/ConfigParseTest.cpp  |   9 +-
 clang/unittests/Format/FormatTest.cpp   | 126 +++-
 7 files changed, 414 insertions(+), 24 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index bb00c20922d36..68a1e4d9b2e80 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6036,12 +6036,106 @@ the configuration (without a prefix: ``Auto``).
 
 **SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ 
`
   If ``true``, spaces will be inserted into ``{}``.
+  This option is **deprecated**. The previous behavior is preserved by using
+  ``SpaceInEmptyBraces`` with ``Custom`` and by setting ``Block`` in
+  ``SpaceInEmptyBracesOptions`` to ``true``.
+
+.. _SpaceInEmptyBraces:
+
+**SpaceInEmptyBraces** (``SpaceInEmptyBracesStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Defines in which cases spaces will be inserted in empty braces.
+
+  Possible values:
+
+  * ``SIEBO_Never`` (in configuration: ``Never``)
+Never put a space in empty braces.
+
+.. code-block:: c++
+
+   void f() {}
+   T x{};
+   while (true) {}
+   struct U1 {};
+   union U2 {};
+   class U3 {};
+   enum U4 {};
+
+  * ``SIEBO_Always`` (in configuration: ``Always``)
+Always put a space in empty braces.
+
+  * ``SIEBO_Custom`` (in configuration: ``Custom``)
+Configure each individual space in empty braces in
+`SpacesInEmptyBracesOptions`.
+
+
+
+.. _SpaceInEmptyBracesOptions:
+
+**SpaceInEmptyBracesOptions** (``SpaceInEmptyBracesCustom``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Control of individual spaces in empty braces.
+
+  If ``SpaceInEmptyBraces`` is set to ``Custom``, use this to specify
+  how each individual space in empty braces case should be handled.
+  Otherwise, this is ignored.
+
+  .. code-block:: yaml
+
+# Example of usage:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Function: true
+  Record: false
+  InitList: true
+  Block: false
+
+  Nested configuration flags:
+
+  Precise control over the spacing in empty braces.
 
   .. code-block:: c++
 
- true:false:
- void f() { }   vs.   void f() {}
- while (true) { } while (true) {}
+# Should be declared this way:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Function: true
+  Record: false
+  InitList: true
+  Block: false
+
+  * ``bool Function`` Put a space in empty braces of function definition.
+
+.. code-block:: c++
+
+   true:  false:
+   void f() { }   vs. void f() {}
+
+  * ``bool Record`` Put a space in empty braces of record/struct definition.
+
+.. code-block:: c++
+
+   true:  false:
+   struct U1 { }; vs. struct U1 {};
+   union U2 { };  union U2 {};
+   class U3 { };  class U3 {};
+   enum U4 { };   enum U4 {};
+
+  * ``bool InitList`` Put a space in empty braces of initializer list.
+
+.. code-block:: c++
+
+   true:  false:
+   T x{ };vs. T x{};
+
+  * ``bool Block`` Put a space in empty braces of other blocks, including 
functions and
+record, compatible with ``SpaceInEmptyBlock``.
+
+.. code-block:: c++
+
+   true:  false:
+   void f() { }   vs. void f() {}
+   enum Unit { }; enum Unit {};
+   while (true) { }   while (true) {}
+
 
 .. _SpaceInEmptyParentheses:
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 4fd6e013df25b..661147a454694 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4493,13 +4493,11 @@ struct FormatStyle {
   bool SpaceBeforeRangeBasedForLoopColon;
 
   /// If ``true``, spaces will be inserted into ``{}``.
-  /// \code
-  ///true:false:
-  ///void f() { }   vs.   void f() {}
-  ///while (true) { } while (true

[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-19 Thread Kohei Asano via cfe-commits

khei4 wrote:

I confirmed [the update of WebKit Code Style Guideline for empty 
braces](https://github.com/WebKit/WebKit/pull/29668). I make WebKit style 
insert a space in any empty braces. I also updated document by script.

https://github.com/llvm/llvm-project/pull/93634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces (PR #93634)

2024-05-28 Thread Kohei Asano via cfe-commits

https://github.com/khei4 created https://github.com/llvm/llvm-project/pull/93634

# What
This patch introduces an option to insert a space between empty braces, 
especially for empty initializer.


# Motivation

WebKit has [its own `.clang-format` 
](https://github.com/WebKit/WebKit/blob/main/.clang-format) and [clang-format 
has `basedOnStyle: 
WebKit`](https://clang.llvm.org/docs/ClangFormatStyleOptions.html#basedonstyle),
 but it's inconsistent with [internal style checker 
script](https://github.com/WebKit/WebKit/blob/main/Tools/Scripts/check-webkit-style),
 at least for the empty initializers.
For example, the following line, tweaked from [WebKit source 
code](https://github.com/WebKit/WebKit/blob/main/Source/WebKit/UIProcess/Inspector/win/WebInspectorUIProxyWin.cpp#L222),
 would be checked by the script 
```c++
toImpl(listenerRef)->use( {} );
```
```bash
$ python Tools/Scripts/check-webkit-style
ERROR: Source/WebKit/UIProcess/Inspector/win/WebInspectorUIProxyWin.cpp:222:  
Extra space after ( in function call  [whitespace/parens] [4]
ERROR: Source/WebKit/UIProcess/Inspector/win/WebInspectorUIProxyWin.cpp:222:  
Extra space before )  [whitespace/parens] [2]
ERROR: Source/WebKit/UIProcess/Inspector/win/WebInspectorUIProxyWin.cpp:222:  
Missing space inside { }.  [whitespace/braces] [5]
```

A space in empty braces is required, but one in (also for empty) parens isn't 
allowed.

Current clang-format could insert a space in empty parenthesis and block 
simultaneously by turning on 
[SpacesInParensOptions.InEmptyParentheses](https://clang.llvm.org/docs/ClangFormatStyleOptions.html#spacesinparensoptions),
 but formatting only braces couldn't be achieved.

So we want to insert a space only for braces.

# Note

I guess compatibility is important, but including braces in parens options 
might have been miss-leading. If more descriptive option name and desirable 
changes exist, I'm very happy to hear that :)

>From f9022ddba4dd26dea5d04dbcd3c256d2d42b3bad Mon Sep 17 00:00:00 2001
From: Kohei Asano 
Date: Wed, 29 May 2024 11:40:39 +0900
Subject: [PATCH] [clang-format] add an option to insert a space only for empty
 braces

---
 clang/docs/ClangFormatStyleOptions.rst | 14 +-
 clang/include/clang/Format/Format.h| 21 +
 clang/lib/Format/Format.cpp|  1 +
 clang/lib/Format/TokenAnnotator.cpp|  5 +
 clang/unittests/Format/ConfigParseTest.cpp | 21 +
 clang/unittests/Format/FormatTest.cpp  |  5 +
 6 files changed, 54 insertions(+), 13 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 6d092219877f9..a1944eec8582b 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6237,18 +6237,30 @@ the configuration (without a prefix: ``Auto``).
true:  false:
x = ( int32 )y vs. x = (int32)y
 
-  * ``bool InEmptyParentheses`` Put a space in parentheses only if the 
parentheses are empty i.e. '()'
+  * ``bool InEmptyParentheses`` Put a space in parentheses and braces only if 
they are empty i.e. '()' or '{}'
 
 .. code-block:: c++
 
true:false:
void f( ) {vs.   void f() {
  int x[] = {foo( ), bar( )};  int x[] = {foo(), bar()};
+ T a = { };   T a = {};
  if (true) {  if (true) {
f( );f();
  }}
}}
 
+  * ``bool InEmptyBraces`` Put a space in *only* braces, not for parentheses, 
only if the braces are empty i.e. '{}'
+
+.. code-block:: c++
+
+   true:false:
+   void f() { vs.   void f() {
+ T x = {};T x = { };
+ g(x, {});g(x, { });
+   }}
+
+
   * ``bool Other`` Put a space in parentheses not covered by preceding options.
 
 .. code-block:: c++
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 274b45d1bc586..4482f7fb49788 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4673,6 +4673,17 @@ struct FormatStyle {
 ///}}
 /// \endcode
 bool InEmptyParentheses;
+/// Put a space in brackets only if the parentheses are empty i.e. '()'
+/// \code
+///true:false:
+///void f( ) {vs.   void f() {
+///  int x[] = {foo( ), bar( )};  int x[] = {foo(), bar()};
+///  if (true) {  if (true) {
+///f( );f();
+/

[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-05-28 Thread Kohei Asano via cfe-commits

https://github.com/khei4 edited https://github.com/llvm/llvm-project/pull/93634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-05-28 Thread Kohei Asano via cfe-commits

https://github.com/khei4 edited https://github.com/llvm/llvm-project/pull/93634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-05-29 Thread Kohei Asano via cfe-commits


@@ -6237,18 +6237,30 @@ the configuration (without a prefix: ``Auto``).
true:  false:
x = ( int32 )y vs. x = (int32)y
 
-  * ``bool InEmptyParentheses`` Put a space in parentheses only if the 
parentheses are empty i.e. '()'
+  * ``bool InEmptyParentheses`` Put a space in parentheses and braces only if 
they are empty i.e. '()' or '{}'

khei4 wrote:

I made by hand. I didn't notice the script, (and still don't know what to be 
used...)

https://github.com/llvm/llvm-project/pull/93634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-05-29 Thread Kohei Asano via cfe-commits


@@ -6237,18 +6237,30 @@ the configuration (without a prefix: ``Auto``).
true:  false:
x = ( int32 )y vs. x = (int32)y
 
-  * ``bool InEmptyParentheses`` Put a space in parentheses only if the 
parentheses are empty i.e. '()'
+  * ``bool InEmptyParentheses`` Put a space in parentheses and braces only if 
they are empty i.e. '()' or '{}'

khei4 wrote:

> it feels to me like InEmptyParentheses should be parenthese only

I totally agree with you, but it seems to break compatibility. I didn't know 
how such a change should land, but I'm eager to implement if it's ok to change 
that.

> InEmptyBraces should inherit by default from InEmptyParentheses if its not 
> defined in the config?

That sounds reasonable and consistent. But that change would be non-functional 
and I can't find how I create inheritance of options appropriately. So if it's 
necessary, could you kindly tell me where inheritance should be placed? 🙏  

https://github.com/llvm/llvm-project/pull/93634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-05-29 Thread Kohei Asano via cfe-commits

https://github.com/khei4 edited https://github.com/llvm/llvm-project/pull/93634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-05-29 Thread Kohei Asano via cfe-commits

https://github.com/khei4 updated https://github.com/llvm/llvm-project/pull/93634

>From f9022ddba4dd26dea5d04dbcd3c256d2d42b3bad Mon Sep 17 00:00:00 2001
From: Kohei Asano 
Date: Wed, 29 May 2024 11:40:39 +0900
Subject: [PATCH 1/2] [clang-format] add an option to insert a space only for
 empty braces

---
 clang/docs/ClangFormatStyleOptions.rst | 14 +-
 clang/include/clang/Format/Format.h| 21 +
 clang/lib/Format/Format.cpp|  1 +
 clang/lib/Format/TokenAnnotator.cpp|  5 +
 clang/unittests/Format/ConfigParseTest.cpp | 21 +
 clang/unittests/Format/FormatTest.cpp  |  5 +
 6 files changed, 54 insertions(+), 13 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 6d092219877f9..a1944eec8582b 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6237,18 +6237,30 @@ the configuration (without a prefix: ``Auto``).
true:  false:
x = ( int32 )y vs. x = (int32)y
 
-  * ``bool InEmptyParentheses`` Put a space in parentheses only if the 
parentheses are empty i.e. '()'
+  * ``bool InEmptyParentheses`` Put a space in parentheses and braces only if 
they are empty i.e. '()' or '{}'
 
 .. code-block:: c++
 
true:false:
void f( ) {vs.   void f() {
  int x[] = {foo( ), bar( )};  int x[] = {foo(), bar()};
+ T a = { };   T a = {};
  if (true) {  if (true) {
f( );f();
  }}
}}
 
+  * ``bool InEmptyBraces`` Put a space in *only* braces, not for parentheses, 
only if the braces are empty i.e. '{}'
+
+.. code-block:: c++
+
+   true:false:
+   void f() { vs.   void f() {
+ T x = {};T x = { };
+ g(x, {});g(x, { });
+   }}
+
+
   * ``bool Other`` Put a space in parentheses not covered by preceding options.
 
 .. code-block:: c++
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 274b45d1bc586..4482f7fb49788 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4673,6 +4673,17 @@ struct FormatStyle {
 ///}}
 /// \endcode
 bool InEmptyParentheses;
+/// Put a space in brackets only if the parentheses are empty i.e. '()'
+/// \code
+///true:false:
+///void f( ) {vs.   void f() {
+///  int x[] = {foo( ), bar( )};  int x[] = {foo(), bar()};
+///  if (true) {  if (true) {
+///f( );f();
+///  }}
+///}}
+/// \endcode
+bool InEmptyBraces;
 /// Put a space in parentheses not covered by preceding options.
 /// \code
 ///true:  false:
@@ -4682,18 +4693,20 @@ struct FormatStyle {
 
 SpacesInParensCustom()
 : InConditionalStatements(false), InCStyleCasts(false),
-  InEmptyParentheses(false), Other(false) {}
+  InEmptyParentheses(false), InEmptyBraces(false), Other(false) {}
 
 SpacesInParensCustom(bool InConditionalStatements, bool InCStyleCasts,
- bool InEmptyParentheses, bool Other)
+ bool InEmptyParentheses, bool InEmptyBraces,
+ bool Other)
 : InConditionalStatements(InConditionalStatements),
   InCStyleCasts(InCStyleCasts), InEmptyParentheses(InEmptyParentheses),
-  Other(Other) {}
+  InEmptyBraces(InEmptyBraces), Other(Other) {}
 
 bool operator==(const SpacesInParensCustom &R) const {
   return InConditionalStatements == R.InConditionalStatements &&
  InCStyleCasts == R.InCStyleCasts &&
- InEmptyParentheses == R.InEmptyParentheses && Other == R.Other;
+ InEmptyParentheses == R.InEmptyParentheses &&
+ InEmptyBraces == R.InEmptyBraces && Other == R.Other;
 }
 bool operator!=(const SpacesInParensCustom &R) const {
   return !(*this == R);
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 9cba0c2614eef..efcc48b910718 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -723,6 +723,7 @@ template <> struct 
MappingTraits {
 IO.mapOptional("InCStyleCasts", Spaces.InCStyleCasts);
 IO.mapOptional("InConditionalStatements", Spa

[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-05-29 Thread Kohei Asano via cfe-commits

https://github.com/khei4 edited https://github.com/llvm/llvm-project/pull/93634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-05-29 Thread Kohei Asano via cfe-commits


@@ -14027,6 +14027,11 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
   SpaceBetweenBraces.SpacesInParens = FormatStyle::SIPO_Custom;
   SpaceBetweenBraces.SpacesInParensOptions.InEmptyParentheses = true;
   verifyFormat("vector< int > x{ };", SpaceBetweenBraces);
+  SpaceBetweenBraces.SpacesInParens = FormatStyle::SIPO_Custom;
+  SpaceBetweenBraces.SpacesInParensOptions.InEmptyParentheses = false;
+  SpaceBetweenBraces.SpacesInParensOptions.Other = false;
+  SpaceBetweenBraces.SpacesInParensOptions.InEmptyBraces = true;
+  verifyFormat("T x = { };\nf(x, { });\ng();", SpaceBetweenBraces);
 }

khei4 wrote:

Sounds reasonable, I replace `f(x, { });` with `toImpl(listenerRef)->use({ 
});\n` and drop a comment, thanks!

https://github.com/llvm/llvm-project/pull/93634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-05-29 Thread Kohei Asano via cfe-commits


@@ -4682,18 +4693,20 @@ struct FormatStyle {
 
 SpacesInParensCustom()

khei4 wrote:

Thanks for a good catch! I think more correspondence with [`.clang-format` 
](https://github.com/WebKit/WebKit/blob/main/.clang-format) and `basedOnStyle: 
WebKit`, and WebKit style checker script requires more fixes, I may update 
other things later ;)

https://github.com/llvm/llvm-project/pull/93634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-05-29 Thread Kohei Asano via cfe-commits

https://github.com/khei4 edited https://github.com/llvm/llvm-project/pull/93634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-05-29 Thread Kohei Asano via cfe-commits

https://github.com/khei4 edited https://github.com/llvm/llvm-project/pull/93634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-05-29 Thread Kohei Asano via cfe-commits

https://github.com/khei4 updated https://github.com/llvm/llvm-project/pull/93634

>From 0b41025a9ba677caf694f65620ce4a7b9aae2265 Mon Sep 17 00:00:00 2001
From: Kohei Asano 
Date: Wed, 29 May 2024 11:40:39 +0900
Subject: [PATCH] [clang-format] add an option to insert a space only for empty
 braces
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: Björn Schäpers 
---
 clang/docs/ClangFormatStyleOptions.rst | 14 +-
 clang/include/clang/Format/Format.h| 21 +
 clang/lib/Format/Format.cpp|  4 
 clang/lib/Format/TokenAnnotator.cpp|  5 +
 clang/unittests/Format/ConfigParseTest.cpp | 21 +
 clang/unittests/Format/FormatTest.cpp  | 10 ++
 6 files changed, 62 insertions(+), 13 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 6d092219877f9..a1944eec8582b 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6237,18 +6237,30 @@ the configuration (without a prefix: ``Auto``).
true:  false:
x = ( int32 )y vs. x = (int32)y
 
-  * ``bool InEmptyParentheses`` Put a space in parentheses only if the 
parentheses are empty i.e. '()'
+  * ``bool InEmptyParentheses`` Put a space in parentheses and braces only if 
they are empty i.e. '()' or '{}'
 
 .. code-block:: c++
 
true:false:
void f( ) {vs.   void f() {
  int x[] = {foo( ), bar( )};  int x[] = {foo(), bar()};
+ T a = { };   T a = {};
  if (true) {  if (true) {
f( );f();
  }}
}}
 
+  * ``bool InEmptyBraces`` Put a space in *only* braces, not for parentheses, 
only if the braces are empty i.e. '{}'
+
+.. code-block:: c++
+
+   true:false:
+   void f() { vs.   void f() {
+ T x = {};T x = { };
+ g(x, {});g(x, { });
+   }}
+
+
   * ``bool Other`` Put a space in parentheses not covered by preceding options.
 
 .. code-block:: c++
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 274b45d1bc586..4482f7fb49788 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4673,6 +4673,17 @@ struct FormatStyle {
 ///}}
 /// \endcode
 bool InEmptyParentheses;
+/// Put a space in brackets only if the parentheses are empty i.e. '()'
+/// \code
+///true:false:
+///void f( ) {vs.   void f() {
+///  int x[] = {foo( ), bar( )};  int x[] = {foo(), bar()};
+///  if (true) {  if (true) {
+///f( );f();
+///  }}
+///}}
+/// \endcode
+bool InEmptyBraces;
 /// Put a space in parentheses not covered by preceding options.
 /// \code
 ///true:  false:
@@ -4682,18 +4693,20 @@ struct FormatStyle {
 
 SpacesInParensCustom()
 : InConditionalStatements(false), InCStyleCasts(false),
-  InEmptyParentheses(false), Other(false) {}
+  InEmptyParentheses(false), InEmptyBraces(false), Other(false) {}
 
 SpacesInParensCustom(bool InConditionalStatements, bool InCStyleCasts,
- bool InEmptyParentheses, bool Other)
+ bool InEmptyParentheses, bool InEmptyBraces,
+ bool Other)
 : InConditionalStatements(InConditionalStatements),
   InCStyleCasts(InCStyleCasts), InEmptyParentheses(InEmptyParentheses),
-  Other(Other) {}
+  InEmptyBraces(InEmptyBraces), Other(Other) {}
 
 bool operator==(const SpacesInParensCustom &R) const {
   return InConditionalStatements == R.InConditionalStatements &&
  InCStyleCasts == R.InCStyleCasts &&
- InEmptyParentheses == R.InEmptyParentheses && Other == R.Other;
+ InEmptyParentheses == R.InEmptyParentheses &&
+ InEmptyBraces == R.InEmptyBraces && Other == R.Other;
 }
 bool operator!=(const SpacesInParensCustom &R) const {
   return !(*this == R);
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 9cba0c2614eef..453a87745642d 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -723,6 +723,7 @@ template <> struct 

[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-01 Thread Kohei Asano via cfe-commits

https://github.com/khei4 converted_to_draft 
https://github.com/llvm/llvm-project/pull/93634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-02 Thread Kohei Asano via cfe-commits

https://github.com/khei4 updated https://github.com/llvm/llvm-project/pull/93634

>From b55d09f4baa5f0a5cbe9b2614c23cc0ab5f2ef58 Mon Sep 17 00:00:00 2001
From: Kohei Asano 
Date: Mon, 3 Jun 2024 09:15:44 +0900
Subject: [PATCH] [clang-format] add an option to insert a space only for empty
 braces

---
 clang/docs/ClangFormatStyleOptions.rst  | 78 +-
 clang/include/clang/Format/Format.h | 89 +++--
 clang/lib/Format/Format.cpp | 36 -
 clang/lib/Format/TokenAnnotator.cpp | 12 ++-
 clang/lib/Format/UnwrappedLineFormatter.cpp |  6 +-
 clang/unittests/Format/ConfigParseTest.cpp  |  9 ++-
 clang/unittests/Format/FormatTest.cpp   | 42 +-
 7 files changed, 253 insertions(+), 19 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 6d092219877f9..bf0088203dd54 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6028,12 +6028,84 @@ the configuration (without a prefix: ``Auto``).
 
 **SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ 
`
   If ``true``, spaces will be inserted into ``{}``.
+  This option is **deprecated**. The previous behavior is preserved by using
+  ``SpaceInEmptyBraces`` with ``Custom`` and by setting Record
+  ``SpaceInEmptyBracesOptions`` to ``true``.
+
+.. _SpaceInEmptyBlock:
+
+**SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ 
`
+  If ``true``, spaces will be inserted into ``{}`` for record declarations
+  and blocks. This option is **deprecated**. The previous behavior is
+  preserved by using ``SpaceInEmptyBraces`` with ``Custom`` and by setting
+  ``Record`` on ``SpaceInEmptyBracesOptions`` to ``true``.
+
+.. _SpaceInEmptyBraces:
+
+**SpaceInEmptyBraces** (``SpaceInEmptyBracesStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Defines in which cases spaces will be inserted in empty braces.
+
+  Possible values:
+
+  * ``SIEBO_Never`` (in configuration: ``Never``)
+Never put a space in empty braces.
+
+.. code-block:: c++
+
+   T x{};
+   while (true) {}
+   struct Unit {};
+
+  * ``SIEBO_Custom`` (in configuration: ``Custom``)
+Configure each individual space in empty braces in
+`SpacesInEmptyBracesOptions`.
+
+
+
+.. _SpaceInEmptyBracesOptions:
+
+**SpaceInEmptyBracesOptions** (``SpaceInEmptyBracesCustom``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Control of individual spaces in empty braces.
+
+  If ``SpaceInEmptyBraces`` is set to ``Custom``, use this to specify
+  how each individual space in empty braces case should be handled.
+  Otherwise, this is ignored.
+
+  .. code-block:: yaml
+
+# Example of usage:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Block: true
+  Record: true
+
+  Nested configuration flags:
+
+  Precise control over the spacing in empty braces.
 
   .. code-block:: c++
 
- true:false:
- void f() { }   vs.   void f() {}
- while (true) { } while (true) {}
+# Should be declared this way:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Block: true
+  Record: true
+
+  * ``bool Block`` Put a space in empty braces of code blocks and record 
declarations.
+
+.. code-block:: c++
+
+   true:  false:
+   int f() { }vs. int f() {}
+   struct Unit {};struct Unit {};
+
+  * ``bool InitList`` Put a space in empty braces of initializer list.
+
+.. code-block:: c++
+
+   true:  false:
+   T x{ };vs. T x{};
+
 
 .. _SpaceInEmptyParentheses:
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 274b45d1bc586..8b623eb2cb4bc 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4487,13 +4487,11 @@ struct FormatStyle {
   bool SpaceBeforeRangeBasedForLoopColon;
 
   /// If ``true``, spaces will be inserted into ``{}``.
-  /// \code
-  ///true:false:
-  ///void f() { }   vs.   void f() {}
-  ///while (true) { } while (true) {}
-  /// \endcode
+  /// This option is **deprecated**. The previous behavior is preserved by 
using
+  /// ``SpaceInEmptyBraces`` with ``Custom`` and by setting Record
+  /// ``SpaceInEmptyBracesOptions`` to ``true``.
   /// \version 10
-  bool SpaceInEmptyBlock;
+  // bool SpaceInEmptyBlock;
 
   /// If ``true``, spaces may be inserted into ``()``.
   /// This option is **deprecated**. See ``InEmptyParentheses`` of
@@ -4715,6 +4713,82 @@ struct FormatStyle {
   /// \version 17
   SpacesInParensCustom SpacesInParensOptions;
 
+  /// Different ways to put a space in empty braces.
+  enum SpaceInEmptyBracesStyle : int8_t {

[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-06-02 Thread Kohei Asano via cfe-commits

https://github.com/khei4 updated https://github.com/llvm/llvm-project/pull/93634

>From 5d409bcd0966a7581effdf1488c2f4cfa32aebc6 Mon Sep 17 00:00:00 2001
From: Kohei Asano 
Date: Mon, 3 Jun 2024 09:15:44 +0900
Subject: [PATCH] [clang-format] add an option to insert a space only for empty
 braces

---
 clang/docs/ClangFormatStyleOptions.rst  | 78 +++-
 clang/include/clang/Format/Format.h | 82 +++--
 clang/lib/Format/Format.cpp | 36 -
 clang/lib/Format/TokenAnnotator.cpp | 12 ++-
 clang/lib/Format/UnwrappedLineFormatter.cpp |  6 +-
 clang/unittests/Format/ConfigParseTest.cpp  |  9 ++-
 clang/unittests/Format/FormatTest.cpp   | 42 ++-
 7 files changed, 246 insertions(+), 19 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 6d092219877f9..bf0088203dd54 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6028,12 +6028,84 @@ the configuration (without a prefix: ``Auto``).
 
 **SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ 
`
   If ``true``, spaces will be inserted into ``{}``.
+  This option is **deprecated**. The previous behavior is preserved by using
+  ``SpaceInEmptyBraces`` with ``Custom`` and by setting Record
+  ``SpaceInEmptyBracesOptions`` to ``true``.
+
+.. _SpaceInEmptyBlock:
+
+**SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ 
`
+  If ``true``, spaces will be inserted into ``{}`` for record declarations
+  and blocks. This option is **deprecated**. The previous behavior is
+  preserved by using ``SpaceInEmptyBraces`` with ``Custom`` and by setting
+  ``Record`` on ``SpaceInEmptyBracesOptions`` to ``true``.
+
+.. _SpaceInEmptyBraces:
+
+**SpaceInEmptyBraces** (``SpaceInEmptyBracesStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Defines in which cases spaces will be inserted in empty braces.
+
+  Possible values:
+
+  * ``SIEBO_Never`` (in configuration: ``Never``)
+Never put a space in empty braces.
+
+.. code-block:: c++
+
+   T x{};
+   while (true) {}
+   struct Unit {};
+
+  * ``SIEBO_Custom`` (in configuration: ``Custom``)
+Configure each individual space in empty braces in
+`SpacesInEmptyBracesOptions`.
+
+
+
+.. _SpaceInEmptyBracesOptions:
+
+**SpaceInEmptyBracesOptions** (``SpaceInEmptyBracesCustom``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Control of individual spaces in empty braces.
+
+  If ``SpaceInEmptyBraces`` is set to ``Custom``, use this to specify
+  how each individual space in empty braces case should be handled.
+  Otherwise, this is ignored.
+
+  .. code-block:: yaml
+
+# Example of usage:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Block: true
+  Record: true
+
+  Nested configuration flags:
+
+  Precise control over the spacing in empty braces.
 
   .. code-block:: c++
 
- true:false:
- void f() { }   vs.   void f() {}
- while (true) { } while (true) {}
+# Should be declared this way:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Block: true
+  Record: true
+
+  * ``bool Block`` Put a space in empty braces of code blocks and record 
declarations.
+
+.. code-block:: c++
+
+   true:  false:
+   int f() { }vs. int f() {}
+   struct Unit {};struct Unit {};
+
+  * ``bool InitList`` Put a space in empty braces of initializer list.
+
+.. code-block:: c++
+
+   true:  false:
+   T x{ };vs. T x{};
+
 
 .. _SpaceInEmptyParentheses:
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 274b45d1bc586..b63ddd7e2b92b 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4487,13 +4487,11 @@ struct FormatStyle {
   bool SpaceBeforeRangeBasedForLoopColon;
 
   /// If ``true``, spaces will be inserted into ``{}``.
-  /// \code
-  ///true:false:
-  ///void f() { }   vs.   void f() {}
-  ///while (true) { } while (true) {}
-  /// \endcode
+  /// This option is **deprecated**. The previous behavior is preserved by 
using
+  /// ``SpaceInEmptyBraces`` with ``Custom`` and by setting Record
+  /// ``SpaceInEmptyBracesOptions`` to ``true``.
   /// \version 10
-  bool SpaceInEmptyBlock;
+  // bool SpaceInEmptyBlock;
 
   /// If ``true``, spaces may be inserted into ``()``.
   /// This option is **deprecated**. See ``InEmptyParentheses`` of
@@ -4715,6 +4713,75 @@ struct FormatStyle {
   /// \version 17
   SpacesInParensCustom SpacesInParensOptions;
 
+  /// Different ways to put a space in empty braces.
+  enum SpaceInEmptyBracesStyle : int8_t

[clang] [Clang][Docs] use CommonOptionsParser::create instead of protected constructor on libTooling tutorial (NFC) (PR #70427)

2024-04-29 Thread Kohei Asano via cfe-commits

https://github.com/khei4 updated https://github.com/llvm/llvm-project/pull/70427

>From 12e29c46366e93c98c96e7561258bc83f66755c1 Mon Sep 17 00:00:00 2001
From: khei4 
Date: Fri, 27 Oct 2023 17:46:34 +0900
Subject: [PATCH 1/2] use create instead of protected Constructor

---
 clang/docs/LibTooling.rst | 22 +-
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/clang/docs/LibTooling.rst b/clang/docs/LibTooling.rst
index df50dcebf9b83c..8ef59da67417ba 100644
--- a/clang/docs/LibTooling.rst
+++ b/clang/docs/LibTooling.rst
@@ -63,15 +63,22 @@ and automatic location of the compilation database using 
source files paths.
   #include "llvm/Support/CommandLine.h"
 
   using namespace clang::tooling;
+  using namespace llvm;
 
   // Apply a custom category to all command-line options so that they are the
   // only ones displayed.
-  static llvm::cl::OptionCategory MyToolCategory("my-tool options");
+  static cl::OptionCategory MyToolCategory("my-tool options");
 
   int main(int argc, const char **argv) {
-// CommonOptionsParser constructor will parse arguments and create a
-// CompilationDatabase.  In case of error it will terminate the program.
-CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
+// CommonOptionsParser::create will parse arguments and create a
+// CompilationDatabase. In case of error it will terminate the program.
+auto ExpectedParser = CommonOptionsParser::create(argc, argv, 
MyToolCategory);
+if (!ExpectedParser) {
+  // Fail gracefully for unsupported options.
+  llvm::errs() << ExpectedParser.takeError();
+  return 1;
+}
+CommonOptionsParser& OptionsParser = ExpectedParser.get();
 
 // Use OptionsParser.getCompilations() and 
OptionsParser.getSourcePathList()
 // to retrieve CompilationDatabase and the list of input file paths.
@@ -133,7 +140,12 @@ version of this example tool is also checked into the 
clang tree at
   static cl::extrahelp MoreHelp("\nMore help text...\n");
 
   int main(int argc, const char **argv) {
-CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
+auto ExpectedParser = CommonOptionsParser::create(argc, argv, 
MyToolCategory);
+if (!ExpectedParser) {
+  llvm::errs() << ExpectedParser.takeError();
+  return 1;
+}
+CommonOptionsParser& OptionsParser = ExpectedParser.get();
 ClangTool Tool(OptionsParser.getCompilations(),
OptionsParser.getSourcePathList());
 return Tool.run(newFrontendActionFactory().get());

>From 44b1b694f57eeb16cd6b9269bcb2177ce03c2b7c Mon Sep 17 00:00:00 2001
From: Kohei Asano <32860920+kh...@users.noreply.github.com>
Date: Mon, 29 Apr 2024 20:24:16 +0900
Subject: [PATCH 2/2] Update clang/docs/LibTooling.rst

Co-authored-by: Sirraide 
---
 clang/docs/LibTooling.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/LibTooling.rst b/clang/docs/LibTooling.rst
index 8ef59da67417ba..87d84321ab2830 100644
--- a/clang/docs/LibTooling.rst
+++ b/clang/docs/LibTooling.rst
@@ -71,7 +71,7 @@ and automatic location of the compilation database using 
source files paths.
 
   int main(int argc, const char **argv) {
 // CommonOptionsParser::create will parse arguments and create a
-// CompilationDatabase. In case of error it will terminate the program.
+// CompilationDatabase.
 auto ExpectedParser = CommonOptionsParser::create(argc, argv, 
MyToolCategory);
 if (!ExpectedParser) {
   // Fail gracefully for unsupported options.

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Docs] use CommonOptionsParser::create instead of protected constructor on libTooling tutorial (NFC) (PR #70427)

2024-04-29 Thread Kohei Asano via cfe-commits

https://github.com/khei4 closed https://github.com/llvm/llvm-project/pull/70427
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2025-01-11 Thread Kohei Asano via cfe-commits

https://github.com/khei4 updated https://github.com/llvm/llvm-project/pull/93634

>From 079f6d29c1091b89e949d674b1983bb6e08155df Mon Sep 17 00:00:00 2001
From: Kohei Asano 
Date: Mon, 3 Jun 2024 09:15:44 +0900
Subject: [PATCH] [clang-format] add an option to insert a space only for empty
 braces

---
 clang/docs/ClangFormatStyleOptions.rst  | 100 +++-
 clang/include/clang/Format/Format.h | 114 --
 clang/lib/Format/Format.cpp |  39 +-
 clang/lib/Format/TokenAnnotator.cpp |  26 +++-
 clang/lib/Format/UnwrappedLineFormatter.cpp |  23 +++-
 clang/unittests/Format/ConfigParseTest.cpp  |   9 +-
 clang/unittests/Format/FormatTest.cpp   | 126 +++-
 7 files changed, 416 insertions(+), 21 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 0edf7af72c24e9..2e4f87e4de238f 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6327,12 +6327,106 @@ the configuration (without a prefix: ``Auto``).
 
 **SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ 
`
   If ``true``, spaces will be inserted into ``{}``.
+  This option is **deprecated**. The previous behavior is preserved by using
+  ``SpaceInEmptyBraces`` with ``Custom`` and by setting ``Block`` in
+  ``SpaceInEmptyBracesOptions`` to ``true``.
+
+.. _SpaceInEmptyBraces:
+
+**SpaceInEmptyBraces** (``SpaceInEmptyBracesStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Defines in which cases spaces will be inserted in empty braces.
+
+  Possible values:
+
+  * ``SIEBO_Never`` (in configuration: ``Never``)
+Never put a space in empty braces.
+
+.. code-block:: c++
+
+   void f() {}
+   T x{};
+   while (true) {}
+   struct U1 {};
+   union U2 {};
+   class U3 {};
+   enum U4 {};
+
+  * ``SIEBO_Always`` (in configuration: ``Always``)
+Always put a space in empty braces.
+
+  * ``SIEBO_Custom`` (in configuration: ``Custom``)
+Configure each individual space in empty braces in
+`SpacesInEmptyBracesOptions`.
+
+
+
+.. _SpaceInEmptyBracesOptions:
+
+**SpaceInEmptyBracesOptions** (``SpaceInEmptyBracesCustom``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Control of individual spaces in empty braces.
+
+  If ``SpaceInEmptyBraces`` is set to ``Custom``, use this to specify
+  how each individual space in empty braces case should be handled.
+  Otherwise, this is ignored.
+
+  .. code-block:: yaml
+
+# Example of usage:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Function: true
+  Record: false
+  InitList: true
+  Block: false
+
+  Nested configuration flags:
+
+  Precise control over the spacing in empty braces.
 
   .. code-block:: c++
 
- true:false:
- void f() { }   vs.   void f() {}
- while (true) { } while (true) {}
+# Should be declared this way:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Function: true
+  Record: false
+  InitList: true
+  Block: false
+
+  * ``bool Function`` Put a space in empty braces of function definition.
+
+.. code-block:: c++
+
+   true:  false:
+   void f() { }   vs. void f() {}
+
+  * ``bool Record`` Put a space in empty braces of record/struct definition.
+
+.. code-block:: c++
+
+   true:  false:
+   struct U1 { }; vs. struct U1 {};
+   union U2 { };  union U2 {};
+   class U3 { };  class U3 {};
+   enum U4 { };   enum U4 {};
+
+  * ``bool InitList`` Put a space in empty braces of initializer list.
+
+.. code-block:: c++
+
+   true:  false:
+   T x{ };vs. T x{};
+
+  * ``bool Block`` Put a space in empty braces of other blocks, including 
functions and
+record, compatible with ``SpaceInEmptyBlock``.
+
+.. code-block:: c++
+
+   true:  false:
+   void f() { }   vs. void f() {}
+   enum Unit { }; enum Unit {};
+   while (true) { }   while (true) {}
+
 
 .. _SpaceInEmptyParentheses:
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 7c2afd4d94ab0d..3359f9e90cca7f 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4668,13 +4668,11 @@ struct FormatStyle {
   bool SpaceBeforeRangeBasedForLoopColon;
 
   /// If ``true``, spaces will be inserted into ``{}``.
-  /// \code
-  ///true:false:
-  ///void f() { }   vs.   void f() {}
-  ///while (true) { } while (t

[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2025-01-11 Thread Kohei Asano via cfe-commits

khei4 wrote:

rebased but still required to be tested and fix again 

https://github.com/llvm/llvm-project/pull/93634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2025-01-11 Thread Kohei Asano via cfe-commits

https://github.com/khei4 converted_to_draft 
https://github.com/llvm/llvm-project/pull/93634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2025-01-14 Thread Kohei Asano via cfe-commits

https://github.com/khei4 updated https://github.com/llvm/llvm-project/pull/93634

>From 079f6d29c1091b89e949d674b1983bb6e08155df Mon Sep 17 00:00:00 2001
From: Kohei Asano 
Date: Mon, 3 Jun 2024 09:15:44 +0900
Subject: [PATCH 1/2] [clang-format] add an option to insert a space only for
 empty braces

---
 clang/docs/ClangFormatStyleOptions.rst  | 100 +++-
 clang/include/clang/Format/Format.h | 114 --
 clang/lib/Format/Format.cpp |  39 +-
 clang/lib/Format/TokenAnnotator.cpp |  26 +++-
 clang/lib/Format/UnwrappedLineFormatter.cpp |  23 +++-
 clang/unittests/Format/ConfigParseTest.cpp  |   9 +-
 clang/unittests/Format/FormatTest.cpp   | 126 +++-
 7 files changed, 416 insertions(+), 21 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 0edf7af72c24e9..2e4f87e4de238f 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6327,12 +6327,106 @@ the configuration (without a prefix: ``Auto``).
 
 **SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ 
`
   If ``true``, spaces will be inserted into ``{}``.
+  This option is **deprecated**. The previous behavior is preserved by using
+  ``SpaceInEmptyBraces`` with ``Custom`` and by setting ``Block`` in
+  ``SpaceInEmptyBracesOptions`` to ``true``.
+
+.. _SpaceInEmptyBraces:
+
+**SpaceInEmptyBraces** (``SpaceInEmptyBracesStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Defines in which cases spaces will be inserted in empty braces.
+
+  Possible values:
+
+  * ``SIEBO_Never`` (in configuration: ``Never``)
+Never put a space in empty braces.
+
+.. code-block:: c++
+
+   void f() {}
+   T x{};
+   while (true) {}
+   struct U1 {};
+   union U2 {};
+   class U3 {};
+   enum U4 {};
+
+  * ``SIEBO_Always`` (in configuration: ``Always``)
+Always put a space in empty braces.
+
+  * ``SIEBO_Custom`` (in configuration: ``Custom``)
+Configure each individual space in empty braces in
+`SpacesInEmptyBracesOptions`.
+
+
+
+.. _SpaceInEmptyBracesOptions:
+
+**SpaceInEmptyBracesOptions** (``SpaceInEmptyBracesCustom``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Control of individual spaces in empty braces.
+
+  If ``SpaceInEmptyBraces`` is set to ``Custom``, use this to specify
+  how each individual space in empty braces case should be handled.
+  Otherwise, this is ignored.
+
+  .. code-block:: yaml
+
+# Example of usage:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Function: true
+  Record: false
+  InitList: true
+  Block: false
+
+  Nested configuration flags:
+
+  Precise control over the spacing in empty braces.
 
   .. code-block:: c++
 
- true:false:
- void f() { }   vs.   void f() {}
- while (true) { } while (true) {}
+# Should be declared this way:
+SpaceInEmptyBraces: Custom
+SpaceInEmptyBracesOptions:
+  Function: true
+  Record: false
+  InitList: true
+  Block: false
+
+  * ``bool Function`` Put a space in empty braces of function definition.
+
+.. code-block:: c++
+
+   true:  false:
+   void f() { }   vs. void f() {}
+
+  * ``bool Record`` Put a space in empty braces of record/struct definition.
+
+.. code-block:: c++
+
+   true:  false:
+   struct U1 { }; vs. struct U1 {};
+   union U2 { };  union U2 {};
+   class U3 { };  class U3 {};
+   enum U4 { };   enum U4 {};
+
+  * ``bool InitList`` Put a space in empty braces of initializer list.
+
+.. code-block:: c++
+
+   true:  false:
+   T x{ };vs. T x{};
+
+  * ``bool Block`` Put a space in empty braces of other blocks, including 
functions and
+record, compatible with ``SpaceInEmptyBlock``.
+
+.. code-block:: c++
+
+   true:  false:
+   void f() { }   vs. void f() {}
+   enum Unit { }; enum Unit {};
+   while (true) { }   while (true) {}
+
 
 .. _SpaceInEmptyParentheses:
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 7c2afd4d94ab0d..3359f9e90cca7f 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4668,13 +4668,11 @@ struct FormatStyle {
   bool SpaceBeforeRangeBasedForLoopColon;
 
   /// If ``true``, spaces will be inserted into ``{}``.
-  /// \code
-  ///true:false:
-  ///void f() { }   vs.   void f() {}
-  ///while (true) { } whil

[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2025-01-14 Thread Kohei Asano via cfe-commits

https://github.com/khei4 edited https://github.com/llvm/llvm-project/pull/93634
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits