ClangFormatStyleOptions.rst 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509
  1. ==========================
  2. Clang-Format Style Options
  3. ==========================
  4. :doc:`ClangFormatStyleOptions` describes configurable formatting style options
  5. supported by :doc:`LibFormat` and :doc:`ClangFormat`.
  6. When using :program:`clang-format` command line utility or
  7. ``clang::format::reformat(...)`` functions from code, one can either use one of
  8. the predefined styles (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft) or
  9. create a custom style by configuring specific style options.
  10. Configuring Style with clang-format
  11. ===================================
  12. :program:`clang-format` supports two ways to provide custom style options:
  13. directly specify style configuration in the ``-style=`` command line option or
  14. use ``-style=file`` and put style configuration in the ``.clang-format`` or
  15. ``_clang-format`` file in the project directory.
  16. When using ``-style=file``, :program:`clang-format` for each input file will
  17. try to find the ``.clang-format`` file located in the closest parent directory
  18. of the input file. When the standard input is used, the search is started from
  19. the current directory.
  20. The ``.clang-format`` file uses YAML format:
  21. .. code-block:: yaml
  22. key1: value1
  23. key2: value2
  24. # A comment.
  25. ...
  26. The configuration file can consist of several sections each having different
  27. ``Language:`` parameter denoting the programming language this section of the
  28. configuration is targeted at. See the description of the **Language** option
  29. below for the list of supported languages. The first section may have no
  30. language set, it will set the default style options for all lanugages.
  31. Configuration sections for specific language will override options set in the
  32. default section.
  33. When :program:`clang-format` formats a file, it auto-detects the language using
  34. the file name. When formatting standard input or a file that doesn't have the
  35. extension corresponding to its language, ``-assume-filename=`` option can be
  36. used to override the file name :program:`clang-format` uses to detect the
  37. language.
  38. An example of a configuration file for multiple languages:
  39. .. code-block:: yaml
  40. ---
  41. # We'll use defaults from the LLVM style, but with 4 columns indentation.
  42. BasedOnStyle: LLVM
  43. IndentWidth: 4
  44. ---
  45. Language: Cpp
  46. # Force pointers to the type for C++.
  47. DerivePointerAlignment: false
  48. PointerAlignment: Left
  49. ---
  50. Language: JavaScript
  51. # Use 100 columns for JS.
  52. ColumnLimit: 100
  53. ---
  54. Language: Proto
  55. # Don't format .proto files.
  56. DisableFormat: true
  57. ---
  58. Language: CSharp
  59. # Use 100 columns for C#.
  60. ColumnLimit: 100
  61. ...
  62. An easy way to get a valid ``.clang-format`` file containing all configuration
  63. options of a certain predefined style is:
  64. .. code-block:: console
  65. clang-format -style=llvm -dump-config > .clang-format
  66. When specifying configuration in the ``-style=`` option, the same configuration
  67. is applied for all input files. The format of the configuration is:
  68. .. code-block:: console
  69. -style='{key1: value1, key2: value2, ...}'
  70. Disabling Formatting on a Piece of Code
  71. =======================================
  72. Clang-format understands also special comments that switch formatting in a
  73. delimited range. The code between a comment ``// clang-format off`` or
  74. ``/* clang-format off */`` up to a comment ``// clang-format on`` or
  75. ``/* clang-format on */`` will not be formatted. The comments themselves
  76. will be formatted (aligned) normally.
  77. .. code-block:: c++
  78. int formatted_code;
  79. // clang-format off
  80. void unformatted_code ;
  81. // clang-format on
  82. void formatted_code_again;
  83. Configuring Style in Code
  84. =========================
  85. When using ``clang::format::reformat(...)`` functions, the format is specified
  86. by supplying the `clang::format::FormatStyle
  87. <https://clang.llvm.org/doxygen/structclang_1_1format_1_1FormatStyle.html>`_
  88. structure.
  89. Configurable Format Style Options
  90. =================================
  91. This section lists the supported style options. Value type is specified for
  92. each option. For enumeration types possible values are specified both as a C++
  93. enumeration member (with a prefix, e.g. ``LS_Auto``), and as a value usable in
  94. the configuration (without a prefix: ``Auto``).
  95. **BasedOnStyle** (``string``)
  96. The style used for all options not specifically set in the configuration.
  97. This option is supported only in the :program:`clang-format` configuration
  98. (both within ``-style='{...}'`` and the ``.clang-format`` file).
  99. Possible values:
  100. * ``LLVM``
  101. A style complying with the `LLVM coding standards
  102. <https://llvm.org/docs/CodingStandards.html>`_
  103. * ``Google``
  104. A style complying with `Google's C++ style guide
  105. <https://google.github.io/styleguide/cppguide.html>`_
  106. * ``Chromium``
  107. A style complying with `Chromium's style guide
  108. <https://chromium.googlesource.com/chromium/src/+/master/styleguide/styleguide.md>`_
  109. * ``Mozilla``
  110. A style complying with `Mozilla's style guide
  111. <https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style>`_
  112. * ``WebKit``
  113. A style complying with `WebKit's style guide
  114. <https://www.webkit.org/coding/coding-style.html>`_
  115. * ``Microsoft``
  116. A style complying with `Microsoft's style guide
  117. <https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017>`_
  118. .. START_FORMAT_STYLE_OPTIONS
  119. **AccessModifierOffset** (``int``)
  120. The extra indent or outdent of access modifiers, e.g. ``public:``.
  121. **AlignAfterOpenBracket** (``BracketAlignmentStyle``)
  122. If ``true``, horizontally aligns arguments after an open bracket.
  123. This applies to round brackets (parentheses), angle brackets and square
  124. brackets.
  125. Possible values:
  126. * ``BAS_Align`` (in configuration: ``Align``)
  127. Align parameters on the open bracket, e.g.:
  128. .. code-block:: c++
  129. someLongFunction(argument1,
  130. argument2);
  131. * ``BAS_DontAlign`` (in configuration: ``DontAlign``)
  132. Don't align, instead use ``ContinuationIndentWidth``, e.g.:
  133. .. code-block:: c++
  134. someLongFunction(argument1,
  135. argument2);
  136. * ``BAS_AlwaysBreak`` (in configuration: ``AlwaysBreak``)
  137. Always break after an open bracket, if the parameters don't fit
  138. on a single line, e.g.:
  139. .. code-block:: c++
  140. someLongFunction(
  141. argument1, argument2);
  142. **AlignConsecutiveAssignments** (``bool``)
  143. If ``true``, aligns consecutive assignments.
  144. This will align the assignment operators of consecutive lines. This
  145. will result in formattings like
  146. .. code-block:: c++
  147. int aaaa = 12;
  148. int b = 23;
  149. int ccc = 23;
  150. **AlignConsecutiveDeclarations** (``bool``)
  151. If ``true``, aligns consecutive declarations.
  152. This will align the declaration names of consecutive lines. This
  153. will result in formattings like
  154. .. code-block:: c++
  155. int aaaa = 12;
  156. float b = 23;
  157. std::string ccc = 23;
  158. **AlignConsecutiveMacros** (``bool``)
  159. If ``true``, aligns consecutive C/C++ preprocessor macros.
  160. This will align C/C++ preprocessor macros of consecutive lines.
  161. Will result in formattings like
  162. .. code-block:: c++
  163. #define SHORT_NAME 42
  164. #define LONGER_NAME 0x007f
  165. #define EVEN_LONGER_NAME (2)
  166. #define foo(x) (x * x)
  167. #define bar(y, z) (y + z)
  168. **AlignEscapedNewlines** (``EscapedNewlineAlignmentStyle``)
  169. Options for aligning backslashes in escaped newlines.
  170. Possible values:
  171. * ``ENAS_DontAlign`` (in configuration: ``DontAlign``)
  172. Don't align escaped newlines.
  173. .. code-block:: c++
  174. #define A \
  175. int aaaa; \
  176. int b; \
  177. int dddddddddd;
  178. * ``ENAS_Left`` (in configuration: ``Left``)
  179. Align escaped newlines as far left as possible.
  180. .. code-block:: c++
  181. true:
  182. #define A \
  183. int aaaa; \
  184. int b; \
  185. int dddddddddd;
  186. false:
  187. * ``ENAS_Right`` (in configuration: ``Right``)
  188. Align escaped newlines in the right-most column.
  189. .. code-block:: c++
  190. #define A \
  191. int aaaa; \
  192. int b; \
  193. int dddddddddd;
  194. **AlignOperands** (``bool``)
  195. If ``true``, horizontally align operands of binary and ternary
  196. expressions.
  197. Specifically, this aligns operands of a single expression that needs to be
  198. split over multiple lines, e.g.:
  199. .. code-block:: c++
  200. int aaa = bbbbbbbbbbbbbbb +
  201. ccccccccccccccc;
  202. **AlignTrailingComments** (``bool``)
  203. If ``true``, aligns trailing comments.
  204. .. code-block:: c++
  205. true: false:
  206. int a; // My comment a vs. int a; // My comment a
  207. int b = 2; // comment b int b = 2; // comment about b
  208. **AllowAllArgumentsOnNextLine** (``bool``)
  209. If a function call or braced initializer list doesn't fit on a
  210. line, allow putting all arguments onto the next line, even if
  211. ``BinPackArguments`` is ``false``.
  212. .. code-block:: c++
  213. true:
  214. callFunction(
  215. a, b, c, d);
  216. false:
  217. callFunction(a,
  218. b,
  219. c,
  220. d);
  221. **AllowAllConstructorInitializersOnNextLine** (``bool``)
  222. If a constructor definition with a member initializer list doesn't
  223. fit on a single line, allow putting all member initializers onto the next
  224. line, if ```ConstructorInitializerAllOnOneLineOrOnePerLine``` is true.
  225. Note that this parameter has no effect if
  226. ```ConstructorInitializerAllOnOneLineOrOnePerLine``` is false.
  227. .. code-block:: c++
  228. true:
  229. MyClass::MyClass() :
  230. member0(0), member1(2) {}
  231. false:
  232. MyClass::MyClass() :
  233. member0(0),
  234. member1(2) {}
  235. **AllowAllParametersOfDeclarationOnNextLine** (``bool``)
  236. If the function declaration doesn't fit on a line,
  237. allow putting all parameters of a function declaration onto
  238. the next line even if ``BinPackParameters`` is ``false``.
  239. .. code-block:: c++
  240. true:
  241. void myFunction(
  242. int a, int b, int c, int d, int e);
  243. false:
  244. void myFunction(int a,
  245. int b,
  246. int c,
  247. int d,
  248. int e);
  249. **AllowShortBlocksOnASingleLine** (``ShortBlockStyle``)
  250. Dependent on the value, ``while (true) { continue; }`` can be put on a
  251. single line.
  252. Possible values:
  253. * ``SBS_Never`` (in configuration: ``Never``)
  254. Never merge blocks into a single line.
  255. .. code-block:: c++
  256. while (true) {
  257. }
  258. while (true) {
  259. continue;
  260. }
  261. * ``SBS_Empty`` (in configuration: ``Empty``)
  262. Only merge empty blocks.
  263. .. code-block:: c++
  264. while (true) {}
  265. while (true) {
  266. continue;
  267. }
  268. * ``SBS_Always`` (in configuration: ``Always``)
  269. Always merge short blocks into a single line.
  270. .. code-block:: c++
  271. while (true) {}
  272. while (true) { continue; }
  273. **AllowShortCaseLabelsOnASingleLine** (``bool``)
  274. If ``true``, short case labels will be contracted to a single line.
  275. .. code-block:: c++
  276. true: false:
  277. switch (a) { vs. switch (a) {
  278. case 1: x = 1; break; case 1:
  279. case 2: return; x = 1;
  280. } break;
  281. case 2:
  282. return;
  283. }
  284. **AllowShortFunctionsOnASingleLine** (``ShortFunctionStyle``)
  285. Dependent on the value, ``int f() { return 0; }`` can be put on a
  286. single line.
  287. Possible values:
  288. * ``SFS_None`` (in configuration: ``None``)
  289. Never merge functions into a single line.
  290. * ``SFS_InlineOnly`` (in configuration: ``InlineOnly``)
  291. Only merge functions defined inside a class. Same as "inline",
  292. except it does not implies "empty": i.e. top level empty functions
  293. are not merged either.
  294. .. code-block:: c++
  295. class Foo {
  296. void f() { foo(); }
  297. };
  298. void f() {
  299. foo();
  300. }
  301. void f() {
  302. }
  303. * ``SFS_Empty`` (in configuration: ``Empty``)
  304. Only merge empty functions.
  305. .. code-block:: c++
  306. void f() {}
  307. void f2() {
  308. bar2();
  309. }
  310. * ``SFS_Inline`` (in configuration: ``Inline``)
  311. Only merge functions defined inside a class. Implies "empty".
  312. .. code-block:: c++
  313. class Foo {
  314. void f() { foo(); }
  315. };
  316. void f() {
  317. foo();
  318. }
  319. void f() {}
  320. * ``SFS_All`` (in configuration: ``All``)
  321. Merge all functions fitting on a single line.
  322. .. code-block:: c++
  323. class Foo {
  324. void f() { foo(); }
  325. };
  326. void f() { bar(); }
  327. **AllowShortIfStatementsOnASingleLine** (``ShortIfStyle``)
  328. If ``true``, ``if (a) return;`` can be put on a single line.
  329. Possible values:
  330. * ``SIS_Never`` (in configuration: ``Never``)
  331. Never put short ifs on the same line.
  332. .. code-block:: c++
  333. if (a)
  334. return ;
  335. else {
  336. return;
  337. }
  338. * ``SIS_WithoutElse`` (in configuration: ``WithoutElse``)
  339. Without else put short ifs on the same line only if
  340. the else is not a compound statement.
  341. .. code-block:: c++
  342. if (a) return;
  343. else
  344. return;
  345. * ``SIS_Always`` (in configuration: ``Always``)
  346. Always put short ifs on the same line if
  347. the else is not a compound statement or not.
  348. .. code-block:: c++
  349. if (a) return;
  350. else {
  351. return;
  352. }
  353. **AllowShortLambdasOnASingleLine** (``ShortLambdaStyle``)
  354. Dependent on the value, ``auto lambda []() { return 0; }`` can be put on a
  355. single line.
  356. Possible values:
  357. * ``SLS_None`` (in configuration: ``None``)
  358. Never merge lambdas into a single line.
  359. * ``SLS_Empty`` (in configuration: ``Empty``)
  360. Only merge empty lambdas.
  361. .. code-block:: c++
  362. auto lambda = [](int a) {}
  363. auto lambda2 = [](int a) {
  364. return a;
  365. };
  366. * ``SLS_Inline`` (in configuration: ``Inline``)
  367. Merge lambda into a single line if argument of a function.
  368. .. code-block:: c++
  369. auto lambda = [](int a) {
  370. return a;
  371. };
  372. sort(a.begin(), a.end(), ()[] { return x < y; })
  373. * ``SLS_All`` (in configuration: ``All``)
  374. Merge all lambdas fitting on a single line.
  375. .. code-block:: c++
  376. auto lambda = [](int a) {}
  377. auto lambda2 = [](int a) { return a; };
  378. **AllowShortLoopsOnASingleLine** (``bool``)
  379. If ``true``, ``while (true) continue;`` can be put on a single
  380. line.
  381. **AlwaysBreakAfterDefinitionReturnType** (``DefinitionReturnTypeBreakingStyle``)
  382. The function definition return type breaking style to use. This
  383. option is **deprecated** and is retained for backwards compatibility.
  384. Possible values:
  385. * ``DRTBS_None`` (in configuration: ``None``)
  386. Break after return type automatically.
  387. ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
  388. * ``DRTBS_All`` (in configuration: ``All``)
  389. Always break after the return type.
  390. * ``DRTBS_TopLevel`` (in configuration: ``TopLevel``)
  391. Always break after the return types of top-level functions.
  392. **AlwaysBreakAfterReturnType** (``ReturnTypeBreakingStyle``)
  393. The function declaration return type breaking style to use.
  394. Possible values:
  395. * ``RTBS_None`` (in configuration: ``None``)
  396. Break after return type automatically.
  397. ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
  398. .. code-block:: c++
  399. class A {
  400. int f() { return 0; };
  401. };
  402. int f();
  403. int f() { return 1; }
  404. * ``RTBS_All`` (in configuration: ``All``)
  405. Always break after the return type.
  406. .. code-block:: c++
  407. class A {
  408. int
  409. f() {
  410. return 0;
  411. };
  412. };
  413. int
  414. f();
  415. int
  416. f() {
  417. return 1;
  418. }
  419. * ``RTBS_TopLevel`` (in configuration: ``TopLevel``)
  420. Always break after the return types of top-level functions.
  421. .. code-block:: c++
  422. class A {
  423. int f() { return 0; };
  424. };
  425. int
  426. f();
  427. int
  428. f() {
  429. return 1;
  430. }
  431. * ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``)
  432. Always break after the return type of function definitions.
  433. .. code-block:: c++
  434. class A {
  435. int
  436. f() {
  437. return 0;
  438. };
  439. };
  440. int f();
  441. int
  442. f() {
  443. return 1;
  444. }
  445. * ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``)
  446. Always break after the return type of top-level definitions.
  447. .. code-block:: c++
  448. class A {
  449. int f() { return 0; };
  450. };
  451. int f();
  452. int
  453. f() {
  454. return 1;
  455. }
  456. **AlwaysBreakBeforeMultilineStrings** (``bool``)
  457. If ``true``, always break before multiline string literals.
  458. This flag is mean to make cases where there are multiple multiline strings
  459. in a file look more consistent. Thus, it will only take effect if wrapping
  460. the string at that point leads to it being indented
  461. ``ContinuationIndentWidth`` spaces from the start of the line.
  462. .. code-block:: c++
  463. true: false:
  464. aaaa = vs. aaaa = "bbbb"
  465. "bbbb" "cccc";
  466. "cccc";
  467. **AlwaysBreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``)
  468. The template declaration breaking style to use.
  469. Possible values:
  470. * ``BTDS_No`` (in configuration: ``No``)
  471. Do not force break before declaration.
  472. ``PenaltyBreakTemplateDeclaration`` is taken into account.
  473. .. code-block:: c++
  474. template <typename T> T foo() {
  475. }
  476. template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
  477. int bbbbbbbbbbbbbbbbbbbbb) {
  478. }
  479. * ``BTDS_MultiLine`` (in configuration: ``MultiLine``)
  480. Force break after template declaration only when the following
  481. declaration spans multiple lines.
  482. .. code-block:: c++
  483. template <typename T> T foo() {
  484. }
  485. template <typename T>
  486. T foo(int aaaaaaaaaaaaaaaaaaaaa,
  487. int bbbbbbbbbbbbbbbbbbbbb) {
  488. }
  489. * ``BTDS_Yes`` (in configuration: ``Yes``)
  490. Always break after template declaration.
  491. .. code-block:: c++
  492. template <typename T>
  493. T foo() {
  494. }
  495. template <typename T>
  496. T foo(int aaaaaaaaaaaaaaaaaaaaa,
  497. int bbbbbbbbbbbbbbbbbbbbb) {
  498. }
  499. **BinPackArguments** (``bool``)
  500. If ``false``, a function call's arguments will either be all on the
  501. same line or will have one line each.
  502. .. code-block:: c++
  503. true:
  504. void f() {
  505. f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
  506. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
  507. }
  508. false:
  509. void f() {
  510. f(aaaaaaaaaaaaaaaaaaaa,
  511. aaaaaaaaaaaaaaaaaaaa,
  512. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
  513. }
  514. **BinPackParameters** (``bool``)
  515. If ``false``, a function declaration's or function definition's
  516. parameters will either all be on the same line or will have one line each.
  517. .. code-block:: c++
  518. true:
  519. void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa,
  520. int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
  521. false:
  522. void f(int aaaaaaaaaaaaaaaaaaaa,
  523. int aaaaaaaaaaaaaaaaaaaa,
  524. int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
  525. **BraceWrapping** (``BraceWrappingFlags``)
  526. Control of individual brace wrapping cases.
  527. If ``BreakBeforeBraces`` is set to ``BS_Custom``, use this to specify how
  528. each individual brace case should be handled. Otherwise, this is ignored.
  529. .. code-block:: yaml
  530. # Example of usage:
  531. BreakBeforeBraces: Custom
  532. BraceWrapping:
  533. AfterEnum: true
  534. AfterStruct: false
  535. SplitEmptyFunction: false
  536. Nested configuration flags:
  537. * ``bool AfterCaseLabel`` Wrap case labels.
  538. .. code-block:: c++
  539. false: true:
  540. switch (foo) { vs. switch (foo) {
  541. case 1: { case 1:
  542. bar(); {
  543. break; bar();
  544. } break;
  545. default: { }
  546. plop(); default:
  547. } {
  548. } plop();
  549. }
  550. }
  551. * ``bool AfterClass`` Wrap class definitions.
  552. .. code-block:: c++
  553. true:
  554. class foo {};
  555. false:
  556. class foo
  557. {};
  558. * ``BraceWrappingAfterControlStatementStyle AfterControlStatement``
  559. Wrap control statements (``if``/``for``/``while``/``switch``/..).
  560. Possible values:
  561. * ``BWACS_Never`` (in configuration: ``Never``)
  562. Never wrap braces after a control statement.
  563. .. code-block:: c++
  564. if (foo()) {
  565. } else {
  566. }
  567. for (int i = 0; i < 10; ++i) {
  568. }
  569. * ``BWACS_MultiLine`` (in configuration: ``MultiLine``)
  570. Only wrap braces after a multi-line control statement.
  571. .. code-block:: c++
  572. if (foo && bar &&
  573. baz)
  574. {
  575. quux();
  576. }
  577. while (foo || bar) {
  578. }
  579. * ``BWACS_Always`` (in configuration: ``Always``)
  580. Always wrap braces after a control statement.
  581. .. code-block:: c++
  582. if (foo())
  583. {
  584. } else
  585. {}
  586. for (int i = 0; i < 10; ++i)
  587. {}
  588. * ``bool AfterEnum`` Wrap enum definitions.
  589. .. code-block:: c++
  590. true:
  591. enum X : int
  592. {
  593. B
  594. };
  595. false:
  596. enum X : int { B };
  597. * ``bool AfterFunction`` Wrap function definitions.
  598. .. code-block:: c++
  599. true:
  600. void foo()
  601. {
  602. bar();
  603. bar2();
  604. }
  605. false:
  606. void foo() {
  607. bar();
  608. bar2();
  609. }
  610. * ``bool AfterNamespace`` Wrap namespace definitions.
  611. .. code-block:: c++
  612. true:
  613. namespace
  614. {
  615. int foo();
  616. int bar();
  617. }
  618. false:
  619. namespace {
  620. int foo();
  621. int bar();
  622. }
  623. * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (interfaces, implementations...).
  624. @autoreleasepool and @synchronized blocks are wrapped
  625. according to `AfterControlStatement` flag.
  626. * ``bool AfterStruct`` Wrap struct definitions.
  627. .. code-block:: c++
  628. true:
  629. struct foo
  630. {
  631. int x;
  632. };
  633. false:
  634. struct foo {
  635. int x;
  636. };
  637. * ``bool AfterUnion`` Wrap union definitions.
  638. .. code-block:: c++
  639. true:
  640. union foo
  641. {
  642. int x;
  643. }
  644. false:
  645. union foo {
  646. int x;
  647. }
  648. * ``bool AfterExternBlock`` Wrap extern blocks.
  649. .. code-block:: c++
  650. true:
  651. extern "C"
  652. {
  653. int foo();
  654. }
  655. false:
  656. extern "C" {
  657. int foo();
  658. }
  659. * ``bool BeforeCatch`` Wrap before ``catch``.
  660. .. code-block:: c++
  661. true:
  662. try {
  663. foo();
  664. }
  665. catch () {
  666. }
  667. false:
  668. try {
  669. foo();
  670. } catch () {
  671. }
  672. * ``bool BeforeElse`` Wrap before ``else``.
  673. .. code-block:: c++
  674. true:
  675. if (foo()) {
  676. }
  677. else {
  678. }
  679. false:
  680. if (foo()) {
  681. } else {
  682. }
  683. * ``bool IndentBraces`` Indent the wrapped braces themselves.
  684. * ``bool SplitEmptyFunction`` If ``false``, empty function body can be put on a single line.
  685. This option is used only if the opening brace of the function has
  686. already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
  687. set, and the function could/should not be put on a single line (as per
  688. `AllowShortFunctionsOnASingleLine` and constructor formatting options).
  689. .. code-block:: c++
  690. int f() vs. inf f()
  691. {} {
  692. }
  693. * ``bool SplitEmptyRecord`` If ``false``, empty record (e.g. class, struct or union) body
  694. can be put on a single line. This option is used only if the opening
  695. brace of the record has already been wrapped, i.e. the `AfterClass`
  696. (for classes) brace wrapping mode is set.
  697. .. code-block:: c++
  698. class Foo vs. class Foo
  699. {} {
  700. }
  701. * ``bool SplitEmptyNamespace`` If ``false``, empty namespace body can be put on a single line.
  702. This option is used only if the opening brace of the namespace has
  703. already been wrapped, i.e. the `AfterNamespace` brace wrapping mode is
  704. set.
  705. .. code-block:: c++
  706. namespace Foo vs. namespace Foo
  707. {} {
  708. }
  709. **BreakAfterJavaFieldAnnotations** (``bool``)
  710. Break after each annotation on a field in Java files.
  711. .. code-block:: java
  712. true: false:
  713. @Partial vs. @Partial @Mock DataLoad loader;
  714. @Mock
  715. DataLoad loader;
  716. **BreakBeforeBinaryOperators** (``BinaryOperatorStyle``)
  717. The way to wrap binary operators.
  718. Possible values:
  719. * ``BOS_None`` (in configuration: ``None``)
  720. Break after operators.
  721. .. code-block:: c++
  722. LooooooooooongType loooooooooooooooooooooongVariable =
  723. someLooooooooooooooooongFunction();
  724. bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
  725. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==
  726. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
  727. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >
  728. ccccccccccccccccccccccccccccccccccccccccc;
  729. * ``BOS_NonAssignment`` (in configuration: ``NonAssignment``)
  730. Break before operators that aren't assignments.
  731. .. code-block:: c++
  732. LooooooooooongType loooooooooooooooooooooongVariable =
  733. someLooooooooooooooooongFunction();
  734. bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  735. + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  736. == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  737. && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  738. > ccccccccccccccccccccccccccccccccccccccccc;
  739. * ``BOS_All`` (in configuration: ``All``)
  740. Break before operators.
  741. .. code-block:: c++
  742. LooooooooooongType loooooooooooooooooooooongVariable
  743. = someLooooooooooooooooongFunction();
  744. bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  745. + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  746. == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  747. && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  748. > ccccccccccccccccccccccccccccccccccccccccc;
  749. **BreakBeforeBraces** (``BraceBreakingStyle``)
  750. The brace breaking style to use.
  751. Possible values:
  752. * ``BS_Attach`` (in configuration: ``Attach``)
  753. Always attach braces to surrounding context.
  754. .. code-block:: c++
  755. try {
  756. foo();
  757. } catch () {
  758. }
  759. void foo() { bar(); }
  760. class foo {};
  761. if (foo()) {
  762. } else {
  763. }
  764. enum X : int { A, B };
  765. * ``BS_Linux`` (in configuration: ``Linux``)
  766. Like ``Attach``, but break before braces on function, namespace and
  767. class definitions.
  768. .. code-block:: c++
  769. try {
  770. foo();
  771. } catch () {
  772. }
  773. void foo() { bar(); }
  774. class foo
  775. {
  776. };
  777. if (foo()) {
  778. } else {
  779. }
  780. enum X : int { A, B };
  781. * ``BS_Mozilla`` (in configuration: ``Mozilla``)
  782. Like ``Attach``, but break before braces on enum, function, and record
  783. definitions.
  784. .. code-block:: c++
  785. try {
  786. foo();
  787. } catch () {
  788. }
  789. void foo() { bar(); }
  790. class foo
  791. {
  792. };
  793. if (foo()) {
  794. } else {
  795. }
  796. enum X : int { A, B };
  797. * ``BS_Stroustrup`` (in configuration: ``Stroustrup``)
  798. Like ``Attach``, but break before function definitions, ``catch``, and
  799. ``else``.
  800. .. code-block:: c++
  801. try {
  802. foo();
  803. }
  804. catch () {
  805. }
  806. void foo() { bar(); }
  807. class foo {
  808. };
  809. if (foo()) {
  810. }
  811. else {
  812. }
  813. enum X : int { A, B };
  814. * ``BS_Allman`` (in configuration: ``Allman``)
  815. Always break before braces.
  816. .. code-block:: c++
  817. try
  818. {
  819. foo();
  820. }
  821. catch ()
  822. {
  823. }
  824. void foo() { bar(); }
  825. class foo
  826. {
  827. };
  828. if (foo())
  829. {
  830. }
  831. else
  832. {
  833. }
  834. enum X : int
  835. {
  836. A,
  837. B
  838. };
  839. * ``BS_Whitesmiths`` (in configuration: ``Whitesmiths``)
  840. Like ``Allman`` but always indent braces and line up code with braces.
  841. .. code-block:: c++
  842. try
  843. {
  844. foo();
  845. }
  846. catch ()
  847. {
  848. }
  849. void foo() { bar(); }
  850. class foo
  851. {
  852. };
  853. if (foo())
  854. {
  855. }
  856. else
  857. {
  858. }
  859. enum X : int
  860. {
  861. A,
  862. B
  863. };
  864. * ``BS_GNU`` (in configuration: ``GNU``)
  865. Always break before braces and add an extra level of indentation to
  866. braces of control statements, not to those of class, function
  867. or other definitions.
  868. .. code-block:: c++
  869. try
  870. {
  871. foo();
  872. }
  873. catch ()
  874. {
  875. }
  876. void foo() { bar(); }
  877. class foo
  878. {
  879. };
  880. if (foo())
  881. {
  882. }
  883. else
  884. {
  885. }
  886. enum X : int
  887. {
  888. A,
  889. B
  890. };
  891. * ``BS_WebKit`` (in configuration: ``WebKit``)
  892. Like ``Attach``, but break before functions.
  893. .. code-block:: c++
  894. try {
  895. foo();
  896. } catch () {
  897. }
  898. void foo() { bar(); }
  899. class foo {
  900. };
  901. if (foo()) {
  902. } else {
  903. }
  904. enum X : int { A, B };
  905. * ``BS_Custom`` (in configuration: ``Custom``)
  906. Configure each individual brace in `BraceWrapping`.
  907. **BreakBeforeTernaryOperators** (``bool``)
  908. If ``true``, ternary operators will be placed after line breaks.
  909. .. code-block:: c++
  910. true:
  911. veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription
  912. ? firstValue
  913. : SecondValueVeryVeryVeryVeryLong;
  914. false:
  915. veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
  916. firstValue :
  917. SecondValueVeryVeryVeryVeryLong;
  918. **BreakConstructorInitializers** (``BreakConstructorInitializersStyle``)
  919. The constructor initializers style to use.
  920. Possible values:
  921. * ``BCIS_BeforeColon`` (in configuration: ``BeforeColon``)
  922. Break constructor initializers before the colon and after the commas.
  923. .. code-block:: c++
  924. Constructor()
  925. : initializer1(),
  926. initializer2()
  927. * ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``)
  928. Break constructor initializers before the colon and commas, and align
  929. the commas with the colon.
  930. .. code-block:: c++
  931. Constructor()
  932. : initializer1()
  933. , initializer2()
  934. * ``BCIS_AfterColon`` (in configuration: ``AfterColon``)
  935. Break constructor initializers after the colon and commas.
  936. .. code-block:: c++
  937. Constructor() :
  938. initializer1(),
  939. initializer2()
  940. **BreakInheritanceList** (``BreakInheritanceListStyle``)
  941. The inheritance list style to use.
  942. Possible values:
  943. * ``BILS_BeforeColon`` (in configuration: ``BeforeColon``)
  944. Break inheritance list before the colon and after the commas.
  945. .. code-block:: c++
  946. class Foo
  947. : Base1,
  948. Base2
  949. {};
  950. * ``BILS_BeforeComma`` (in configuration: ``BeforeComma``)
  951. Break inheritance list before the colon and commas, and align
  952. the commas with the colon.
  953. .. code-block:: c++
  954. class Foo
  955. : Base1
  956. , Base2
  957. {};
  958. * ``BILS_AfterColon`` (in configuration: ``AfterColon``)
  959. Break inheritance list after the colon and commas.
  960. .. code-block:: c++
  961. class Foo :
  962. Base1,
  963. Base2
  964. {};
  965. **BreakStringLiterals** (``bool``)
  966. Allow breaking string literals when formatting.
  967. **ColumnLimit** (``unsigned``)
  968. The column limit.
  969. A column limit of ``0`` means that there is no column limit. In this case,
  970. clang-format will respect the input's line breaking decisions within
  971. statements unless they contradict other rules.
  972. **CommentPragmas** (``std::string``)
  973. A regular expression that describes comments with special meaning,
  974. which should not be split into lines or otherwise changed.
  975. .. code-block:: c++
  976. // CommentPragmas: '^ FOOBAR pragma:'
  977. // Will leave the following line unaffected
  978. #include <vector> // FOOBAR pragma: keep
  979. **CompactNamespaces** (``bool``)
  980. If ``true``, consecutive namespace declarations will be on the same
  981. line. If ``false``, each namespace is declared on a new line.
  982. .. code-block:: c++
  983. true:
  984. namespace Foo { namespace Bar {
  985. }}
  986. false:
  987. namespace Foo {
  988. namespace Bar {
  989. }
  990. }
  991. If it does not fit on a single line, the overflowing namespaces get
  992. wrapped:
  993. .. code-block:: c++
  994. namespace Foo { namespace Bar {
  995. namespace Extra {
  996. }}}
  997. **ConstructorInitializerAllOnOneLineOrOnePerLine** (``bool``)
  998. If the constructor initializers don't fit on a line, put each
  999. initializer on its own line.
  1000. .. code-block:: c++
  1001. true:
  1002. SomeClass::Constructor()
  1003. : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
  1004. return 0;
  1005. }
  1006. false:
  1007. SomeClass::Constructor()
  1008. : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa),
  1009. aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) {
  1010. return 0;
  1011. }
  1012. **ConstructorInitializerIndentWidth** (``unsigned``)
  1013. The number of characters to use for indentation of constructor
  1014. initializer lists as well as inheritance lists.
  1015. **ContinuationIndentWidth** (``unsigned``)
  1016. Indent width for line continuations.
  1017. .. code-block:: c++
  1018. ContinuationIndentWidth: 2
  1019. int i = // VeryVeryVeryVeryVeryLongComment
  1020. longFunction( // Again a long comment
  1021. arg);
  1022. **Cpp11BracedListStyle** (``bool``)
  1023. If ``true``, format braced lists as best suited for C++11 braced
  1024. lists.
  1025. Important differences:
  1026. - No spaces inside the braced list.
  1027. - No line break before the closing brace.
  1028. - Indentation with the continuation indent, not with the block indent.
  1029. Fundamentally, C++11 braced lists are formatted exactly like function
  1030. calls would be formatted in their place. If the braced list follows a name
  1031. (e.g. a type or variable name), clang-format formats as if the ``{}`` were
  1032. the parentheses of a function call with that name. If there is no name,
  1033. a zero-length name is assumed.
  1034. .. code-block:: c++
  1035. true: false:
  1036. vector<int> x{1, 2, 3, 4}; vs. vector<int> x{ 1, 2, 3, 4 };
  1037. vector<T> x{{}, {}, {}, {}}; vector<T> x{ {}, {}, {}, {} };
  1038. f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]);
  1039. new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 };
  1040. **DerivePointerAlignment** (``bool``)
  1041. If ``true``, analyze the formatted file for the most common
  1042. alignment of ``&`` and ``*``.
  1043. Pointer and reference alignment styles are going to be updated according
  1044. to the preferences found in the file.
  1045. ``PointerAlignment`` is then used only as fallback.
  1046. **DisableFormat** (``bool``)
  1047. Disables formatting completely.
  1048. **ExperimentalAutoDetectBinPacking** (``bool``)
  1049. If ``true``, clang-format detects whether function calls and
  1050. definitions are formatted with one parameter per line.
  1051. Each call can be bin-packed, one-per-line or inconclusive. If it is
  1052. inconclusive, e.g. completely on one line, but a decision needs to be
  1053. made, clang-format analyzes whether there are other bin-packed cases in
  1054. the input file and act accordingly.
  1055. NOTE: This is an experimental flag, that might go away or be renamed. Do
  1056. not use this in config files, etc. Use at your own risk.
  1057. **FixNamespaceComments** (``bool``)
  1058. If ``true``, clang-format adds missing namespace end comments and
  1059. fixes invalid existing ones.
  1060. .. code-block:: c++
  1061. true: false:
  1062. namespace a { vs. namespace a {
  1063. foo(); foo();
  1064. } // namespace a }
  1065. **ForEachMacros** (``std::vector<std::string>``)
  1066. A vector of macros that should be interpreted as foreach loops
  1067. instead of as function calls.
  1068. These are expected to be macros of the form:
  1069. .. code-block:: c++
  1070. FOREACH(<variable-declaration>, ...)
  1071. <loop-body>
  1072. In the .clang-format configuration file, this can be configured like:
  1073. .. code-block:: yaml
  1074. ForEachMacros: ['RANGES_FOR', 'FOREACH']
  1075. For example: BOOST_FOREACH.
  1076. **IncludeBlocks** (``IncludeBlocksStyle``)
  1077. Dependent on the value, multiple ``#include`` blocks can be sorted
  1078. as one and divided based on category.
  1079. Possible values:
  1080. * ``IBS_Preserve`` (in configuration: ``Preserve``)
  1081. Sort each ``#include`` block separately.
  1082. .. code-block:: c++
  1083. #include "b.h" into #include "b.h"
  1084. #include <lib/main.h> #include "a.h"
  1085. #include "a.h" #include <lib/main.h>
  1086. * ``IBS_Merge`` (in configuration: ``Merge``)
  1087. Merge multiple ``#include`` blocks together and sort as one.
  1088. .. code-block:: c++
  1089. #include "b.h" into #include "a.h"
  1090. #include "b.h"
  1091. #include <lib/main.h> #include <lib/main.h>
  1092. #include "a.h"
  1093. * ``IBS_Regroup`` (in configuration: ``Regroup``)
  1094. Merge multiple ``#include`` blocks together and sort as one.
  1095. Then split into groups based on category priority. See
  1096. ``IncludeCategories``.
  1097. .. code-block:: c++
  1098. #include "b.h" into #include "a.h"
  1099. #include "b.h"
  1100. #include <lib/main.h>
  1101. #include "a.h" #include <lib/main.h>
  1102. **IncludeCategories** (``std::vector<IncludeCategory>``)
  1103. Regular expressions denoting the different ``#include`` categories
  1104. used for ordering ``#includes``.
  1105. `POSIX extended
  1106. <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html>`_
  1107. regular expressions are supported.
  1108. These regular expressions are matched against the filename of an include
  1109. (including the <> or "") in order. The value belonging to the first
  1110. matching regular expression is assigned and ``#includes`` are sorted first
  1111. according to increasing category number and then alphabetically within
  1112. each category.
  1113. If none of the regular expressions match, INT_MAX is assigned as
  1114. category. The main header for a source file automatically gets category 0.
  1115. so that it is generally kept at the beginning of the ``#includes``
  1116. (https://llvm.org/docs/CodingStandards.html#include-style). However, you
  1117. can also assign negative priorities if you have certain headers that
  1118. always need to be first.
  1119. There is a third and optional field ``SortPriority`` which can used while
  1120. ``IncludeBloks = IBS_Regroup`` to define the priority in which ``#includes``
  1121. should be ordered, and value of ``Priority`` defines the order of
  1122. ``#include blocks`` and also enables to group ``#includes`` of different
  1123. priority for order.``SortPriority`` is set to the value of ``Priority``
  1124. as default if it is not assigned.
  1125. To configure this in the .clang-format file, use:
  1126. .. code-block:: yaml
  1127. IncludeCategories:
  1128. - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
  1129. Priority: 2
  1130. SortPriority: 2
  1131. - Regex: '^(<|"(gtest|gmock|isl|json)/)'
  1132. Priority: 3
  1133. - Regex: '<[[:alnum:].]+>'
  1134. Priority: 4
  1135. - Regex: '.*'
  1136. Priority: 1
  1137. SortPriority: 0
  1138. **IncludeIsMainRegex** (``std::string``)
  1139. Specify a regular expression of suffixes that are allowed in the
  1140. file-to-main-include mapping.
  1141. When guessing whether a #include is the "main" include (to assign
  1142. category 0, see above), use this regex of allowed suffixes to the header
  1143. stem. A partial match is done, so that:
  1144. - "" means "arbitrary suffix"
  1145. - "$" means "no suffix"
  1146. For example, if configured to "(_test)?$", then a header a.h would be seen
  1147. as the "main" include in both a.cc and a_test.cc.
  1148. **IndentCaseLabels** (``bool``)
  1149. Indent case labels one level from the switch statement.
  1150. When ``false``, use the same indentation level as for the switch statement.
  1151. Switch statement body is always indented one level more than case labels.
  1152. .. code-block:: c++
  1153. false: true:
  1154. switch (fool) { vs. switch (fool) {
  1155. case 1: case 1:
  1156. bar(); bar();
  1157. break; break;
  1158. default: default:
  1159. plop(); plop();
  1160. } }
  1161. **IndentGotoLabels** (``bool``)
  1162. Indent goto labels.
  1163. When ``false``, goto labels are flushed left.
  1164. .. code-block:: c++
  1165. true: false:
  1166. int f() { vs. int f() {
  1167. if (foo()) { if (foo()) {
  1168. label1: label1:
  1169. bar(); bar();
  1170. } }
  1171. label2: label2:
  1172. return 1; return 1;
  1173. } }
  1174. **IndentPPDirectives** (``PPDirectiveIndentStyle``)
  1175. The preprocessor directive indenting style to use.
  1176. Possible values:
  1177. * ``PPDIS_None`` (in configuration: ``None``)
  1178. Does not indent any directives.
  1179. .. code-block:: c++
  1180. #if FOO
  1181. #if BAR
  1182. #include <foo>
  1183. #endif
  1184. #endif
  1185. * ``PPDIS_AfterHash`` (in configuration: ``AfterHash``)
  1186. Indents directives after the hash.
  1187. .. code-block:: c++
  1188. #if FOO
  1189. # if BAR
  1190. # include <foo>
  1191. # endif
  1192. #endif
  1193. * ``PPDIS_BeforeHash`` (in configuration: ``BeforeHash``)
  1194. Indents directives before the hash.
  1195. .. code-block:: c++
  1196. #if FOO
  1197. #if BAR
  1198. #include <foo>
  1199. #endif
  1200. #endif
  1201. **IndentWidth** (``unsigned``)
  1202. The number of columns to use for indentation.
  1203. .. code-block:: c++
  1204. IndentWidth: 3
  1205. void f() {
  1206. someFunction();
  1207. if (true, false) {
  1208. f();
  1209. }
  1210. }
  1211. **IndentWrappedFunctionNames** (``bool``)
  1212. Indent if a function definition or declaration is wrapped after the
  1213. type.
  1214. .. code-block:: c++
  1215. true:
  1216. LoooooooooooooooooooooooooooooooooooooooongReturnType
  1217. LoooooooooooooooooooooooooooooooongFunctionDeclaration();
  1218. false:
  1219. LoooooooooooooooooooooooooooooooooooooooongReturnType
  1220. LoooooooooooooooooooooooooooooooongFunctionDeclaration();
  1221. **JavaImportGroups** (``std::vector<std::string>``)
  1222. A vector of prefixes ordered by the desired groups for Java imports.
  1223. Each group is separated by a newline. Static imports will also follow the
  1224. same grouping convention above all non-static imports. One group's prefix
  1225. can be a subset of another - the longest prefix is always matched. Within
  1226. a group, the imports are ordered lexicographically.
  1227. In the .clang-format configuration file, this can be configured like
  1228. in the following yaml example. This will result in imports being
  1229. formatted as in the Java example below.
  1230. .. code-block:: yaml
  1231. JavaImportGroups: ['com.example', 'com', 'org']
  1232. .. code-block:: java
  1233. import static com.example.function1;
  1234. import static com.test.function2;
  1235. import static org.example.function3;
  1236. import com.example.ClassA;
  1237. import com.example.Test;
  1238. import com.example.a.ClassB;
  1239. import com.test.ClassC;
  1240. import org.example.ClassD;
  1241. **JavaScriptQuotes** (``JavaScriptQuoteStyle``)
  1242. The JavaScriptQuoteStyle to use for JavaScript strings.
  1243. Possible values:
  1244. * ``JSQS_Leave`` (in configuration: ``Leave``)
  1245. Leave string quotes as they are.
  1246. .. code-block:: js
  1247. string1 = "foo";
  1248. string2 = 'bar';
  1249. * ``JSQS_Single`` (in configuration: ``Single``)
  1250. Always use single quotes.
  1251. .. code-block:: js
  1252. string1 = 'foo';
  1253. string2 = 'bar';
  1254. * ``JSQS_Double`` (in configuration: ``Double``)
  1255. Always use double quotes.
  1256. .. code-block:: js
  1257. string1 = "foo";
  1258. string2 = "bar";
  1259. **JavaScriptWrapImports** (``bool``)
  1260. Whether to wrap JavaScript import/export statements.
  1261. .. code-block:: js
  1262. true:
  1263. import {
  1264. VeryLongImportsAreAnnoying,
  1265. VeryLongImportsAreAnnoying,
  1266. VeryLongImportsAreAnnoying,
  1267. } from 'some/module.js'
  1268. false:
  1269. import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
  1270. **KeepEmptyLinesAtTheStartOfBlocks** (``bool``)
  1271. If true, the empty line at the start of blocks is kept.
  1272. .. code-block:: c++
  1273. true: false:
  1274. if (foo) { vs. if (foo) {
  1275. bar();
  1276. bar(); }
  1277. }
  1278. **Language** (``LanguageKind``)
  1279. Language, this format style is targeted at.
  1280. Possible values:
  1281. * ``LK_None`` (in configuration: ``None``)
  1282. Do not use.
  1283. * ``LK_Cpp`` (in configuration: ``Cpp``)
  1284. Should be used for C, C++.
  1285. * ``LK_CSharp`` (in configuration: ``CSharp``)
  1286. Should be used for C#.
  1287. * ``LK_Java`` (in configuration: ``Java``)
  1288. Should be used for Java.
  1289. * ``LK_JavaScript`` (in configuration: ``JavaScript``)
  1290. Should be used for JavaScript.
  1291. * ``LK_ObjC`` (in configuration: ``ObjC``)
  1292. Should be used for Objective-C, Objective-C++.
  1293. * ``LK_Proto`` (in configuration: ``Proto``)
  1294. Should be used for Protocol Buffers
  1295. (https://developers.google.com/protocol-buffers/).
  1296. * ``LK_TableGen`` (in configuration: ``TableGen``)
  1297. Should be used for TableGen code.
  1298. * ``LK_TextProto`` (in configuration: ``TextProto``)
  1299. Should be used for Protocol Buffer messages in text format
  1300. (https://developers.google.com/protocol-buffers/).
  1301. **MacroBlockBegin** (``std::string``)
  1302. A regular expression matching macros that start a block.
  1303. .. code-block:: c++
  1304. # With:
  1305. MacroBlockBegin: "^NS_MAP_BEGIN|\
  1306. NS_TABLE_HEAD$"
  1307. MacroBlockEnd: "^\
  1308. NS_MAP_END|\
  1309. NS_TABLE_.*_END$"
  1310. NS_MAP_BEGIN
  1311. foo();
  1312. NS_MAP_END
  1313. NS_TABLE_HEAD
  1314. bar();
  1315. NS_TABLE_FOO_END
  1316. # Without:
  1317. NS_MAP_BEGIN
  1318. foo();
  1319. NS_MAP_END
  1320. NS_TABLE_HEAD
  1321. bar();
  1322. NS_TABLE_FOO_END
  1323. **MacroBlockEnd** (``std::string``)
  1324. A regular expression matching macros that end a block.
  1325. **MaxEmptyLinesToKeep** (``unsigned``)
  1326. The maximum number of consecutive empty lines to keep.
  1327. .. code-block:: c++
  1328. MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0
  1329. int f() { int f() {
  1330. int = 1; int i = 1;
  1331. i = foo();
  1332. i = foo(); return i;
  1333. }
  1334. return i;
  1335. }
  1336. **NamespaceIndentation** (``NamespaceIndentationKind``)
  1337. The indentation used for namespaces.
  1338. Possible values:
  1339. * ``NI_None`` (in configuration: ``None``)
  1340. Don't indent in namespaces.
  1341. .. code-block:: c++
  1342. namespace out {
  1343. int i;
  1344. namespace in {
  1345. int i;
  1346. }
  1347. }
  1348. * ``NI_Inner`` (in configuration: ``Inner``)
  1349. Indent only in inner namespaces (nested in other namespaces).
  1350. .. code-block:: c++
  1351. namespace out {
  1352. int i;
  1353. namespace in {
  1354. int i;
  1355. }
  1356. }
  1357. * ``NI_All`` (in configuration: ``All``)
  1358. Indent in all namespaces.
  1359. .. code-block:: c++
  1360. namespace out {
  1361. int i;
  1362. namespace in {
  1363. int i;
  1364. }
  1365. }
  1366. **NamespaceMacros** (``std::vector<std::string>``)
  1367. A vector of macros which are used to open namespace blocks.
  1368. These are expected to be macros of the form:
  1369. .. code-block:: c++
  1370. NAMESPACE(<namespace-name>, ...) {
  1371. <namespace-content>
  1372. }
  1373. For example: TESTSUITE
  1374. **ObjCBinPackProtocolList** (``BinPackStyle``)
  1375. Controls bin-packing Objective-C protocol conformance list
  1376. items into as few lines as possible when they go over ``ColumnLimit``.
  1377. If ``Auto`` (the default), delegates to the value in
  1378. ``BinPackParameters``. If that is ``true``, bin-packs Objective-C
  1379. protocol conformance list items into as few lines as possible
  1380. whenever they go over ``ColumnLimit``.
  1381. If ``Always``, always bin-packs Objective-C protocol conformance
  1382. list items into as few lines as possible whenever they go over
  1383. ``ColumnLimit``.
  1384. If ``Never``, lays out Objective-C protocol conformance list items
  1385. onto individual lines whenever they go over ``ColumnLimit``.
  1386. .. code-block:: objc
  1387. Always (or Auto, if BinPackParameters=true):
  1388. @interface ccccccccccccc () <
  1389. ccccccccccccc, ccccccccccccc,
  1390. ccccccccccccc, ccccccccccccc> {
  1391. }
  1392. Never (or Auto, if BinPackParameters=false):
  1393. @interface ddddddddddddd () <
  1394. ddddddddddddd,
  1395. ddddddddddddd,
  1396. ddddddddddddd,
  1397. ddddddddddddd> {
  1398. }
  1399. Possible values:
  1400. * ``BPS_Auto`` (in configuration: ``Auto``)
  1401. Automatically determine parameter bin-packing behavior.
  1402. * ``BPS_Always`` (in configuration: ``Always``)
  1403. Always bin-pack parameters.
  1404. * ``BPS_Never`` (in configuration: ``Never``)
  1405. Never bin-pack parameters.
  1406. **ObjCBlockIndentWidth** (``unsigned``)
  1407. The number of characters to use for indentation of ObjC blocks.
  1408. .. code-block:: objc
  1409. ObjCBlockIndentWidth: 4
  1410. [operation setCompletionBlock:^{
  1411. [self onOperationDone];
  1412. }];
  1413. **ObjCSpaceAfterProperty** (``bool``)
  1414. Add a space after ``@property`` in Objective-C, i.e. use
  1415. ``@property (readonly)`` instead of ``@property(readonly)``.
  1416. **ObjCSpaceBeforeProtocolList** (``bool``)
  1417. Add a space in front of an Objective-C protocol list, i.e. use
  1418. ``Foo <Protocol>`` instead of ``Foo<Protocol>``.
  1419. **PenaltyBreakAssignment** (``unsigned``)
  1420. The penalty for breaking around an assignment operator.
  1421. **PenaltyBreakBeforeFirstCallParameter** (``unsigned``)
  1422. The penalty for breaking a function call after ``call(``.
  1423. **PenaltyBreakComment** (``unsigned``)
  1424. The penalty for each line break introduced inside a comment.
  1425. **PenaltyBreakFirstLessLess** (``unsigned``)
  1426. The penalty for breaking before the first ``<<``.
  1427. **PenaltyBreakString** (``unsigned``)
  1428. The penalty for each line break introduced inside a string literal.
  1429. **PenaltyBreakTemplateDeclaration** (``unsigned``)
  1430. The penalty for breaking after template declaration.
  1431. **PenaltyExcessCharacter** (``unsigned``)
  1432. The penalty for each character outside of the column limit.
  1433. **PenaltyReturnTypeOnItsOwnLine** (``unsigned``)
  1434. Penalty for putting the return type of a function onto its own
  1435. line.
  1436. **PointerAlignment** (``PointerAlignmentStyle``)
  1437. Pointer and reference alignment style.
  1438. Possible values:
  1439. * ``PAS_Left`` (in configuration: ``Left``)
  1440. Align pointer to the left.
  1441. .. code-block:: c++
  1442. int* a;
  1443. * ``PAS_Right`` (in configuration: ``Right``)
  1444. Align pointer to the right.
  1445. .. code-block:: c++
  1446. int *a;
  1447. * ``PAS_Middle`` (in configuration: ``Middle``)
  1448. Align pointer in the middle.
  1449. .. code-block:: c++
  1450. int * a;
  1451. **RawStringFormats** (``std::vector<RawStringFormat>``)
  1452. Defines hints for detecting supported languages code blocks in raw
  1453. strings.
  1454. A raw string with a matching delimiter or a matching enclosing function
  1455. name will be reformatted assuming the specified language based on the
  1456. style for that language defined in the .clang-format file. If no style has
  1457. been defined in the .clang-format file for the specific language, a
  1458. predefined style given by 'BasedOnStyle' is used. If 'BasedOnStyle' is not
  1459. found, the formatting is based on llvm style. A matching delimiter takes
  1460. precedence over a matching enclosing function name for determining the
  1461. language of the raw string contents.
  1462. If a canonical delimiter is specified, occurrences of other delimiters for
  1463. the same language will be updated to the canonical if possible.
  1464. There should be at most one specification per language and each delimiter
  1465. and enclosing function should not occur in multiple specifications.
  1466. To configure this in the .clang-format file, use:
  1467. .. code-block:: yaml
  1468. RawStringFormats:
  1469. - Language: TextProto
  1470. Delimiters:
  1471. - 'pb'
  1472. - 'proto'
  1473. EnclosingFunctions:
  1474. - 'PARSE_TEXT_PROTO'
  1475. BasedOnStyle: google
  1476. - Language: Cpp
  1477. Delimiters:
  1478. - 'cc'
  1479. - 'cpp'
  1480. BasedOnStyle: llvm
  1481. CanonicalDelimiter: 'cc'
  1482. **ReflowComments** (``bool``)
  1483. If ``true``, clang-format will attempt to re-flow comments.
  1484. .. code-block:: c++
  1485. false:
  1486. // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information
  1487. /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */
  1488. true:
  1489. // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
  1490. // information
  1491. /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
  1492. * information */
  1493. **SortIncludes** (``bool``)
  1494. If ``true``, clang-format will sort ``#includes``.
  1495. .. code-block:: c++
  1496. false: true:
  1497. #include "b.h" vs. #include "a.h"
  1498. #include "a.h" #include "b.h"
  1499. **SortUsingDeclarations** (``bool``)
  1500. If ``true``, clang-format will sort using declarations.
  1501. The order of using declarations is defined as follows:
  1502. Split the strings by "::" and discard any initial empty strings. The last
  1503. element of each list is a non-namespace name; all others are namespace
  1504. names. Sort the lists of names lexicographically, where the sort order of
  1505. individual names is that all non-namespace names come before all namespace
  1506. names, and within those groups, names are in case-insensitive
  1507. lexicographic order.
  1508. .. code-block:: c++
  1509. false: true:
  1510. using std::cout; vs. using std::cin;
  1511. using std::cin; using std::cout;
  1512. **SpaceAfterCStyleCast** (``bool``)
  1513. If ``true``, a space is inserted after C style casts.
  1514. .. code-block:: c++
  1515. true: false:
  1516. (int) i; vs. (int)i;
  1517. **SpaceAfterLogicalNot** (``bool``)
  1518. If ``true``, a space is inserted after the logical not operator (``!``).
  1519. .. code-block:: c++
  1520. true: false:
  1521. ! someExpression(); vs. !someExpression();
  1522. **SpaceAfterTemplateKeyword** (``bool``)
  1523. If ``true``, a space will be inserted after the 'template' keyword.
  1524. .. code-block:: c++
  1525. true: false:
  1526. template <int> void foo(); vs. template<int> void foo();
  1527. **SpaceBeforeAssignmentOperators** (``bool``)
  1528. If ``false``, spaces will be removed before assignment operators.
  1529. .. code-block:: c++
  1530. true: false:
  1531. int a = 5; vs. int a= 5;
  1532. a += 42; a+= 42;
  1533. **SpaceBeforeCpp11BracedList** (``bool``)
  1534. If ``true``, a space will be inserted before a C++11 braced list
  1535. used to initialize an object (after the preceding identifier or type).
  1536. .. code-block:: c++
  1537. true: false:
  1538. Foo foo { bar }; vs. Foo foo{ bar };
  1539. Foo {}; Foo{};
  1540. vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 };
  1541. new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 };
  1542. **SpaceBeforeCtorInitializerColon** (``bool``)
  1543. If ``false``, spaces will be removed before constructor initializer
  1544. colon.
  1545. .. code-block:: c++
  1546. true: false:
  1547. Foo::Foo() : a(a) {} Foo::Foo(): a(a) {}
  1548. **SpaceBeforeInheritanceColon** (``bool``)
  1549. If ``false``, spaces will be removed before inheritance colon.
  1550. .. code-block:: c++
  1551. true: false:
  1552. class Foo : Bar {} vs. class Foo: Bar {}
  1553. **SpaceBeforeParens** (``SpaceBeforeParensOptions``)
  1554. Defines in which cases to put a space before opening parentheses.
  1555. Possible values:
  1556. * ``SBPO_Never`` (in configuration: ``Never``)
  1557. Never put a space before opening parentheses.
  1558. .. code-block:: c++
  1559. void f() {
  1560. if(true) {
  1561. f();
  1562. }
  1563. }
  1564. * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``)
  1565. Put a space before opening parentheses only after control statement
  1566. keywords (``for/if/while...``).
  1567. .. code-block:: c++
  1568. void f() {
  1569. if (true) {
  1570. f();
  1571. }
  1572. }
  1573. * ``SBPO_NonEmptyParentheses`` (in configuration: ``NonEmptyParentheses``)
  1574. Put a space before opening parentheses only if the parentheses are not
  1575. empty i.e. '()'
  1576. .. code-block:: c++
  1577. void() {
  1578. if (true) {
  1579. f();
  1580. g (x, y, z);
  1581. }
  1582. }
  1583. * ``SBPO_Always`` (in configuration: ``Always``)
  1584. Always put a space before opening parentheses, except when it's
  1585. prohibited by the syntax rules (in function-like macro definitions) or
  1586. when determined by other style rules (after unary operators, opening
  1587. parentheses, etc.)
  1588. .. code-block:: c++
  1589. void f () {
  1590. if (true) {
  1591. f ();
  1592. }
  1593. }
  1594. **SpaceBeforeRangeBasedForLoopColon** (``bool``)
  1595. If ``false``, spaces will be removed before range-based for loop
  1596. colon.
  1597. .. code-block:: c++
  1598. true: false:
  1599. for (auto v : values) {} vs. for(auto v: values) {}
  1600. **SpaceInEmptyBlock** (``bool``)
  1601. If ``true``, spaces will be inserted into ``{}``.
  1602. .. code-block:: c++
  1603. true: false:
  1604. void f() { } vs. void f() {}
  1605. while (true) { } while (true) {}
  1606. **SpaceInEmptyParentheses** (``bool``)
  1607. If ``true``, spaces may be inserted into ``()``.
  1608. .. code-block:: c++
  1609. true: false:
  1610. void f( ) { vs. void f() {
  1611. int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()};
  1612. if (true) { if (true) {
  1613. f( ); f();
  1614. } }
  1615. } }
  1616. **SpacesBeforeTrailingComments** (``unsigned``)
  1617. The number of spaces before trailing line comments
  1618. (``//`` - comments).
  1619. This does not affect trailing block comments (``/*`` - comments) as
  1620. those commonly have different usage patterns and a number of special
  1621. cases.
  1622. .. code-block:: c++
  1623. SpacesBeforeTrailingComments: 3
  1624. void f() {
  1625. if (true) { // foo1
  1626. f(); // bar
  1627. } // foo
  1628. }
  1629. **SpacesInAngles** (``bool``)
  1630. If ``true``, spaces will be inserted after ``<`` and before ``>``
  1631. in template argument lists.
  1632. .. code-block:: c++
  1633. true: false:
  1634. static_cast< int >(arg); vs. static_cast<int>(arg);
  1635. std::function< void(int) > fct; std::function<void(int)> fct;
  1636. **SpacesInCStyleCastParentheses** (``bool``)
  1637. If ``true``, spaces may be inserted into C style casts.
  1638. .. code-block:: c++
  1639. true: false:
  1640. x = ( int32 )y vs. x = (int32)y
  1641. **SpacesInContainerLiterals** (``bool``)
  1642. If ``true``, spaces are inserted inside container literals (e.g.
  1643. ObjC and Javascript array and dict literals).
  1644. .. code-block:: js
  1645. true: false:
  1646. var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3];
  1647. f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});
  1648. **SpacesInParentheses** (``bool``)
  1649. If ``true``, spaces will be inserted after ``(`` and before ``)``.
  1650. .. code-block:: c++
  1651. true: false:
  1652. t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
  1653. **SpacesInSquareBrackets** (``bool``)
  1654. If ``true``, spaces will be inserted after ``[`` and before ``]``.
  1655. Lambdas without arguments or unspecified size array declarations will not be
  1656. affected.
  1657. .. code-block:: c++
  1658. true: false:
  1659. int a[ 5 ]; vs. int a[5];
  1660. std::unique_ptr<int[]> foo() {} // Won't be affected
  1661. **Standard** (``LanguageStandard``)
  1662. Parse and format C++ constructs compatible with this standard.
  1663. .. code-block:: c++
  1664. c++03: latest:
  1665. vector<set<int> > x; vs. vector<set<int>> x;
  1666. Possible values:
  1667. * ``LS_Cpp03`` (in configuration: ``c++03``)
  1668. Use C++03-compatible syntax.
  1669. * ``LS_Cpp11`` (in configuration: ``c++11``)
  1670. Use C++11-compatible syntax.
  1671. * ``LS_Cpp14`` (in configuration: ``c++14``)
  1672. Use C++14-compatible syntax.
  1673. * ``LS_Cpp17`` (in configuration: ``c++17``)
  1674. Use C++17-compatible syntax.
  1675. * ``LS_Cpp20`` (in configuration: ``c++20``)
  1676. Use C++20-compatible syntax.
  1677. * ``LS_Latest`` (in configuration: ``Latest``)
  1678. Parse and format using the latest supported language version.
  1679. * ``LS_Auto`` (in configuration: ``Auto``)
  1680. Automatic detection based on the input.
  1681. * ``Cpp03``: deprecated alias for ``c++03``
  1682. * ``Cpp11``: deprecated alias for ``Latest``
  1683. **StatementMacros** (``std::vector<std::string>``)
  1684. A vector of macros that should be interpreted as complete
  1685. statements.
  1686. Typical macros are expressions, and require a semi-colon to be
  1687. added; sometimes this is not the case, and this allows to make
  1688. clang-format aware of such cases.
  1689. For example: Q_UNUSED
  1690. **TabWidth** (``unsigned``)
  1691. The number of columns used for tab stops.
  1692. **TypenameMacros** (``std::vector<std::string>``)
  1693. A vector of macros that should be interpreted as type declarations
  1694. instead of as function calls.
  1695. These are expected to be macros of the form:
  1696. .. code-block:: c++
  1697. STACK_OF(...)
  1698. In the .clang-format configuration file, this can be configured like:
  1699. .. code-block:: yaml
  1700. TypenameMacros: ['STACK_OF', 'LIST']
  1701. For example: OpenSSL STACK_OF, BSD LIST_ENTRY.
  1702. **UseTab** (``UseTabStyle``)
  1703. The way to use tab characters in the resulting file.
  1704. Possible values:
  1705. * ``UT_Never`` (in configuration: ``Never``)
  1706. Never use tab.
  1707. * ``UT_ForIndentation`` (in configuration: ``ForIndentation``)
  1708. Use tabs only for indentation.
  1709. * ``UT_ForContinuationAndIndentation`` (in configuration: ``ForContinuationAndIndentation``)
  1710. Use tabs only for line continuation and indentation.
  1711. * ``UT_Always`` (in configuration: ``Always``)
  1712. Use tabs whenever we need to fill whitespace that spans at least from
  1713. one tab stop to the next one.
  1714. .. END_FORMAT_STYLE_OPTIONS
  1715. Adding additional style options
  1716. ===============================
  1717. Each additional style option adds costs to the clang-format project. Some of
  1718. these costs affect the clang-format development itself, as we need to make
  1719. sure that any given combination of options work and that new features don't
  1720. break any of the existing options in any way. There are also costs for end users
  1721. as options become less discoverable and people have to think about and make a
  1722. decision on options they don't really care about.
  1723. The goal of the clang-format project is more on the side of supporting a
  1724. limited set of styles really well as opposed to supporting every single style
  1725. used by a codebase somewhere in the wild. Of course, we do want to support all
  1726. major projects and thus have established the following bar for adding style
  1727. options. Each new style option must ..
  1728. * be used in a project of significant size (have dozens of contributors)
  1729. * have a publicly accessible style guide
  1730. * have a person willing to contribute and maintain patches
  1731. Examples
  1732. ========
  1733. A style similar to the `Linux Kernel style
  1734. <https://www.kernel.org/doc/Documentation/CodingStyle>`_:
  1735. .. code-block:: yaml
  1736. BasedOnStyle: LLVM
  1737. IndentWidth: 8
  1738. UseTab: Always
  1739. BreakBeforeBraces: Linux
  1740. AllowShortIfStatementsOnASingleLine: false
  1741. IndentCaseLabels: false
  1742. The result is (imagine that tabs are used for indentation here):
  1743. .. code-block:: c++
  1744. void test()
  1745. {
  1746. switch (x) {
  1747. case 0:
  1748. case 1:
  1749. do_something();
  1750. break;
  1751. case 2:
  1752. do_something_else();
  1753. break;
  1754. default:
  1755. break;
  1756. }
  1757. if (condition)
  1758. do_something_completely_different();
  1759. if (x == y) {
  1760. q();
  1761. } else if (x > y) {
  1762. w();
  1763. } else {
  1764. r();
  1765. }
  1766. }
  1767. A style similar to the default Visual Studio formatting style:
  1768. .. code-block:: yaml
  1769. UseTab: Never
  1770. IndentWidth: 4
  1771. BreakBeforeBraces: Allman
  1772. AllowShortIfStatementsOnASingleLine: false
  1773. IndentCaseLabels: false
  1774. ColumnLimit: 0
  1775. The result is:
  1776. .. code-block:: c++
  1777. void test()
  1778. {
  1779. switch (suffix)
  1780. {
  1781. case 0:
  1782. case 1:
  1783. do_something();
  1784. break;
  1785. case 2:
  1786. do_something_else();
  1787. break;
  1788. default:
  1789. break;
  1790. }
  1791. if (condition)
  1792. do_somthing_completely_different();
  1793. if (x == y)
  1794. {
  1795. q();
  1796. }
  1797. else if (x > y)
  1798. {
  1799. w();
  1800. }
  1801. else
  1802. {
  1803. r();
  1804. }
  1805. }