summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTest.cpp
Commit message (Collapse)AuthorAgeFilesLines
* clang-format: Don't corrupt macros with open braces.Daniel Jasper2015-03-131-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | Formatting: #define A { { #define B } } Before: #define A \ { \ { #define B } \ } After: #define A \ { \ { #define B \ } \ } This fixes llvm.org/PR22884. llvm-svn: 232166
* clang-format: [OBJC] Don't indent 8 spaces in method declarations.Daniel Jasper2015-03-121-0/+2
| | | | | | | | | | | | Before: - (void)aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: (SoooooooooooooooooooooomeType *)bbbbbbbbbb; After: - (void)aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: (SoooooooooooooooooooooomeType *)bbbbbbbbbb; llvm-svn: 232112
* clang-format: When putting */& next to types, also wrap before them.Daniel Jasper2015-03-121-7/+11
| | | | | | | | | | | | Before: LoooooooooooongType * loooooooooooongVariable; After: LoooooooooooongType *loooooooooooongVariable; llvm-svn: 232044
* clang-format: Fix incorrect && recognition.Daniel Jasper2015-03-111-0/+1
| | | | | | | | | | Before: if (a &&(b = c)) .. After: if (a && (b = c)) .. llvm-svn: 231920
* clang-format: Don't remove newline if macro ends in access specifier.Daniel Jasper2015-03-091-0/+24
| | | | | | | | | | | I.e.: #define A public: // The new line before this line would be removed. int a; llvm-svn: 231636
* clang-format: Slightly change indentation rules in for loops.Daniel Jasper2015-03-061-3/+5
| | | | | | | | | | | | | | | | | | | | | | There was already a TODO to double-check whether the extra indenation makes sense. A slightly different case reveals that it is actively harmful: for (int i = 0; i < aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa || bbbbbbbbbbbbbbbbbbbb < ccccccccccccccc; ++i) { } Here (and it is probably not a totally infrequent case, it just works out that "i < " is four spaces and so the four space extra indentation makes the operator precedence confusing. So, this will now instead be formatted as: for (int i = 0; i < aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa || bbbbbbbbbbbbbbbbbbbb < ccccccccccccccc; ++i) { } llvm-svn: 231461
* clang-format: Fix access to uninitialized memory.Daniel Jasper2015-03-031-0/+4
| | | | | | | | | With incomplete code, we aren't guaranteed to generated changes for every token. In that case, we need to assume that even the very first change can continue a preprocessor directive and initialize values accordingly. llvm-svn: 231066
* clang-format: Prefer wrapping a lambda's body over the lambda's return type.Daniel Jasper2015-03-021-0/+6
| | | | | | | | | | | | | | | Before: aaaaaaaaaaaaaaaaaaaaaa( [](aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &aaa) -> aaaaaaaaaaaaaaaaaaaaa { return aaaaaaaaaaaaaaaaa; }); After: aaaaaaaaaaaaaaaaaaaaaa( [](aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &aaa) -> aaaaaaaaaaaaaaaaaaaaa { return aaaaaaaaaaaaaaaaa; }); llvm-svn: 230942
* clang-format: Always align */& in multi-var DeclStmts.Daniel Jasper2015-03-011-10/+11
| | | | | | | | Seems like the most consistent thing to do and in multi-var DeclStmts, it is especially important to point out that the */& bind to the identifier. llvm-svn: 230903
* clang-format: Make trailing commas in array inits force one per line.Daniel Jasper2015-02-271-0/+4
| | | | | | | | | | | | | Before: NSArray *array = @[ @"a", @"a", ]; After: NSArray *array = @[ @"a", @"a", ]; llvm-svn: 230741
* clang-format: Make braced list formatting more consistent.Daniel Jasper2015-02-261-0/+5
| | | | | | | | | | | | | | | | | | | | | | Before: Aaaa aaaaaaaaaaa{ { a, // +1 indent weird. b, // trailing comma signals one per line. }, // trailing comma signals one per line. }; After: Aaaa aaaaaaaaaaa{ { a, // better!? b, // trailing comma signals one per line. }, // trailing comma signals one per line. }; Interesting that this apparently was entirely untested :-(. llvm-svn: 230627
* clang-format: Fix space of arrays of pointers to templated types.Daniel Jasper2015-02-261-0/+5
| | | | | | | | | | Before: vector<int>(*foo_)[6]; After: vector<int> (*foo_)[6]; llvm-svn: 230625
* clang-format: Allow breaking after "else if(" as a last resort.Daniel Jasper2015-02-261-0/+5
| | | | | | This isn't generally nice, but better than violating the column limit. llvm-svn: 230620
* clang-format: Fix spacing for function with ref-qualification ..Daniel Jasper2015-02-251-5/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | .. when using SpacesInCStyleCastParentheses != SpacesInParentheses. Before: FormatStyle Spaces = getLLVMStyle(); Deleted &operator=(const Deleted &)& = default; Spaces.SpacesInParentheses = true; Deleted(const Deleted &)& = default; Spaces.SpacesInCStyleCastParentheses = true; Spaces.SpacesInParentheses= false; Deleted( const Deleted & )& = default; After: FormatStyle Spaces = getLLVMStyle(); Deleted &operator=(const Deleted &)& = default;; Spaces.SpacesInParentheses= true; Deleted( const Deleted & )& = default; Spaces.SpacesInCStyleCastParentheses = true; Spaces.SpacesInParentheses= false; Deleted(const Deleted &)& = default; Patch by Jean-Philippe Dufraigne. Thank you! llvm-svn: 230473
* clang-format: Change location of stashed tokenJacques Pienaar2015-02-241-0/+1
| | | | | | Commit of patch in http://reviews.llvm.org/D7871 llvm-svn: 230395
* Fix merging of << at end of input.Jacques Pienaar2015-02-201-0/+1
| | | | | | Commit of review http://reviews.llvm.org/D7766 llvm-svn: 230061
* clang-format: Space and triple angle braces.Jacques Pienaar2015-02-181-0/+21
| | | | | | Committing patch http://reviews.llvm.org/D6800. llvm-svn: 229783
* clang-format: Don't force a break after "endl" if everything fits on one line.Daniel Jasper2015-02-171-2/+3
| | | | llvm-svn: 229486
* clang-format: Fix crasher.Daniel Jasper2015-02-171-0/+1
| | | | llvm-svn: 229485
* Reverting a switch from LLVM_DELETED_FUNCTION to = delete; this test should ↵Aaron Ballman2015-02-161-1/+1
| | | | | | not have changed. llvm-svn: 229394
* Removing LLVM_DELETED_FUNCTION, as MSVC 2012 was the last reason for ↵Aaron Ballman2015-02-151-1/+1
| | | | | | requiring the macro. NFC; Clang edition. llvm-svn: 229339
* clang-format: Correctly mark preprocessor lines in child blocks.Daniel Jasper2015-02-081-0/+7
| | | | | | | | | | | | | | | | | | | | | | This prevents contracting: auto lambda = []() { int a = 2 #if A + 2 #endif ; }; into: auto lambda = []() { int a = 2 #if A + 2 #endif ; }; Which is obviously BAD. This fixes llvm.org/PR22496. llvm-svn: 228522
* clang-format: Format Objective-C try blocks like all the other try blocks.Nico Weber2015-02-071-4/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Before: @try { // ... } @finally { // ... } Now: @try { // ... } @finally { // ... } This is consistent with how we format C++ try blocks and SEH try blocks. clang-format not doing this before was an implementation oversight. This is dependent on BraceBreakingStyle. The snippet above is with the Attach style. Style Stroustrip for example still results in the "Before:" snippet, which makes sense since other blocks (try, else) break after '}' too. llvm-svn: 228483
* clang-format: Fix assert triggering on carriage returns.Daniel Jasper2015-02-051-0/+4
| | | | llvm-svn: 228288
* clang-format: Add support for SEH __try / __except / __finally blocks.Nico Weber2015-02-041-0/+27
| | | | | | | | | | | | | | | | | | | | | | | | This lets clang-format format __try { } __except(0) { } and __try { } __finally { } correctly. __try and __finally are keywords if `LangOpts.MicrosoftExt` is set, so this turns this on. This also enables a few other keywords, but it shouldn't overly perturb regular clang-format operation. __except is a context-sensitive keyword, so `AdditionalKeywords` needs to be passed around to a few more places. Fixes PR22321. llvm-svn: 228148
* clang-format: Fix crasher caused by not properly setting dry-run.Daniel Jasper2015-01-291-0/+2
| | | | llvm-svn: 227427
* clang-format: Fix another crasher caused by incomplete macro code.Daniel Jasper2015-01-231-0/+1
| | | | | | | | We did't properly mark all of an AnnotatedLine's children as finalized and thus would reformat the same tokens in different branches of #if/#else sequences leading to invalid replacements. llvm-svn: 226930
* clang-format: Fix incorrect classification of "*".Daniel Jasper2015-01-231-0/+1
| | | | | | | | | | Before: *a = b *c; After: *a = b * c; llvm-svn: 226923
* clang-format: Fix crasher when splitting incomplete escape sequences.Daniel Jasper2015-01-211-0/+6
| | | | llvm-svn: 226698
* clang-format: Fix crasher caused by incorrect resetting of token info.Daniel Jasper2015-01-211-0/+1
| | | | llvm-svn: 226685
* clang-format: Fix bad memory access.Daniel Jasper2015-01-211-0/+1
| | | | llvm-svn: 226680
* clang-format: Fix use-heap-after-free bug.Daniel Jasper2015-01-211-0/+2
| | | | | | Discovered by the awesome test case and ASAN. llvm-svn: 226678
* clang-format: Fix AlwaysBreakBeforeMultilineStrings with ColumnLimit=0Daniel Jasper2015-01-201-0/+3
| | | | | | | | | | | | | | Before: const char *x = "hello llvm"; After: const char *x = "hello llvm"; This fixes llvm.org/PR22245. Patch by Bill Meltsner, thank you! llvm-svn: 226564
* clang-format: Fix crasher on weird comments.Daniel Jasper2015-01-191-0/+3
| | | | | | | | Crashing input: /\ / comment llvm-svn: 226454
* clang-format: Fix crasher on incomplete condition compilation.Daniel Jasper2015-01-191-0/+6
| | | | | | | | | | | Previously crashing input: void f( #if A ); #else #endif llvm-svn: 226451
* clang-format: Fix crash on invalid code.Daniel Jasper2015-01-191-0/+2
| | | | | | Input "a<," made clang-format crash. llvm-svn: 226450
* clang-format: Fix clang-format crash on invalid code.Daniel Jasper2015-01-191-0/+8
| | | | llvm-svn: 226449
* clang-format: Fix assertion when trying to build a nullptr StringRef.Daniel Jasper2015-01-191-0/+1
| | | | llvm-svn: 226448
* clang-format: Fix endless loop on incomplete try-catch-block.Daniel Jasper2015-01-191-0/+3
| | | | llvm-svn: 226447
* clang-format: Remove assert that isn't helpful.Daniel Jasper2015-01-191-0/+1
| | | | | | | This assert would trigger on: #d , = } llvm-svn: 226446
* Fix assertion in BreakableBlockComment (http://llvm.org/PR21916).Alexander Kornienko2015-01-121-0/+11
| | | | | | | | | | | | Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D6894 llvm-svn: 225628
* clang-format: Improve format of lambdas in ctor initializers.Daniel Jasper2015-01-121-0/+4
| | | | | | | | | | | | | | | | Before: Constructor() : Constructor([] { // comment int i; }) {} After: Constructor() : Constructor([] { // comment int i; }) {} llvm-svn: 225625
* clang-format: Fix formatting of inline asm.Daniel Jasper2015-01-121-2/+6
| | | | | | | | | Specifically, adjust the leading "__asm {" and trailing "}" while still leaving the assembly inside it alone. This fixes llvm.org/PR22190. llvm-svn: 225623
* clang-format: Force line break between "endl" and "<<".Daniel Jasper2015-01-081-0/+4
| | | | | | | | | | | | | | | | This makes piped output easier to read in many instances. Before: llvm::errs() << aaaa << std::endl << bbbb << std::endl; After: llvm::errs() << aaaa << std::endl << bbbb << std::endl; Also fix a few instance of "don't use else after return" as per the coding standards. llvm-svn: 225444
* clang-format: Improve template parameter detection.Daniel Jasper2015-01-081-0/+1
| | | | | | | | | | Before: struct A < std::enable_if<sizeof(T2) <sizeof(int32)>::type>; After: struct A<std::enable_if<sizeof(T2) < sizeof(int32)>::type>; llvm-svn: 225435
* clang-format: Understand single-line comments at the end of blocks.Daniel Jasper2015-01-071-0/+8
| | | | | | | | | | | This prevents clang-format from moving/aligning the comment in the snippet: void f() { int i; // some comment // some unrelated comment } llvm-svn: 225352
* clang-format: Fix unary operator detection.Daniel Jasper2015-01-071-0/+1
| | | | | | | | | | Before: ** outparam = 1; After: **outparam = 1; llvm-svn: 225349
* clang-format: Fix incorrect detection of ObjC "in" keyword.Daniel Jasper2014-12-181-0/+1
| | | | | | | | | | Before: for (auto v : in [1]) { .. After: for (auto v : in[1]) { .. llvm-svn: 224513
* Don't break single-line raw string literals.Alexander Kornienko2014-12-141-21/+8
| | | | | | | | | | | | Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D6636 llvm-svn: 224223
* clang-format: Revamp nested block formatting.Daniel Jasper2014-12-121-2/+7
| | | | | | | | | | | | | | | | | | | | | | This fixed llvm.org/PR21804 and hopefully a few other strange cases. Before: if (blah_blah(whatever, whatever, [] { doo_dah(); doo_dah(); })) { } } After: if (blah_blah(whatever, whatever, [] { doo_dah(); doo_dah(); })) { } } llvm-svn: 224112
OpenPOWER on IntegriCloud