If there are possible column formats, but they weren't selected because
they don't fit within remaining characters for the current path then
applying severe penalty to induce column layout by selection of a
different path seems fair.
But if due to style configuration or what the input code is, there are
no possible column formats, different paths aren't going to have column
layouts. Seems wrong to apply the severe penalty to induce column
layouts if there are none available.
It just causes selection of sub-optimal paths, e.g. get bad formatting
when brace initializers are used inside lambda bodies.
Fixes#56350
This restores a subset of functionality that was forego in
d68826dfbd987377ef6771d40c1d984f09ee3b9e.
Streaming multiple string literals is rare enough in practice, hence
that change makes sense in general. But it seems people were
incidentally relying on this for having line breaks after string
literals that ended with `\n`.
This patch tries to restore that behavior to prevent regressions in the
upcoming LLVM release, until we can implement some configuration based
approach as proposed in https://github.com/llvm/llvm-project/pull/69859.
We have found that 199fc973ced20016b04ba540cf63a1d4914fa513 regresses
formatting of our codebases because we do not properly configure the
names of attribute macros.
`GUARDED_BY` and `ABSL_GUARDED_BY` are very commoon in Google codebases
so it is reasonable to include them by default to avoid the need for
extra configuration in every Google repository.
This would also fix the overlapping replacements below:
```
$ clang-format
a(
#else
#endif
) = []() {
)}
The new replacement overlaps with an existing replacement.
New replacement: <stdin>: 38:+7:"
"
Existing replacement: <stdin>: 38:+7:" "
```
Fixed#73487.
Function and variable names are not detected when there is a
__attribute__((x)) preceding the name.
Fixes#64137.
Differential Revision: https://reviews.llvm.org/D156370
This patch addresses some examples of bad formatting in Clang. The following commit contains only changes suggested by clang-format: 21689b56d1.
I believe it's a net negative on readability, with a couple of particularly bad cases. Highlights:
```diff
- [[clang::preferred_type(bool)]]
- mutable unsigned CachedLocalOrUnnamed : 1;
+ [[clang::preferred_type(bool)]] mutable unsigned CachedLocalOrUnnamed : 1;
```
```diff
- [[clang::preferred_type(TypeDependence)]]
- unsigned Dependence : llvm::BitWidth<TypeDependence>;
+ [[clang::preferred_type(TypeDependence)]] unsigned Dependence
+ : llvm::BitWidth<TypeDependence>;
```
```diff
- [[clang::preferred_type(ExceptionSpecificationType)]]
- unsigned ExceptionSpecType : 4;
+ [[clang::preferred_type(
+ ExceptionSpecificationType)]] unsigned ExceptionSpecType : 4;
```
Style guides doesn't appear to have an opinion on this matter.
clang-format brace wrapping did not take requires into consideration,
compound requirements will be affected by BraceWrapping.AfterFunction.
Closes#59412.
Differential Revision: https://reviews.llvm.org/D139834
Add AfterPlacementNew option to SpaceBeforeParensOptions to have more
control on placement new expressions.
Fixes#41501
Relates to #54703
Differential Revision: https://reviews.llvm.org/D127270
There are two parts to this fix:
- Annotate the paren after an AttributeMacro as an AttributeLParen.
- Treat an AttributeMacro-without-paren the same as one with a paren.
I added a new test-case to differentiate a macro that is or is-not an
AttributeMacro; also handled whether ColumnLimit is set to infinite (0) or a
finite value, as part of this patch is in ContinuationIndenter.
Closes#68722.
Differential Revision: https://reviews.llvm.org/D145262
Reland 6a621ed8e4cb which failed on Windows but not macOS.
The failures were caused by moving the annotation of the children from the
top to the bottom of TokenAnnotator::annotate(), resulting in invalid lines
including incomplete ones being skipped.
After annotating constructors/destructors as FunctionDeclarationName in
commit 08630512088, we have seen several issues because ctors/dtors had
been treated differently than functions in aligning, wrapping, and
indenting.
This patch annotates ctors/dtors as CtorDtorDeclName instead and would
effectively revert commit 0468fa07f87f, which is obsolete now.
Fixed#67903.
Fixed#67907.
Don't remove the outermost parentheses surrounding a return statement
expression when inside a function/lambda that has the decltype(auto)
return type.
Fixed#67892.
By default, OuterScope aligns lambdas to the beginning of the current
line. This makes sense for most types of statements within code blocks
but leads to unappealing and misleading indentation for lambdas within
constructor initializers.
Avoid unnecessarily aggressive line-breaking when using
"LambdaBodyIndentation: OuterScope" with argument bin-packing.
Differential Revision: https://reviews.llvm.org/D148131
Fixing the clang-format crash with the segmentation fault error when
formatting code with nested namespaces.
Fixes#64701.
Differential Revision: https://reviews.llvm.org/D158363
Currently AlignArrayOfStructures=Left is hard coding setting Spaces to
0 for the token following the initial opening brace, but not touching
Spaces for the subsequent lines, which leads to the array being
misaligned. Additionally, it's not adding a space before the trailing
} which is generally done when Cpp11BracedListStyle=false.
I'm not exactly sure why this function needs to override the Spaces as
it seems to generally already be set to either 0 or 1 according to
the other formatting settings, but I'm going with an explicit fix where
I just force the padding to 1 when Cpp11BracedListStyle=false.
AlignArrayOfStructures=Right doesn't have any alignment problems, but
isn't adding the expected padding around the braces either, so I'm
giving that the same treatment.
Fixes#57611.
Differential Revision: https://reviews.llvm.org/D158795
Replaces some 600 EXPECT_EQ() to verifyFormat() or verifyNoChange() in
FormatTest.cpp because the former neither checks stability of formatting
nor tests formatting C++ as Objective C.
Also marks dozens of unstable test cases with FIXME comments.
Differential Revision: https://reviews.llvm.org/D159051
(0e63f1aacc00 was reverted by 7590b7657004 due to a crash.)
Annotate constructor/destructor names as FunctionDeclarationName.
Fixes#63046.
Differential Revision: https://reviews.llvm.org/D157963
Removes some 500 newlines (\n and \r\n) at the end of test cases in
FormatTest.cpp.
Also changes a few verifyFormat() to verifyNoChange() in tests
InsertNewlineAtEOF and WhitespaceSensitiveMacros as messUp() removes
trailing newlines as well.
Differential Revision: https://reviews.llvm.org/D158805