Actual regression was introduced in r272668. This revision fixes JS script, but
also regress Cpp case. It manifests with spaces added when template is followed
with array. Bug 30527 mentions case of array as a nested template type
(foo<bar<baz>[]>). Fix is to detect such case and to prevent treating it as
array initialization, but as a subscript case. However, before r272668, this
case was treated simple because we were detecting it as a StartsObjCMethodExpr.
Same was true for other similar case - array of templates (foo<int>[]). This
patch tries to address two problems: 1) fixing regression 2) making sure both
cases (array as a nested type, array of templates) which were entering
StartsObjCMethodExpr branch are handled now appropriately.
https://reviews.llvm.org/D26163
Patch from Branko Kokanovic <branko@kokanovic.org>!
llvm-svn: 286507
Output generated by option -ast-print looks like C/C++ code, and it
really is for plain C. For C++ the produced output was not valid C++
code, but the differences were small. With this change the output
is fixed and can be compiled. Tests are changed so that output produced
by -ast-print is compiled again with the same flags and both outputs are
compared.
Option -ast-print is extensively used in clang tests but it itself
was tested poorly, existing tests only checked that compiler did not
crash. There are unit tests in file DeclPrinterTest.cpp, but they test
only terse output mode.
Differential Revision: https://reviews.llvm.org/D26452
llvm-svn: 286439
Summary:
This provides a better interface for clang-tidy and encapsulates the knowledge
about experimental checkers instead of leaving this to the clients.
Reviewers: zaks.anna
Subscribers: a.sidorin, NoQ, dcoughlin, cfe-commits
Differential Revision: https://reviews.llvm.org/D26310
llvm-svn: 286218
Summary:
The current version does not deduplicate equivalent file paths correctly.
For example, a relative path and an absolute path are considered inequivalent.
Comparing FileEnry addresses these issues.
Reviewers: djasper
Subscribers: alexshap, klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D26288
llvm-svn: 286096
Summary:
During clang-format source lexing >> and << operators are split and
treated as two less/greater operators but column position of following
tokens was not adjusted accordingly.
Fixes PR26887
Patch by Paweł Żukowski.
Reviewers: djasper
Subscribers: malcolm.parsons, mprobst, klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D25439
llvm-svn: 285934
Reasoning:
- ExpressionParser uses a lot of stack for these, bad in some environments.
- Our formatting algorithm is N^3 and gets really slow.
- The resulting formatting is unlikely to be any good.
- This is probably generated code we're formatting by accident.
We treat these as unparseable, and signal incomplete formatting. 50 is
an arbitrary number, I've only seen real problems from ~150 levels.
Patch by Sam McCall. Thank you.
llvm-svn: 285570
Summary:
The matcher
varDecl(hasDescendant(
callExpr(hasDeclaration(functionDecl(unless(isNoThrow()))))))
didn't match calls from default arguments because the expression
for a CXXDefaultArgExpr was not visited.
Reviewers: klimek, jdennett, alexfh, aaron.ballman
Subscribers: aaron.ballman, cfe-commits
Differential Revision: https://reviews.llvm.org/D25992
llvm-svn: 285239
Summary:
clang-tidy's modernize-use-auto check uses the SourceRange of a
TypeLoc when replacing the type with auto.
This was producing the wrong result for multi-token builtin types
like long long:
-long long *ll = new long long();
+auto long *ll = new long long();
Reviewers: alexfh, hokein, rsmith, Prazek, aaron.ballman
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D25363
llvm-svn: 284885
Summary:
Previously, automatic semicolon insertion would add an unwrapped line
when a template string contained a line break.
var x = `foo${
bar}`;
Would be formatted with `bar...` on a separate line and no indent.
Reviewers: djasper
Subscribers: cfe-commits, klimek
Differential Revision: https://reviews.llvm.org/D25675
llvm-svn: 284807
Summary:
Remove colon and commas after replacing constructor body with = default.
Fix annotation of TT_CtorInitializerColon when preceded by a comment.
Reviewers: djasper
Subscribers: cfe-commits, klimek
Differential Revision: https://reviews.llvm.org/D25768
llvm-svn: 284732
Summary:
If there are multiple <File, Replacements> pairs with the same file
path after removing dots, we only keep one pair (with path after dots being
removed) and discard the rest.
Reviewers: djasper
Subscribers: klimek, hokein, bkramer, cfe-commits
Differential Revision: https://reviews.llvm.org/D25565
llvm-svn: 284219
Summary:
append newline after code when inserting new headers at the end of the
code which does not end with newline.
Reviewers: djasper
Subscribers: cfe-commits, klimek
Differential Revision: https://reviews.llvm.org/D21026
llvm-svn: 283330
Summary:
Now two replacements are considered order-independent if applying them in
either order produces the same result. These include (but not restricted
to) replacements that:
- don't overlap (being directly adjacent is fine) and
- are overlapping deletions.
- are insertions at the same offset and applying them in either order
has the same effect, i.e. X + Y = Y + X if one inserts text X and the
other inserts text Y.
Discussion about this design can be found in D24717
Reviewers: djasper, klimek
Subscribers: omtcyfz, cfe-commits
Differential Revision: https://reviews.llvm.org/D24800
llvm-svn: 282577
Fixes the following:
BOOL (^aaa)(void) = ^BOOL {
};
The first BOOL's token was getting set to TT_FunctionAnnotationRParen
incorrectly, which was causing an unexpected newline after (^aaa). This
was introduced in r245846.
Patch by Kent Sutherland, thank you!
llvm-svn: 282448
Summary:
- If a replacement has offset UINT_MAX, length 0, and a replacement text
that is an #include directive, this will insert the #include into the
correct block in the \p Code.
- If a replacement has offset UINT_MAX, length 1, and a replacement text
that is the name of the header to be removed, the header will be removed
from \p Code if it exists.
Reviewers: djasper
Subscribers: cfe-commits, klimek
Differential Revision: https://reviews.llvm.org/D24829
llvm-svn: 282253
Summary:
Diff to r281457:
- added a test case `CalculateRangesOfInsertionAroundReplacement`.
Reviewers: djasper
Subscribers: cfe-commits, klimek
Differential Revision: https://reviews.llvm.org/D24606
llvm-svn: 281891
Summary:
Previously, clang-format would always insert an additional line break after the
import block if the main body started with a comment, due to loosing track of
the first non-import line.
Reviewers: djasper
Subscribers: cfe-commits, klimek
Differential Revision: https://reviews.llvm.org/D24708
llvm-svn: 281888
Summary:
`// taze: ... from ...` comments are used help tools where a
specific global symbol comes from.
Before:
// taze: many, different, symbols from
// 'some_long_location_here'
After:
// taze: many, different, symbols from 'some_long_location_here'
Reviewers: djasper
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D24477
llvm-svn: 281857
Summary:
Before when a semicolon was missing after a boolean literal:
a = true
return 1;
clang-format would parse this as one line and format as:
a = true return 1;
It turns out that C++ does not consider `true` and `false` to be literals, we
have to check for that explicitly.
Reviewers: djasper
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D24574
llvm-svn: 281856
Summary:
Extend `tooling::Replacements::add()` to support adding order-independent replacements.
Two replacements are considered order-independent if one of the following conditions is true:
- They do not overlap. (This is already supported.)
- One replacement is insertion, and the other is a replacement with
length > 0, and the insertion is adjecent to but not contained in the
other replacement. In this case, the replacement should always change
the original code instead of the inserted text.
Reviewers: klimek, djasper
Subscribers: cfe-commits, klimek
Differential Revision: https://reviews.llvm.org/D24515
llvm-svn: 281457