Commit Graph

159 Commits

Author SHA1 Message Date
Jake Merdich 51dbda5438 [clang-format][docfix] Update predefined styles in docs
Summary:
The predefined styles that clang-format supports are listed in two
places, and neither is up-to-date. GNU style isn't mentioned at all!

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80309
2020-05-20 20:03:53 -04:00
mydeveloperday 6ef45b0426 [clang-format] Added new option IndentExternBlock
Reviewers: MyDeveloperDay, krasimir, klimek, mitchell-stellar, Abpostelnicu

Patch By: MarcusJohnson91

Reviewed By: MyDeveloperDay, Abpostelnicu

Subscribers: sylvestre.ledru, Abpostelnicu, cfe-commits

Tags: #clang, #clang-format, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D75791
2020-05-20 21:27:15 +01:00
mydeveloperday 807ab2cd0d [clang-format] [PR42164] Add Option to Break before While
Summary:
Its currently not possible to recreate the GNU style using the `BreakBeforeBraces: Custom` style due to a lack of missing `BeforeWhile` in the `BraceWrappingFlags`

The following request was raised to add `BeforeWhile` in a `do..while` context like `BeforeElse` and `BeforeCatch` to give greater control over the positioning of the `while`

https://bugs.llvm.org/show_bug.cgi?id=42164

Reviewers: krasimir, mitchell-stellar, sammccall

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D79325
2020-05-20 07:48:45 +01:00
mydeveloperday b99bf0e08b [clang-format][PR45816] Add AlignConsecutiveBitFields
Summary:
The following revision follows D80115 since @MyDeveloperDay and I apparently both had the same idea at the same time, for https://bugs.llvm.org/show_bug.cgi?id=45816 and my efforts on tooling support for AMDVLK, respectively.

This option aligns adjacent bitfield separators across lines, in a manner similar to AlignConsecutiveAssignments and friends.

Example:
```
struct RawFloat {
  uint32_t sign : 1;
  uint32_t exponent : 8;
  uint32_t mantissa : 23;
};
```
would become
```
struct RawFloat {
  uint32_t sign     : 1;
  uint32_t exponent : 8;
  uint32_t mantissa : 23;
};
```

This also handles c++2a style bitfield-initializers with AlignConsecutiveAssignments.
```
struct RawFloat {
  uint32_t sign     : 1  = 0;
  uint32_t exponent : 8  = 127;
  uint32_t mantissa : 23 = 0;
}; // defaults to 1.0f
```

Things this change does not do:
 - Align multiple comma-chained bitfield variables. None of the other
   AlignConsecutive* options seem to implement that either.
 - Detect bitfields that have a width specified with something other
   than a numeric literal (ie, `int a : SOME_MACRO;`). That'd be fairly
   difficult to parse and is rare.

Patch By:  JakeMerdichAMD

Reviewed By: MyDeveloperDay

Subscribers: cfe-commits, MyDeveloperDay

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D80176
2020-05-20 07:42:58 +01:00
Francois Ferrand 0ee04e6e0d [clang-format] Fix AlignOperands when BreakBeforeBinaryOperators is set
Summary:
Even when BreakBeforeBinaryOperators is set, AlignOperands kept
aligning the beginning of the line, even when it could align the
actual operands (e.g. after an assignment).

With this patch, the operands are actually aligned, and the operator
gets aligned with the equal sign:

  int aaaaa = bbbbbb
            + cccccc;

This not happen in tests, to avoid 'breaking' the indentation:

  if (aaaaa
      && bbbbb)
    return;

Reviewers: krasimir, djasper, klimek, MyDeveloperDay

Reviewed By: MyDeveloperDay

Subscribers: MyDeveloperDay, acoomans, cfe-commits, klimek

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D32478
2020-05-15 16:40:31 +02:00
Daan De Meyer f21c704553 clang-format: Add ControlStatementsExceptForEachMacros option to SpaceBeforeParens
Summary: systemd recently added a clang-format file. One issue I
encountered in using clang-format on systemd is that systemd does
not add a space before the parens of their foreach macros but
clang-format always adds a space. This does not seem to be
configurable in clang-format. This revision adds the
ControlStatementsExceptForEachMacros option to SpaceBeforeParens
which puts a space before all control statement parens except
ForEach macros. This drastically reduces the amount of changes
when running clang-format on systemd's source code.

Reviewers: MyDeveloperDay, krasimir, mitchell-stellar

Reviewed By: MyDeveloperDay

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D78869
2020-05-06 20:59:24 +02:00
Aaron Smith 292058a5d6 [clang-format] Fix Microsoft style for enums
Summary:
Before this change enums were formatted incorrectly for the Microsoft style.

[C++ Example]

    enum {
      one,
      two
    } three, four;

[Incorrectly Formatted]

    enum
    {
      one,
      two
    } three,
        four;

[Correct Format with Patch]

    enum
    {
      one,
      two
    } three, four;

Reviewers: jbcoe, MyDeveloperDay, rnk

Reviewed By: MyDeveloperDay

Subscribers: cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D78982
2020-04-30 09:11:54 -07:00
mydeveloperday 0fa7e4adca [clang-format] NFC Correct clang-format headers file so documentation can be once again autogenerated
Summary:
`ClangFormatStyleOptions.rst` should ALWAYS be autogenerated from Format.h using `clang/docs/tools/dump_format_style.py` if not its liable to get removed leaving options undocumented.

This revision reworks the documentation for {D73354} {D73768} to ensure we can continue to regenerated

Fix other minor changes that ensure the documentation remains consistent (Format.h obviously got re clang-formatted after the rst had been regenerated previously)

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D79095
2020-04-30 10:50:29 +01:00
Haojian Wu 47ef09e484 Revert "clang-format: support aligned nested conditionals formatting"
This reverts 3d61b1120e, 5daa25fd7a

The clang-format test (FormatTest.ConfigurableUseOfTab) is failing in the buildbot:

http://lab.llvm.org:8011/builders/clang-s390x-linux/builds/31811/steps/ninja%20check%201/logs/stdio
2020-04-23 09:25:01 +02:00
Francois Ferrand 3d61b1120e clang-format: Introduce stricter AlignOperands flag
Summary:
Even when BreakBeforeBinaryOperators is set, AlignOperands kept
aligning the beginning of the line, even when it could align the
actual operands (e.g. after an assignment).

With this patch, there is an option to actually align the operands, so
that the operator gets right-aligned with the equal sign or return
operator:

  int aaaaa = bbbbbb
            + cccccc;
  return aaaaaaa
      && bbbbbbb;

This not happen in parentheses, to avoid 'breaking' the indentation:

  if (aaaaa
      && bbbbb)
    return;

Reviewers: krasimir, djasper

Subscribers: cfe-commits, klimek

Differential Revision: https://reviews.llvm.org/D32478
2020-04-22 17:36:38 +02:00
mydeveloperday e8111502d8 [clang-format] use spaces for alignment with UT_ForContinuationAndIndentation
Summary:
Use spaces instead of tabs for alignment with UT_ForContinuationAndIndentation to make the code aligned for any tab/indent width.

Fixes https://bugs.llvm.org/show_bug.cgi?id=38381

Reviewed By: MyDeveloperDay

Patch By: fickert

Tags: #clang-format

Differential Revision: https://reviews.llvm.org/D75034
2020-04-13 15:14:26 +01:00
Kanglei Fang 28ecd7f0b0 [clang-format] Don't break multi block parameters on ObjCBreakBeforeNestedBlockParam
Summary:
While [the original diff](https://reviews.llvm.org/D42493) makes a lot of sense, and multiple inline block parameter/trailing paramemter after inline block paramemter should be discouraged, the formatting result is different than what xcode does by default
For the exact same example provided in the original diff:
```
[object
  blockArgument:^{
    a = 42;
  }
     anotherArg:42];
```
The code is hard to read and not very visually pleasing

This diff uses `ObjCBreakBeforeNestedBlockParam` to shield from the formatting
When it's set to false, don't allign the inline block paramemters.

Reviewers: jolesiak, benhamilton, jinlin

Reviewed By: jolesiak

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77039
2020-04-06 14:20:09 -07:00
Mitchell Balan c5c487f0d4 Revert "[clang-format] Add option to specify explicit config file"
There were a number of unexpected test failures.

This reverts commit 10b1a87ba3.
2020-03-11 16:14:42 -04:00
Mitchell Balan 10b1a87ba3 [clang-format] Add option to specify explicit config file
Summary:
This diff extends the -style=file option to allow a config file to be specified explicitly. This is useful (for instance) when adding IDE commands to reformat code to a personal style.

Reviewers: djasper, ioeric, krasimir, MyDeveloperDay

Reviewed by: MyDeveloperDay

Contributed by: tnorth

Subscribers: cfe-commits, lebedev.ri, MyDeveloperDay, klimek, sammccall, mitchell-stellar

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D72326
2020-03-11 15:56:44 -04:00
Wawha fa0118e6e5 [clang-format] Add new option BeforeLambdaBody in Allman style.
This option add a line break then a lambda is inside a function call.

Reviewers : djasper, klimek, krasimir, MyDeveloperDay

Reviewed By: MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D44609
2020-02-13 22:16:41 +01:00
Martin Probst dc04c54fc1 clang-format: [JS] document InsertTrailingCommas.
Summary: In release notes and the regular docs.

Reviewers: MyDeveloperDay

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73768
2020-02-03 08:51:52 +01:00
mydeveloperday 70c98671fa [clang-format] Add option for not breaking line before ObjC params
Summary:
From `clang-format` version 3.7.0 and up, , there is no way to keep following format of ObjectiveC block:
```
- (void)_aMethod
{
    [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
        u = c;
    }]
}
```
Regardless of the change in `.clang-format` configuration file, all parameters will be lined up so that colons will be on the same column, like following:
```
- (void)_aMethod
{
    [self.test1 t:self
                w:self
         callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
             u = c;
         }]
}
```

Considering with ObjectiveC, the first code style is cleaner & more readable for some people, I've added a config option: `ObjCDontBreakBeforeNestedBlockParam` (boolean) so that if it is enable, the first code style will be favored.

Reviewed By: MyDeveloperDay

Patch By: ghvg1313

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D70926
2020-02-01 17:39:34 +00:00
mydeveloperday 14c044756e [clang-format] Add IndentCaseBlocks option
Summary:
The documentation for IndentCaseLabels claimed that the "Switch
statement body is always indented one level more than case labels". This
is technically false for the code block immediately following the label.
Its closing bracket aligns with the start of the label.

If the case label are not indented, it leads to a style where the
closing bracket of the block aligns with the closing bracket of the
switch statement, which can be hard to parse.

This change introduces a new option, IndentCaseBlocks, which when true
treats the block as a scope block (which it technically is).

(Note: regenerated ClangFormatStyleOptions.rst using tools/dump_style.py)

Reviewed By: MyDeveloperDay

Patch By: capn

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D72276
2020-01-19 15:52:26 +00:00
Andrew Gaul 4daa8d1de6 Correct inf typo
Reviewers: krasimir

Reviewed By: krasimir

Subscribers: Jim, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D57732
2019-12-13 11:02:40 +08:00
Mitchell Balan 26748a321e [clang-format] Add new option to add spaces around conditions
Summary:
This diff adds a new option SpacesAroundConditions that inserts spaces inside the braces for conditional statements.

Reviewers: klimek, owenpan, mitchell-stellar, MyDeveloperDay

Patch by: timwoj

Subscribers: rsmmr, cfe-commits

Tags: clang, clang-format

Differential Revision: https://reviews.llvm.org/D68346
2019-12-03 12:20:54 -05:00
mydeveloperday a4a7c1259e [clang-format] Add SpaceBeforeBrackets
Summary: Adds a new option SpaceBeforeBrackets to add spaces before brackets (i.e. int a[23]; -> int a [23];)  This is present as an option in the Visual Studio C++ code formatting settings, but there was no matching setting in clang-format.

Reviewers: djasper, MyDeveloperDay, mitchell-stellar

Reviewed By: MyDeveloperDay

Subscribers: llvm-commits, cfe-commits, klimek

Patch by: Anteru

Tags: #clang, #clang-format, #llvm

Differential Revision: https://reviews.llvm.org/D6920
2019-11-16 11:54:21 +00:00
mydeveloperday 335ac2eb66 Allow additional file suffixes/extensions considered as source in main include grouping
Summary:
By additional regex match, grouping of main include can be enabled in files that are not normally considered as a C/C++ source code.
For example, this might be useful in templated code, where template implementations are being held in *Impl.hpp files.
On the occassion, 'assume-filename' option description was reworded as it was misleading. It has nothing to do with `style=file` option and it does not influence sourced style filename.

Reviewers: rsmith, ioeric, krasimir, sylvestre.ledru, MyDeveloperDay

Reviewed By: MyDeveloperDay

Subscribers: MyDeveloperDay, cfe-commits

Patch by:  furdyna

Tags: #clang

Differential Revision: https://reviews.llvm.org/D67750
2019-11-12 21:26:52 +00:00
paul_hoad 860ee4f3eb [clang-format] NFC allow Format.h to be clang-formatted but still maintain the same doc layout in ClangFormatStyleOptions.rst
Summary:
Format.h is used to generate ClangFormatStyleOptions.rst, the layout of the comments is critical to the rst file. Accidentally clang-formatting Format.h can lead to the .rst changing.

This revision simply add // clang-format off/on statement around the areas who formatting needs to be maintained, mainly around the options that are related to what happens when the line breaks due to `ColumnLimit` (which is what is happening to the comment)

This allows Format.h to be clang-formatted without causing a change in the documentation when dump_format_style.py is rerun, which is also part of the revision.

Reviewers: mitchell-stellar, klimek, sammccall, owenpan

Reviewed By: mitchell-stellar

Subscribers: cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D69951
2019-11-08 21:14:29 +00:00
paul_hoad eb00839c6e [clang-format] Ensure dump_format_style.py can generate ClangFormatStyleOptions.rst without manual intervention
Summary:
This revision is the last in a series of revisions to return `clang/doc/tools/dump_format_style.py` to be being able to parse Format.h without needing to manually merge the ClangFormatStyleOptions.rst file.

The final modification to dump_format_style.py is needed following the addition of a  nested enumeration inside a nested structure following the introduction of {D68296}

Prior  related revisions will allow for a fully clang-formatted `clang/include/clang/Format/Format.h` to once again be used at the source.
{D69951}
{D69433}
{D69404}

Reviewers: mitchell-stellar, klimek, sammccall, owenpan

Reviewed By: mitchell-stellar

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D70003
2019-11-08 14:40:36 +00:00
paulhoad eadb65f273 [clang-format] [NFC] update the documentation in Format.h to allow dump_format_style.py to get a little closer to being correct. (part 2)
Summary:
a change {D67541} cause LanguageStandard to now be subtly different from all other clang-format options, in that the Enum value (less the prefix) is not always allowed as valid as the configuration option.

This caused the ClangFormatStyleOptions.rst and the Format.h to diverge so that the ClangFormatStyleOptions.rst could no longer be generated from the Format.h using dump_format_stlye.py

This fix tried to remedy that:

1) by allowing an additional comment (in Format.h) after the enum to be used as the `in configuration ( XXXX )`  text, and changing the dump_format_style.py to support that.

This makes the following code:

```
enum {
...
LS_Cpp03, // c++03
LS_Cpp11, // c++11
...
};
```

would render as:

```* ``LS_Cpp03`` (in configuration: ``c++03``)
* ``LS_Cpp11`` (in configuration: ``c++11``)
```

And we also  move the deprecated alias into the text of the enum (otherwise it won't be added at the end as an option)

This patch includes a couple of other whitespace changes which help bring Format.h and ClangFormatStyleOptions.rst almost back into line and regeneratable...  (there is still one more)

Reviewers: klimek, mitchell-stellar, sammccall

Reviewed By: mitchell-stellar, sammccall

Subscribers: mrexodia, cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D69433
2019-11-06 20:03:05 +00:00
paulhoad 23b7836415 [clang-format] update documentation
Summary:
  - Added example code for BreakStringLiterals;

Reviewers: MyDeveloperDay

Reviewed By: MyDeveloperDay

Patch By: mrexodia

Subscribers: cfe-commits, MyDeveloperDay

Tags: #clang-tools-extra, #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D31574
2019-10-24 21:10:13 +01:00
Mitchell Balan 77c9736ef3 [NFC] Reverting changes from test commit.
llvm commit access test succeeded.

llvm-svn: 374175
2019-10-09 15:12:22 +00:00
Mitchell Balan 791b0e4160 [NFC] Test commit.
Testing llvm commit access only.

llvm-svn: 374174
2019-10-09 15:11:34 +00:00
Paul Hoad c209598268 [clang-format][docs] Fix the Google C++ and Chromium style guide URLs
Summary: The Google C++ and Chromium style guides are broken in the clang-format docs. This patch updates them.

Reviewers: djasper, MyDeveloperDay

Reviewed By: MyDeveloperDay

Subscribers: cfe-commits

Tags: #clang

Patch by: m4tx

Differential Revision: https://reviews.llvm.org/D61256

llvm-svn: 373844
2019-10-06 09:37:58 +00:00
Paul Hoad 375a84bb75 [clang-format] SpacesInSquareBrackets should affect lambdas with parameters too
Summary:
This patch makes the `SpacesInSquareBrackets` setting also apply to C++ lambdas with parameters.

Looking through the revision history, it appears support for only array brackets was added, and lambda brackets were ignored. Therefore, I am inclined to think it was simply an omission, rather than a deliberate choice.

See https://bugs.llvm.org/show_bug.cgi?id=17887 and https://reviews.llvm.org/D4944.

Reviewers: MyDeveloperDay, reuk, owenpan

Reviewed By: MyDeveloperDay

Subscribers: cfe-commits

Patch by: mitchell-stellar

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D68473

llvm-svn: 373821
2019-10-05 09:55:23 +00:00
Sam McCall b3cc321cb2 [Format] Fix docs after r373439
llvm-svn: 373724
2019-10-04 09:52:54 +00:00
Paul Hoad fb13e65acf [clang-format] Add ability to wrap braces after multi-line control statements
Summary:
Change the BraceWrappingFlags' AfterControlStatement from a bool to an enum with three values:

* "Never": This is the default, and does not do any brace wrapping after control statements.
* "MultiLine": This only wraps braces after multi-line control statements (this really only happens when a ColumnLimit is specified).
* "Always": This always wraps braces after control statements.

The first and last options are backwards-compatible with "false" and "true", respectively.

The new "MultiLine" option is useful for when a wrapped control statement's indentation matches the subsequent block's indentation. It makes it easier to see at a glance where the control statement ends and where the block's code begins. For example:

```
if (
  foo
  && bar )
{
  baz();
}
```

vs.

```
if (
  foo
  && bar ) {
  baz();
}
```

Short control statements (1 line) do not wrap the brace to the next line, e.g.

```
if (foo) {
  bar();
} else {
  baz();
}
```

Reviewers: sammccall, owenpan, reuk, MyDeveloperDay, klimek

Reviewed By: MyDeveloperDay

Subscribers: MyDeveloperDay, cfe-commits

Patch By: mitchell-stellar

Tags: #clang-format, #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D68296

llvm-svn: 373647
2019-10-03 18:42:31 +00:00
Sam McCall e503256790 [ClangFormat] Future-proof Standard option, allow floating or pinning to arbitrary lang version
Summary:
The historical context:
- clang-format was written when C++11 was current,
  and the main language-version concern was >> vs > > template-closers.
  An option was added to allow selection of the 03/11 behavior, or auto-detection.
- there was no option to choose simply "latest standard" so anyone who didn't
  ever want 03 behavior or auto-detection specified Cpp11.
- In r185149 this option started to affect lexer mode.
- no options were added to cover c++14, as parsing/formatting
  didn't change that much. The usage of Cpp11 to mean "latest" became
  codified e.g. in r206263
- c++17 added some new constructs. These were mostly backwards-compatible and so
  not used in old programs, so having no way to turn them off was OK.
- c++20 added some new constructs and keywords (e.g. co_*) that changed the
  meaning of existing programs, and people started to complain that
  the c++20 parsing couldn't be turned off.

New plan:
 - Default ('Auto') behavior remains unchanged: parse as latest, format
   template-closers based on input.
 - Add new 'Latest' option that more clearly expresses the intent "use
   modern features" that many projects have chosen for their .clang-format files.
 - Allow pinning to *any* language version, using the same name as clang -std:
   c++03, c++11, c++14 etc. These set precise lexer options, and any
   clang-format code depending on these can use a >= check.
 - For backwards compatibility, `Cpp11` is an alias for `Latest`, not `c++11`.
   This matches the historical documented semantics of this option.
   This spelling (and `Cpp03`) are deprecated.

Reviewers: klimek, modocache

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D67541

llvm-svn: 373439
2019-10-02 09:50:40 +00:00
Paul Hoad 52e44b1423 [clang-format] Modified SortIncludes and IncludeCategories to priority for sorting #includes within the Group Category.
Summary:
This new Style rule is made as a part of adding support for NetBSD KNF in clang-format. NetBSD have it's own priority of includes which should be followed while formatting NetBSD code. This style sorts the Cpp Includes according to the priorities of NetBSD, as mentioned in the [Style Guide](http://cvsweb.netbsd.org/bsdweb.cgi/src/share/misc/style?rev=HEAD&content-type=text/x-cvsweb-markup)
 The working of this Style rule shown below:

**Configuration:**
This revision introduces a new field under IncludeCategories named `SortPriority` which defines the priority of ordering the `#includes` and the `Priority` will define the categories for grouping the `#include blocks`.

Reviewers: cfe-commits, mgorny, christos, MyDeveloperDay

Reviewed By: MyDeveloperDay

Subscribers: lebedev.ri, rdwampler, christos, mgorny, krytarowski

Patch By: Manikishan

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D64695

llvm-svn: 372919
2019-09-25 20:33:01 +00:00
Paul Hoad a506ed256a Clang-format: Add Whitesmiths indentation style
Summary:
This patch adds support for the Whitesmiths indentation style to clang-format. It’s an update to a patch submitted in 2015 (D6833), but reworks it to use the newer API.

There are still some issues with this patch, primarily around `switch` and `case` support. The added unit test won’t currently pass because of the remaining issues.

Reviewers: mboehme, MyDeveloperDay, djasper

Reviewed By: MyDeveloperDay

Subscribers: krasimir, MyDeveloperDay, echristo, cfe-commits

Patch By: @timwoj (Tim Wojtulewicz)

Tags: #clang

Differential Revision: https://reviews.llvm.org/D67627

llvm-svn: 372497
2019-09-22 12:00:34 +00:00
Paul Hoad 3867a2d510 [clang-format] Add new style option IndentGotoLabels
Summary:
This option determines whether goto labels are indented according to scope. Setting this option to false causes goto labels to be flushed to the left.
This is mostly copied from [[ http://lists.llvm.org/pipermail/cfe-dev/2015-September/045014.html | this patch ]] submitted by Christian Neukirchen that didn't make its way into trunk.

```
     true:                                  false:
     int f() {                      vs.     int f() {
       if (foo()) {                           if (foo()) {
       label1:                              label1:
         bar();                                 bar();
       }                                      }
     label2:                                label2:
       return 1;                              return 1;
     }                                      }
```

Reviewers: klimek, MyDeveloperDay

Reviewed By: MyDeveloperDay

Subscribers: cfe-commits

Tags: #clang, #clang-tools-extra

Patch by: tetsuo-cpp

Differential Revision: https://reviews.llvm.org/D67037

llvm-svn: 371719
2019-09-12 10:07:14 +00:00
Owen Pan 37860d524e [clang-format] Fix a bug that joins template closer and =
Also fixes the documentation for SpaceBeforeAssignmentOperators.

See discussions at https://reviews.llvm.org/D66332

Differential Revision: https://reviews.llvm.org/D66384

llvm-svn: 369214
2019-08-18 18:51:39 +00:00
Owen Pan 10234da71d [clang-format] Expand AllowShortBlocksOnASingleLine for WebKit
See PR40840

Differential Revision: https://reviews.llvm.org/D66059

llvm-svn: 368539
2019-08-11 17:48:36 +00:00
Owen Pan db4ad3603a [clang-format] Add SpaceInEmptyBlock option for WebKit
See PR40840

Differential Revision: https://reviews.llvm.org/D65925

llvm-svn: 368507
2019-08-10 07:51:21 +00:00
Rafael Stahl 0e074fa0fc doc: Fix Google C++ Style Guide link.
llvm-svn: 367219
2019-07-29 11:00:23 +00:00
Sam McCall 04ee232ff2 clang-format: Add new style option AlignConsecutiveMacros
This option behaves similarly to AlignConsecutiveDeclarations and
AlignConsecutiveAssignments, aligning the assignment of C/C++
preprocessor macros on consecutive lines.

I've worked in many projects (embedded, mostly) where header files full
of large, well-aligned "#define" blocks are a common pattern. We
normally avoid using clang-format on these files, since it ruins any
existing alignment in said blocks. This style option will align "simple"
PP macros (no parameters) and PP macros with parameter lists on
consecutive lines.

Related Bugzilla entry (thanks mcuddie):
https://llvm.org/bugs/show_bug.cgi?id=20637

Patch by Nick Renieris (VelocityRa)!

Differential Revision: https://reviews.llvm.org/D28462

llvm-svn: 364938
2019-07-02 15:53:14 +00:00
Francois Ferrand e8a301f87f clang-format: better handle namespace macros
Summary:
Other macros are used to declare namespaces, and should thus be handled
similarly. This is the case for crpcut's TESTSUITE macro, or for
unittest-cpp's SUITE macro:

      TESTSUITE(Foo) {
      TEST(MyFirstTest) {
        assert(0);
      }
      } // TESTSUITE(Foo)

This patch deals with this cases by introducing a new option to specify
lists of namespace macros. Internally, it re-uses the system already in
place for foreach and statement macros, to ensure there is no impact on
performance.

Reviewers: krasimir, djasper, klimek

Reviewed By: klimek

Subscribers: acoomans, cfe-commits, klimek

Tags: #clang

Differential Revision: https://reviews.llvm.org/D37813

llvm-svn: 362740
2019-06-06 20:06:23 +00:00
Jan Korous a3701caad8 [clang-format][NFC] Fix BS_Allman style example in the header docs are generated from
Differential Revision: https://reviews.llvm.org/D61729

llvm-svn: 362646
2019-06-05 20:59:48 +00:00
Francois Ferrand c5227a1f53 [clang-format] Allow configuring list of function-like macros that resolve to a type
Summary:
Adds a `TypenameMacros` configuration option that causes certain identifiers to be handled in a way similar to `typeof()`.

This is enough to:
- Prevent misinterpreting declarations of pointers to such types as expressions (`STACK_OF(int) * foo` -> `STACK_OF(int) *foo`),
- Avoid surprising line breaks in variable/struct field declarations (`STACK_OF(int)\nfoo;` -> `STACK_OF(int) foo;`, see https://bugs.llvm.org/show_bug.cgi?id=30353).

Reviewers: Typz, krasimir, djasper

Reviewed By: Typz

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D57184

llvm-svn: 361986
2019-05-29 16:30:47 +00:00
Owen Pan d7f287f5b1 [clang-format] Fix documentation for FixNamespaceComments
Fixes PR40409

Differential Revision: https://reviews.llvm.org/D61174

llvm-svn: 359280
2019-04-26 07:05:47 +00:00
Owen Pan 806d5741aa [clang-format] Add AfterCaseLabel to BraceWrapping
Fixes PR38686

> llvm-svn: 52527

llvm-svn: 357957
2019-04-08 23:36:25 +00:00
Reuben Thomas 91f60b4495 [clang-format] Optionally insert a space after unary ! operator
llvm-svn: 357908
2019-04-08 12:54:48 +00:00
Ronald Wampler a83e2dbb1e [clang-format] Add style option AllowShortLambdasOnASingleLine
Summary:
This option `AllowShortLambdasOnASingleLine` similar to the other `AllowShort*` options, but applied to C++ lambdas.

Reviewers: djasper, klimek

Reviewed By: klimek

Subscribers: MyDeveloperDay, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D57687

llvm-svn: 357027
2019-03-26 20:18:14 +00:00
Paul Hoad c6deae4521 Clang-format: add finer-grained options for putting all arguments on one line
Summary:
Add two new options,
AllowAllArgumentsOnNextLine and
AllowAllConstructorInitializersOnNextLine.  These mirror the existing
AllowAllParametersOfDeclarationOnNextLine and allow me to support an
internal style guide where I work.  I think this would be generally
useful, some have asked for it on stackoverflow:

https://stackoverflow.com/questions/30057534/clang-format-binpackarguments-not-working-as-expected

https://stackoverflow.com/questions/38635106/clang-format-how-to-prevent-all-function-arguments-on-next-line

Reviewers: djasper, krasimir, MyDeveloperDay

Reviewed By: MyDeveloperDay

Subscribers: jkorous, MyDeveloperDay, aol-nnov, lebedev.ri, uohcsemaj, cfe-commits, klimek

Differential Revision: https://reviews.llvm.org/D40988

Patch By: russellmcc  (Russell McClellan)

llvm-svn: 356834
2019-03-23 14:37:58 +00:00
Paul Hoad cbb726d0c5 [clang-format] Add basic support for formatting C# files
Summary:

This revision adds basic support for formatting C# files with clang-format, I know the barrier to entry is high here  so I'm sending this revision in to test the water as to whether this might be something we'd consider landing.

Tracking in Bugzilla as:
https://bugs.llvm.org/show_bug.cgi?id=40850

Justification:
C# code just looks ugly in comparison to the C++ code in our source tree which is clang-formatted.

I've struggled with Visual Studio reformatting to get a clean and consistent style, I want to format our C# code on saving like I do now for C++ and i want it to have the same style as defined in our .clang-format file, so it consistent as it can be with C++.  (Braces/Breaking/Spaces/Indent etc..)

Using clang format without this patch leaves the code in a bad state, sometimes when the BreakStringLiterals is set, it  fails to compile.

Mostly the C# is similar to Java, except instead of JavaAnnotations I try to reuse the TT_AttributeSquare.

Almost the most valuable portion is to have a new Language in order to partition the configuration for C# within a common .clang-format file, with the auto detection on the .cs extension. But there are other C# specific styles that could be added later if this is accepted. in particular how  `{ set;get }` is formatted.

Reviewers: djasper, klimek, krasimir, benhamilton, JonasToth

Reviewed By: klimek

Subscribers: llvm-commits, mgorny, jdoerfert, cfe-commits

Tags: #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D58404

llvm-svn: 356662
2019-03-21 13:09:22 +00:00