summaryrefslogtreecommitdiff
path: root/clang/docs
diff options
context:
space:
mode:
authorJon Phillips <jonap2811@gmail.com>2023-04-29 00:22:22 -0700
committerOwen Pan <owenpiano@gmail.com>2023-04-29 00:36:19 -0700
commitc12aa69a0be9acd0c751bf92318050d2b3730f9b (patch)
tree0ba08c220a07fad8b08c68a5fa9fc7ca3c118b90 /clang/docs
parent40222ddcf8f54fe523b2d14ab7005ebf412330f1 (diff)
downloadllvm-c12aa69a0be9acd0c751bf92318050d2b3730f9b.tar.gz
[clang-format] Add BracedInitializerIndentWidth option
The option allows users to specify how many columns to use to indent the contents of initializer lists. Closes #51070. Differential Revision: https://reviews.llvm.org/D146101
Diffstat (limited to 'clang/docs')
-rw-r--r--clang/docs/ClangFormatStyleOptions.rst35
-rw-r--r--clang/docs/ReleaseNotes.rst2
-rwxr-xr-xclang/docs/tools/dump_format_style.py13
3 files changed, 46 insertions, 4 deletions
diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst
index 2e9038933c81..bdcd1e88d240 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -1829,6 +1829,41 @@ the configuration (without a prefix: ``Auto``).
}
+.. _BracedInitializerIndentWidth:
+
+**BracedInitializerIndentWidth** (``Unsigned``) :versionbadge:`clang-format 17` :ref:`¶ <BracedInitializerIndentWidth>`
+ The number of columns to use to indent the contents of braced init lists.
+ If unset, ``ContinuationIndentWidth`` is used.
+
+ .. code-block:: c++
+
+ AlignAfterOpenBracket: AlwaysBreak
+ BracedInitializerIndentWidth: 2
+
+ void f() {
+ SomeClass c{
+ "foo",
+ "bar",
+ "baz",
+ };
+ auto s = SomeStruct{
+ .foo = "foo",
+ .bar = "bar",
+ .baz = "baz",
+ };
+ SomeArrayT a[3] = {
+ {
+ foo,
+ bar,
+ },
+ {
+ foo,
+ bar,
+ },
+ SomeArrayT{},
+ };
+ }
+
.. _BreakAfterAttributes:
**BreakAfterAttributes** (``AttributeBreakingStyle``) :versionbadge:`clang-format 16` :ref:`¶ <BreakAfterAttributes>`
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 55fc0e6c790b..d66993b0929f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -513,6 +513,8 @@ clang-format
- Add additional Qualifier Ordering support for special cases such
as templates, requires clauses, long qualified names.
- Fix all known issues associated with ``LambdaBodyIndentation: OuterScope``.
+- Add ``BracedInitializerIndentWidth`` which can be used to configure
+ the indentation level of the contents of braced init lists.
libclang
--------
diff --git a/clang/docs/tools/dump_format_style.py b/clang/docs/tools/dump_format_style.py
index fe6e9147ee94..7b032894ce62 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -69,9 +69,13 @@ def to_yaml_type(typestr: str):
elif typestr == 'std::string':
return 'String'
- subtype, napplied = re.subn(r'^std::vector<(.*)>$', r'\1', typestr)
- if napplied == 1:
- return 'List of ' + pluralize(to_yaml_type(subtype))
+ match = re.match(r'std::vector<(.*)>$', typestr)
+ if match:
+ return 'List of ' + pluralize(to_yaml_type(match.group(1)))
+
+ match = re.match(r'std::optional<(.*)>$', typestr)
+ if match:
+ return to_yaml_type(match.group(1))
return typestr
@@ -331,7 +335,8 @@ class OptionsReader:
if option.type not in ['bool', 'unsigned', 'int', 'std::string',
'std::vector<std::string>',
'std::vector<IncludeCategory>',
- 'std::vector<RawStringFormat>']:
+ 'std::vector<RawStringFormat>',
+ 'std::optional<unsigned>']:
if option.type in enums:
option.enum = enums[option.type]
elif option.type in nested_structs: