summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/TokenAnnotator.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [clang-format] [PR45357] Fix issue found with operator spacingmydeveloperday2020-05-071-0/+6
| | | | | | | | | | | | | | | | | | | Summary: This is a tentative fix for https://bugs.llvm.org/show_bug.cgi?id=45357 Spaces seem to be introduced between * and * due to changes brought in for {D69573} Reviewers: sylvestre.ledru, mitchell-stellar, sammccall, Abpostelnicu, krasimir, jbcoe Reviewed By: Abpostelnicu Subscribers: tstellar, hans, Abpostelnicu, cfe-commits Tags: #clang, #clang-format Differential Revision: https://reviews.llvm.org/D78879 (cherry picked from commit b01dca50085768f1f1a5ad21a685906d48c38816)
* clang-format: Fix pointer alignment for overloaded operators (PR45107)Hans Wennborg2020-05-071-14/+32
| | | | | | | | | | | | | | | | | | This fixes a regression from D69573 which broke the following example: $ echo 'operator C<T>*();' | bin/clang-format --style=Chromium operator C<T> *(); (There should be no space before the asterisk.) It seems the problem is in TokenAnnotator::spaceRequiredBetween(), which only looked at the token to the left of the * to see if it was a type or not. That code only handled simple types or identifiers, not templates or qualified types. This patch addresses that. Differential revision: https://reviews.llvm.org/D76850 (cherry picked from commit eb85e90350e93a64279139e7eca9ca40c8fbf5eb)
* clang-format: fix spacing in `operator const char*()`Krasimir Georgiev2020-03-021-4/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Revision a75f8d98d7ac9e557b238a229a9a2647c71feed1 fixed spacing for operators, but caused the const and non-const versions to diverge: ``` // With Style.PointerAlignment = FormatStyle::PAS_Left: struct A { operator char*() { return ""; } operator const char *() const { return ""; } }; ``` The code was checking if the type specifier was directly preceded by `operator`. However there could be comments and `const/volatile` in between. Reviewers: mprobst Reviewed By: mprobst Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D72911 (cherry picked from commit 33463cfba2be7c8d6c08e666123cc34f114a1f3e)
* [clang-format] Expand the SpacesAroundConditions option to include catch ↵mydeveloperday2020-01-211-1/+1
| | | | | | | | | | | | | | statements Summary: This diff expands the SpacesAroundConditions option added in D68346 to include adding spaces to catch statements. Reviewed By: MyDeveloperDay Patch by: timwoj Differential Revision: https://reviews.llvm.org/D72793 (cherry picked from commit ea2be452542c81b04621e26c0d5e83be565f07e2)
* Fix warning on extra ';'. NFC.Michael Liao2019-12-031-1/+1
|
* [clang-format] Add new option to add spaces around conditionsMitchell Balan2019-12-031-1/+18
| | | | | | | | | | | | | | | 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
* [Format] Add format check for coroutine keywords with negative numbersBrian Gesiak2019-11-301-1/+2
| | | | | | | | | | | | | | | | | | Summary: As a followup to D69144, this diff fixes the coroutine keyword spacing for co_yield / co_returning negative numbers. Reviewers: modocache, sammccall, Quuxplusone Reviewed By: modocache Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69180 Patch by Jonathan Thomas (jonathoma)!
* [clang-format] fix regression in middle pointer alignmentmydeveloperday2019-11-161-1/+1
| | | | | | | | | | | | | | | | | | Summary: a75f8d98d7ac introduced a regression with Middle pointer alignment, which this patch fixes. Reviewers: MyDeveloperDay, klimek, sammccall Reviewed By: MyDeveloperDay, sammccall Subscribers: cfe-commits, merge_guards_bot Patch by: Typz Tags: #clang Differential Revision: https://reviews.llvm.org/D70305
* [clang-format] Add SpaceBeforeBracketsmydeveloperday2019-11-161-1/+3
| | | | | | | | | | | | | | | | 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
* [clang-format] Fixed edge-case with SpacesInSquareBrackets with trailing ↵Mitchell Balan2019-11-141-3/+7
| | | | | | | | | | | | | | | | | | | bare "&" lambda capture. Summary: Lambda captures allow for a lone `&` capture, so `&]` needs to be properly handled. `int foo = [& ]() {}` is fixed to give `int foo = [ & ]() {}` Reviewers: MyDeveloperDay Reviewed by: MyDeveloperDay Subscribers: cfe-commits Tags: #clang, #clang-format Differential Revision: https://reviews.llvm.org/D70249
* [clang-format] [PR36294] AlwaysBreakAfterReturnType works incorrectly for ↵mydeveloperday2019-11-121-6/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | some operator functions Summary: https://bugs.llvm.org/show_bug.cgi?id=36294 Addressing bug related to returning after return type not being honoured for some operator types. ``` $ bin/clang-format --style="{BasedOnStyle: llvm, AlwaysBreakAfterReturnType: TopLevelDefinitions}" /tmp/foo.cpp class Foo { public: bool operator!() const; bool operator<(Foo const &) const; bool operator*() const; bool operator->() const; bool operator+() const; bool operator-() const; bool f() const; }; bool Foo::operator!() const { return true; } bool Foo::operator<(Foo const &) const { return true; } bool Foo::operator*() const { return true; } bool Foo::operator->() const { return true; } bool Foo::operator+() const { return true; } bool Foo::operator-() const { return true; } bool Foo::f() const { return true; } ``` Reviewers: mitchell-stellar, klimek, owenpan, sammccall, rianquinn Reviewed By: sammccall Subscribers: merge_guards_bot, cfe-commits Tags: #clang-format, #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D69573
* [clang-format] [PR35518] C++17 deduction guides are wrongly formattedpaulhoad2019-11-061-0/+68
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: see https://bugs.llvm.org/show_bug.cgi?id=35518 clang-format removes spaces around deduction guides but not trailing return types, make the consistent ``` template <typename T> S(T)->S<T>; auto f(int, int) -> double; ``` becomes ``` template <typename T> S(T) -> S<T>; auto f(int, int) -> double; ``` Reviewers: klimek, mitchell-stellar, owenpan, sammccall, lichray, curdeius, KyrBoh Reviewed By: curdeius Subscribers: merge_guards_bot, hans, lichray, cfe-commits Tags: #clang-format, #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D69577
* [clang-format] Fix SpacesInSquareBrackets for Lambdas with Initial "&ref" ↵Mitchell Balan2019-10-311-1/+1
| | | | | | | | | | | | | | | | | | | Parameter Summary: This fixes an edge case in the `SpacesInSquareBrackets` option where an initial `&ref` lambda parameter is not padded with an initial space. `int foo = [&bar ]() {}` is fixed to give `int foo = [ &bar ]() {}` Reviewers: MyDeveloperDay, klimek, sammccall Reviewed by: MyDeveloperDay Subscribers: cfe-commits Tags: #clang, #clang-format Differential Revision: https://reviews.llvm.org/D69649
* [Format] Add format check for throwing negative numbersBrian Gesiak2019-10-181-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The code `throw -1;` is currently formatted by clang-format as `throw - 1;`. This diff adds a fix for this edge case and a test to check for this in the future. For context, I am looking into a related bug in the clang-formatting of coroutine keywords: `co_yield -1;` is also reformatted in this manner as `co_yield - 1;`. A later diff will add these changes and tests for the `co_yield` and `co_return` keywords. Patch by Jonathan Thomas (jonathoma)! Reviewers: modocache, sammccall, Quuxplusone Reviewed By: sammccall Subscribers: cfe-commits Tags: #clang-format, #clang Differential Revision: https://reviews.llvm.org/D69144 llvm-svn: 375258
* [clang-format] fix regression recognizing casts in Obj-C callsKrasimir Georgiev2019-10-181-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: r373922 added checks for a few tokens that, following an `)` make it unlikely that the `)` is the closing paren of a cast expression. The specific check for `tok::l_square` there introduced a regression for casts of Obj-C calls, like: ``` (cast)[func arg] ``` From the tests added in r373922, I believe the `tok::l_square` case is added to capture the case where a non-cast `)` is directly followed by an attribute specifier, like: ``` int f(int x) [[noreturn]]; ``` I've specialized the code to look for such attribute specifier instead of `tok::l_square` in general. Also, I added a regression test and moved the test cases added in r373922 to an already existing place documenting other instances of historically misidentified casts. Reviewers: MyDeveloperDay Reviewed By: MyDeveloperDay Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69164 llvm-svn: 375247
* [clang-format] throws an incorrect assertion in consumeToken() formatting ↵Paul Hoad2019-10-101-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | the MSVC stl Summary: An incorrect assertion is thrown when clang-formatting MSVC's STL library ``` Assertion failed: !Line.startsWith(tok::hash), file C:/llvm/llvm-project/clang/lib/Format/TokenAnnotator.cpp, line 847 Stack dump: 0. Program arguments: C:\llvm\build\bin\clang-format.exe -i -n ./stl/inc/xkeycheck.h ``` ``` Enable warning C4005 to find the forbidden define. ``` Reviewers: mitchell-stellar, STL_MSFT, klimek, krasimir Reviewed By: mitchell-stellar Subscribers: cfe-commits Tags: #clang-format, #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D68707 llvm-svn: 374399
* [clang-format] Update noexcept reference qualifiers detectionKrasimir Georgiev2019-10-091-14/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: r373165 fixed an issue where a templated noexcept member function with a reference qualifier would be indented more than expected: ``` // Formatting produced with LLVM style with AlwaysBreakTemplateDeclarations: Yes // before r373165: struct f { template <class T> void bar() && noexcept {} }; // after: struct f { template <class T> void bar() && noexcept {} }; ``` The way this is done is that in the AnnotatingParser in `lib/FormatTokenAnnotator.cpp` the determination of the usage of a `&` or `&&` (the line in determineTokenType ``` Current.Type = determineStarAmpUsage(... ``` is not performed in some cases anymore, combining with a few additional related checks afterwards. The net effect of these checks results in the `&` or `&&` token to start being classified as `TT_Unknown` in cases where before `r373165` it would be classified as `TT_UnaryOperator` or `TT_PointerOrReference` by `determineStarAmpUsage`. This inadvertently caused 2 classes of regressions I'm aware of: - The address-of `&` after a function assignment would be classified as `TT_Unknown`, causing spaces to surround it, disregarding style options: ``` // before r373165: void (*fun_ptr)(void) = &fun; // after: void (*fun_ptr)(void) = & fun; ``` - In cases where there is a function declaration list -- looking macro between a template line and the start of the function declaration, an `&` as part of the return type would be classified as `TT_Unknown`, causing spaces to surround it: ``` // before r373165: template <class T> DEPRECATED("lala") Type& foo(); // after: template <class T> DEPRECATED("lala") Type & foo(); ``` In these cases the problems are rooted in the skipping of the classification of a `&` (and similarly `&&`) by determineStarAmpUsage which effects the formatting decisions later in the pipeline. I've looked into the goal of r373165 and noticed that replacing `noexcept` with `const` in the given example produces no extra indentation with the old code: ``` // before r373165: struct f { template <class T> int foo() & const {} }; struct f { template <class T> int foo() & noexcept {} }; ``` I investigated how clang-format annotated these two examples differently to determine the places where the processing of both diverges in the pipeline. There were two places where the processing diverges, causing the extra indent in the `noexcept` case: 1. The `const` is annotated as a `TT_TrailingAnnotation`, whereas `noexcept` is annotated as `TT_Unknown`. I've updated the `determineTokenType` function to account for this by adding a missing `tok:kw_noexcept` to the clause that marks a token as `TT_TrailingAnnotation`. 2. The `&` in the second example is wrongly identified as `TT_BinaryOperator` in `determineStarAmpUsage`. This is the reason for the extra indentation -- clang-format gets confused and thinks this is an expression. I've updated `determineStarAmpUsage` to check for `tok:kw_noexcept`. With these two updates in place, the additional parsing introduced by r373165 becomes unnecessary and all added tests pass (with updates, as now clang-format respects the style configuration for spaces around the `&` in the test examples). I've removed these additions and added regression tests for the cases above. Reviewers: AndWass, MyDeveloperDay Reviewed By: MyDeveloperDay Subscribers: cfe-commits Tags: #clang, #clang-format Differential Revision: https://reviews.llvm.org/D68695 llvm-svn: 374172
* [clang-format] [PR27004] omits leading space for noexcept when formatting ↵Paul Hoad2019-10-071-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | operator delete() Summary: clang-format is incorrectly thinking the parameter parens are part of a cast operation, this is resulting in there sometimes being not space between the paren and the noexcept (and other keywords like volatile etc..) ``` void operator++(int) noexcept; void operator++(int &) noexcept; void operator delete(void *, std::size_t, const std::nothrow_t &)noexcept; ``` Reviewers: klimek, owenpan, mitchell-stellar Reviewed By: mitchell-stellar Subscribers: cfe-commits Tags: #clang-format, #clang Differential Revision: https://reviews.llvm.org/D68481 llvm-svn: 373922
* [clang-format] SpacesInSquareBrackets should affect lambdas with parameters tooPaul Hoad2019-10-051-3/+4
| | | | | | | | | | | | | | | | | | | | | | | 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
* [clang-format] C++11 braced lists should respect the SpacesInParentheses settingPaul Hoad2019-10-041-3/+6
| | | | | | | | | | | | | | | | | | | | | Summary: According to the clang-format documentation, "Fundamentally, C++11 braced lists are formatted exactly like function calls would be formatted in their place. If the braced list follows a name (e.g. a type or variable name), clang-format formats as if the `{}` were the parentheses of a function call with that name." This patch furthers the treatment of C++11 braced list braces as parentheses by respecting the `SpacesInParentheses` setting. Reviewers: MyDeveloperDay, reuk, owenpan Reviewed By: MyDeveloperDay Subscribers: cfe-commits Tags: #clang-format, #clang Patch By: mitchell-stellar Differential Revision: https://reviews.llvm.org/D68415 llvm-svn: 373751
* [clang-format] [PR43531] clang-format damages "alternative representations" ↵Paul Hoad2019-10-041-1/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | for operators Summary: https://bugs.llvm.org/show_bug.cgi?id=43531 Fix for clang-format incorrectly handles "alternative operators" as described by https://en.cppreference.com/w/cpp/language/operator_alternative compl = ~ not = ! these are unary operators, and clang-format will remove the space between them and a numeric constant this incorrectly formats the following code ``` int a compl 5; int a not 5; ``` into: ``` int a compl5; int a not5; ``` The code adds FIXME unit tests for "alternative token" representations for {} [] and # as defined by the same link, which would require a more detailed change to the FormatTokenLexer Reviewers: klimek, reuk, owenpan, mitchell-stellar, STL_MSFT Reviewed By: mitchell-stellar Subscribers: cfe-commits Tags: #clang-format, #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D68332 llvm-svn: 373750
* [clang-format] [PR42417] clang-format inserts a space after '->' for ↵Paul Hoad2019-10-041-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | operator->() overloading Summary: https://bugs.llvm.org/show_bug.cgi?id=42417 This revision removes the extra space between the opertor-> and the parens () ``` class Bug { auto operator-> () -> int*; auto operator++(int) -> int; }; ``` Reviewers: klimek, owenpan, byoungyoung, mitchell-stellar Reviewed By: mitchell-stellar Subscribers: cfe-commits Tags: #clang-format, #clang Differential Revision: https://reviews.llvm.org/D68242 llvm-svn: 373746
* [clang-format] [PR43338] C# clang format has space issues betweern C# only ↵Paul Hoad2019-10-041-5/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | keywords Summary: When formatting C# there can be issues with a lack of spaces between `using (` , `foreach (` and generic types The C# code ``` public class Foo { Dictionary<string,string> foo; } ``` will be formatted as ``` public class Foo { Dictionary<string, string>foo; ^^^^^ missing a space } ``` This revision also reverts some of {D66662} in order to make this cleaner and resolve an issues seen by @owenpan that the formatting didn't add a space when not in a code block This also transforms C# foreach commands to be seen as tok::kw_for commands (to ensure foreach gets the same Brace Wrapping behavior as for without littering the code with `if(Style.isCSharp())` Reviewers: owenpan, klimek, russellmcc, mitchell-stellar Reviewed By: mitchell-stellar Subscribers: cfe-commits Tags: #clang, #clang-format Differential Revision: https://reviews.llvm.org/D67660 llvm-svn: 373709
* [clang-format] [PR43333] Fix C# breaking before function name when using ↵Paul Hoad2019-10-041-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | Attributes Summary: This is a fix for https://bugs.llvm.org/show_bug.cgi?id=43333 This comes with 3 main parts - C# attributes cause function names on a new line even when AlwaysBreakAfterReturnType is set to None - Add AlwaysBreakAfterReturnType to None by default in the Microsoft style, - C# unit tests are not using Microsoft style (which we created to define the default C# style to match a vanilla C# project). Reviewers: owenpan, klimek, russellmcc, mitchell-stellar Reviewed By: mitchell-stellar Subscribers: cfe-commits Tags: #clang-tools-extra, #clang, #clang-format Differential Revision: https://reviews.llvm.org/D67629 llvm-svn: 373707
* [clang-format] Reference qualifiers in member templates causing extra ↵Paul Hoad2019-09-291-4/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | indentation. Summary: The following code ``` struct f { template <class T> void bar() && noexcept {} }; ``` will be formatted to the following with LLVM style, and `AlwaysBreakTemplateDeclarations: Yes` ``` struct f { template <class T> void bar() && noexcept {} }; ``` The indentation of the `void bar()` line is wrong. Reviewers: klimek, owenpan, krasimir, timwoj, MyDeveloperDay Reviewed By: klimek, MyDeveloperDay Subscribers: MyDeveloperDay, ilya-biryukov, llvm-commits, cfe-commits Patch By: AndWass Tags: #clang-format, #clang, #llvm Differential Revision: https://reviews.llvm.org/D68072 llvm-svn: 373165
* Revert r373056: [clang-format] Reference qualifiers in member templates ↵Ilya Biryukov2019-09-271-12/+4
| | | | | | | causing extra indentation Reason: this breaks unit tests. llvm-svn: 373059
* [clang-format] Reference qualifiers in member templates causing extra ↵Ilya Biryukov2019-09-271-4/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | indentation The following code ``` struct f { template <class T> void bar() && noexcept {} }; ``` will be formatted to the following with LLVM style, and `AlwaysBreakTemplateDeclarations: Yes` ``` struct f { template <class T> void bar() && noexcept {} }; ``` The indentation of the `void bar()` line is wrong. Patch by Andreas Wass (AndWass)! Differential Revision: https://reviews.llvm.org/D68072 llvm-svn: 373056
* [clang-format][PR41899] PointerAlignment: Left leads to useless space in ↵Paul Hoad2019-09-181-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | lambda intializer expression Summary: https://bugs.llvm.org/show_bug.cgi?id=41899 ```auto lambda = [&a = a]() { a = 2; };``` is formatted as ```auto lambda = [& a = a]() { a = 2; };``` With an extra space if PointerAlignment is set to Left > The space "& a" looks strange when there is no type in the lambda's intializer expression. This can be worked around with by setting "PointerAlignment: Right", but ideally "PointerAlignment: Left" would not add a space in this case. Reviewers: klimek, owenpan, krasimir, timwoj Reviewed By: klimek Subscribers: cfe-commits Tags: #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D67718 llvm-svn: 372249
* clang-format: Add support for formatting (some) lambdas with explicit ↵Nico Weber2019-09-131-3/+16
| | | | | | | | | | | | | | template parameters. This patch makes cases work where the lambda's template list doesn't contain any of + - ! ~ / % << | || && ^ == != >= <= ? : true false (see added FIXME). Ports r359967 to clang-format. Differential Revision: https://reviews.llvm.org/D67246 llvm-svn: 371854
* [clang-format] [PR43100] clang-format C# support does not add a space ↵Paul Hoad2019-09-121-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | between "using" and paren Summary: Addresses https://bugs.llvm.org/show_bug.cgi?id=43100 Formatting using statement in C# with clang-format removes the space between using and paren even when SpaceBeforeParens is ! ``` using(FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize : 1)) ``` this change simply overcomes this for when using C# settings in the .clang-format file ``` using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize : 1)) ``` All FormatTests pass.. ``` [==========] 688 tests from 21 test cases ran. (88508 ms total) [ PASSED ] 688 tests. ``` Reviewers: djasper, klimek, owenpan Reviewed By: owenpan Subscribers: llvm-commits, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66662 llvm-svn: 371720
* clang-format: [JS] handle `as const`.Martin Probst2019-08-261-0/+4
| | | | | | | | | | | | | | | | | | | | Summary: TypeScript 3.4 supports casting into a const type using `as const`: const x = {x: 1} as const; Previously, clang-format would insert a space after the `const`. With this patch, no space is inserted after the sequence `as const`. Reviewers: krasimir Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66736 llvm-svn: 369916
* [clang-format] Fix a bug that joins template closer and =Owen Pan2019-08-181-1/+1
| | | | | | | | | | Also fixes the documentation for SpaceBeforeAssignmentOperators. See discussions at https://reviews.llvm.org/D66332 Differential Revision: https://reviews.llvm.org/D66384 llvm-svn: 369214
* [clang-format] Fix the bug that joins template closer and > or >>Owen Pan2019-08-161-0/+2
| | | | | | | | | | Also fixes a buggy test case. See PR42404 Differential Revision: https://reviews.llvm.org/D66332 llvm-svn: 369157
* [clang-format] Expand AllowShortBlocksOnASingleLine for WebKitOwen Pan2019-08-111-1/+2
| | | | | | | | See PR40840 Differential Revision: https://reviews.llvm.org/D66059 llvm-svn: 368539
* [clang-format] fix crash involving invalid preprocessor lineKrasimir Georgiev2019-08-081-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This (invalid) fragment is crashing clang-format: ``` #if 1 int x; #elif int y; #endif ``` The reason being that the parser expects a token after `#elif`, and the subsequent parsing of the next line does not check if `CurrentToken` is null. Reviewers: gribozavr Reviewed By: gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65940 llvm-svn: 368280
* clang-format: Support `if CONSTEXPR` if CONSTEXPR is a macro.Nico Weber2019-07-271-7/+8
| | | | | | | | | | | | | | | | | | | | | | This is like r305666 (which added support for `if constexpr`) except that it allows a macro name after the if. This is slightly tricky for two reasons: 1. r305666 didn't add test coverage for all cases where it added a kw_constexpr, so I had to figure out what all the added cases were for. I now added tests for all `if constexpr` bits that didn't have tests. (This took a while, see e.g. https://reviews.llvm.org/D65223) 2. Parsing `if <ident> (` as an if means that `#if defined(` and `#if __has_include(` parse as ifs too. Add some special-case code to prevent this from happening where it's incorrect. Fixes PR39248. Differential Revision: https://reviews.llvm.org/D65227 llvm-svn: 367167
* [Format] Make it easy to add new format::FormatStyle::LanguageStandard. NFCIFangrui Song2019-07-241-2/+2
| | | | | | | | | | | | | | Preparatory change for D65043. We current use `!=LS_Cpp03` to enable language standards 11,14,17, and 2a. `>=LS_Cpp11` is better if we decide to add new LanguageStandard in the future. Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D65183 llvm-svn: 366876
* [Format/ObjC] Avoid breaking between unary operators and operandsBen Hamilton2019-07-191-0/+2
| | | | | | | | | | | | | | | | | | | | Summary: Test Plan: New tests added. Ran tests with: % ninja FormatTests && ./tools/clang/unittests/Format/FormatTests Confirmed tests failed before change and passed after change. Reviewers: krasimir, djasper, sammccall, klimek Reviewed By: sammccall Subscribers: klimek, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64775 llvm-svn: 366592
* [clang-format] Don't detect call to ObjC class method as C++11 attribute ↵Ben Hamilton2019-07-161-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | specifier Summary: Previously, clang-format detected something like the following as a C++11 attribute specifier. @[[NSArray class]] instead of an array with an Objective-C method call inside. In general, when the attribute specifier checking runs, if it sees 2 identifiers in a row, it decides that the square brackets represent an Objective-C method call. However, here, `class` is tokenized as a keyword instead of an identifier, so this check fails. To fix this, the attribute specifier first checks whether the first square bracket has an "@" before it. If it does, then that square bracket is not the start of a attribute specifier because it is an Objective-C array literal. (The assumption is that @[[.*]] is not valid C/C++.) Contributed by rkgibson2. Reviewers: benhamilton Reviewed By: benhamilton Subscribers: aaron.ballman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64632 llvm-svn: 366267
* clang-format: better handle namespace macrosFrancois Ferrand2019-06-061-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [clang-format] Allow configuring list of function-like macros that resolve ↵Francois Ferrand2019-05-291-7/+11
| | | | | | | | | | | | | | | | | | | | | | | 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
* Revert "Revert "[clang-format] Keep protobuf "package" statement on one line""Krasimir Georgiev2019-05-101-3/+3
| | | | | | | | | | | | | | | | | | | | | | | Summary: Top-level "package" and "import" statements should generally be kept on one line, for all languages. ---- This reverts commit rL356912. The regression from rL356835 was fixed via rC358275. Reviewers: krasimir, sammccall, MyDeveloperDay, xinz, dchai, klimek Reviewed By: krasimir, xinz, dchai Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60661 llvm-svn: 360411
* [clang-format] Use SpacesBeforeTrailingComments for "option" directiveKrasimir Georgiev2019-04-121-1/+4
| | | | | | | | | | | | | | | | | | | | | | Summary: AnnotatingParser::next() is needed to implicitly set TT_BlockComment versus TT_LineComment. On most other paths through AnnotatingParser::parseLine(), all tokens are consumed to achieve that. This change updates one place where this wasn't done. Contributed by @dchai! Reviewers: krasimir Reviewed By: krasimir Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60541 llvm-svn: 358275
* [clang-format] Optionally insert a space after unary ! operatorReuben Thomas2019-04-081-1/+2
| | | | llvm-svn: 357908
* [clang-format] BreakAfterReturnType ignored on functions with numeric ↵Paul Hoad2019-04-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | template parameters Summary: Addresses PR40696 - https://bugs.llvm.org/show_bug.cgi?id=40696 The BreakAfterReturnType didn't work if it had a single arguments which was a template with an integer template parameter ``` int foo(A<8> a) { return a; } ``` When run with the Mozilla style. would not break after the `int` ``` int TestFn(A<8> a) { return a; } ``` This revision resolves this issue by allowing numeric constants to be considered function parameters if if seen inside `<>` Reviewers: djasper, klimek, JonasToth, krasimir, reuk, alexfh Reviewed By: klimek Subscribers: cfe-commits, llvm-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D59309 llvm-svn: 357837
* [clang-format]: Add NonEmptyParentheses spacing optionReuben Thomas2019-03-301-4/+10
| | | | | | | | | | | | | This patch aims to add support for the following rules from the JUCE coding standards: - Always put a space before an open parenthesis that contains text - e.g. foo (123); - Never put a space before an empty pair of open/close parenthesis - e.g. foo(); Patch by Reuben Thomas Differential Revision: https://reviews.llvm.org/D55170 llvm-svn: 357344
* [clang-format] Add style option AllowShortLambdasOnASingleLineRonald Wampler2019-03-261-6/+19
| | | | | | | | | | | | | | | | | 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
* [clang-format] Refine structured binding detectionKrasimir Georgiev2019-03-251-8/+8
| | | | | | | | | | | | | | | | | | | | | Summary: Revision r356575 had the unfortunate consequence that now clang-format never detects an ObjC call expression after `&&`. This patch tries harder to distinguish between C++17 structured bindings and ObjC call expressions and adds a few regression tests. Reviewers: klimek Reviewed By: klimek Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D59774 llvm-svn: 356928
* Revert "[clang-format] Keep protobuf "package" statement on one line"Haojian Wu2019-03-251-3/+3
| | | | | | | | | | | | | This reverts commit r356835. This patch causes a regression, see the test below: verifyFormat("// Detached comment\n\n" "// Leading comment\n" "syntax = \"proto2\"; // trailing comment\n\n" "// in foo.bar package\n" "package foo.bar; // foo.bar package\n"); llvm-svn: 356912
* [clang-format] Keep protobuf "package" statement on one linePaul Hoad2019-03-231-3/+3
| | | | | | | | | | | | | | | | | | | | Summary: Top-level "package" and "import" statements should generally be kept on one line, for all languages. Reviewers: sammccall, krasimir, MyDeveloperDay Reviewed By: MyDeveloperDay Subscribers: MyDeveloperDay, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D59627 Patch By: dchai (Donald Chai) llvm-svn: 356835
OpenPOWER on IntegriCloud