diff options
author | Francois Ferrand <thetypz@gmail.com> | 2017-06-30 20:00:02 +0000 |
---|---|---|
committer | Francois Ferrand <thetypz@gmail.com> | 2017-06-30 20:00:02 +0000 |
commit | d2130f51a197dafb969f12f98cde62b148c318d4 (patch) | |
tree | 4e25d305f78d6fea2bb4209ab88e433d18cf948b /clang/unittests/Format/FormatTestJava.cpp | |
parent | 5372f0a73e5711a0508280b5f5e655df9edadf80 (diff) | |
download | llvm-d2130f51a197dafb969f12f98cde62b148c318d4.zip llvm-d2130f51a197dafb969f12f98cde62b148c318d4.tar.gz llvm-d2130f51a197dafb969f12f98cde62b148c318d4.tar.bz2 |
clang-format: Do not binpack initialization lists
Summary:
This patch tries to avoid binpacking when initializing lists/arrays, to allow things like:
static int types[] = {
registerType1(),
registerType2(),
registerType3(),
};
std::map<int, std::string> x = {
{ 0, "foo fjakfjaklf kljj" },
{ 1, "bar fjakfjaklf kljj" },
{ 2, "stuff fjakfjaklf kljj" },
};
This is similar to how dictionnaries are formatted, and actually corresponds to the same conditions: when initializing a container (and not just 'calling' a constructor).
Such formatting involves 2 things:
* Line breaks around the content of the block. This can be forced by adding a comma or comment after the last element
* Elements should not be binpacked
This patch considers the block is an initializer list if it either ends with a comma, or follows an assignment, which seems to provide a sensible approximation.
Reviewers: krasimir, djasper
Reviewed By: djasper
Subscribers: malcolm.parsons, klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D34238
llvm-svn: 306868
Diffstat (limited to 'clang/unittests/Format/FormatTestJava.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTestJava.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/clang/unittests/Format/FormatTestJava.cpp b/clang/unittests/Format/FormatTestJava.cpp index 6e685f6..b9cfaff 100644 --- a/clang/unittests/Format/FormatTestJava.cpp +++ b/clang/unittests/Format/FormatTestJava.cpp @@ -237,7 +237,10 @@ TEST_F(FormatTestJava, EnumDeclarations) { TEST_F(FormatTestJava, ArrayInitializers) { verifyFormat("new int[] {1, 2, 3, 4};"); verifyFormat("new int[] {\n" - " 1, 2, 3, 4,\n" + " 1,\n" + " 2,\n" + " 3,\n" + " 4,\n" "};"); FormatStyle Style = getStyleWithColumns(65); |