diff options
author | Daniel Jasper <djasper@google.com> | 2013-01-13 08:01:36 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-01-13 08:01:36 +0000 |
commit | 4981bd0ca215570ef1e2e1c1c64a2c399069dc42 (patch) | |
tree | 8609a1c7cea041e660bc9d6f7ea3f8ab781e579d /unittests/Format/FormatTest.cpp | |
parent | 377b8c66b48b01fdd3f308d33f49af64ad632e87 (diff) |
Improve identification of c-style casts.
A ")" before any of "=", "{" or ";" won't be a cast. This fixes issues
with the formatting of unnamed parameters.
Before: void f(int *){}
After: void f(int *) {}
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172349 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Format/FormatTest.cpp')
-rw-r--r-- | unittests/Format/FormatTest.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 5ace0f82f9..765d16f99a 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -1045,9 +1045,6 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyFormat("A<int **> a;"); verifyFormat("A<int *, int *> a;"); verifyFormat("A<int **, int **> a;"); - verifyFormat("Type *A = static_cast<Type *>(P);"); - verifyFormat("Type *A = (Type *)P;"); - verifyFormat("Type *A = (vector<Type *, int *>)P;"); verifyFormat( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n" @@ -1062,6 +1059,25 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyGoogleFormat("int a = b ? *c : *d;"); } +TEST_F(FormatTest, FormatsCasts) { + verifyFormat("Type *A = static_cast<Type *>(P);"); + verifyFormat("Type *A = (Type *)P;"); + verifyFormat("Type *A = (vector<Type *, int *>)P;"); + verifyFormat("int a = (int)(2.0f);"); + + // FIXME: These also need to be identified. + verifyFormat("int a = (int) 2.0f;"); + verifyFormat("int a = (int) * b;"); + + // These are not casts. + verifyFormat("void f(int *) {}"); + verifyFormat("void f(int *);"); + verifyFormat("void f(int *) = 0;"); + verifyFormat("void f(SmallVector<int>) {}"); + verifyFormat("void f(SmallVector<int>);"); + verifyFormat("void f(SmallVector<int>) = 0;"); +} + TEST_F(FormatTest, FormatsFunctionTypes) { // FIXME: Determine the cases that need a space after the return type and fix. verifyFormat("A<bool()> a;"); |