diff options
author | Nico Weber <nicolasweber@gmx.de> | 2013-02-12 16:17:07 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2013-02-12 16:17:07 +0000 |
commit | 4444917f5c5586a9283ea4c77e912d67cb75269c (patch) | |
tree | d29ffb66c97b14d8e89569d1ce11ed62ef6e7a2f /clang/unittests | |
parent | 7e7e3de43dfd6b1f5c58a775f3fce3bcbf7ad8d9 (diff) | |
download | bcm5719-llvm-4444917f5c5586a9283ea4c77e912d67cb75269c.tar.gz bcm5719-llvm-4444917f5c5586a9283ea4c77e912d67cb75269c.zip |
Formatter: Correctly format stars in `sizeof(int**)` and similar places.
This redoes how '*' and '&' are classified as pointer / reference markers when
followed by ')', '>', or ','.
Previously, determineStarAmpUsage() marked a single '*' and '&' followed by
')', '>', or ',' as pointer or reference marker. Now, all '*'s and '&'s
preceding ')', '>', or ',' are marked as pointer / reference markers. Fixes
PR14884.
Since only the last '*' in 'int ***' was marked as pointer before (the rest
were unary operators, which don't reach spaceRequiredBetween()),
spaceRequiredBetween() now had to be thought about handing multiple '*'s in
sequence.
Before:
return sizeof(int * *);
Type **A = static_cast<Type * *>(P);
Now:
return sizeof(int**);
Type **A = static_cast<Type **>(P);
While here, also make all methods of AnnotatingParser except parseLine()
private.
Review URL: http://llvm-reviews.chandlerc.com/D384
llvm-svn: 174975
Diffstat (limited to 'clang/unittests')
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 9b9f5c71d21..e9520b618c3 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -1615,6 +1615,14 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyIndependentOfContext("a * (a + b);"); verifyIndependentOfContext("(a *)(a + b);"); verifyIndependentOfContext("int *pa = (int *)&a;"); + verifyIndependentOfContext("return sizeof(int **);"); + verifyIndependentOfContext("return sizeof(int ******);"); + verifyIndependentOfContext("return (int **&)a;"); + verifyGoogleFormat("return sizeof(int**);"); + verifyIndependentOfContext("Type **A = static_cast<Type **>(P);"); + verifyGoogleFormat("Type** A = static_cast<Type**>(P);"); + // FIXME: The newline is wrong. + verifyFormat("auto a = [](int **&, int ***) {}\n;"); verifyIndependentOfContext("InvalidRegions[*R] = 0;"); @@ -2540,8 +2548,7 @@ TEST_F(FormatTest, ObjCSnippets) { verifyFormat("@dynamic textColor;"); verifyFormat("char *buf1 = @encode(int *);"); verifyFormat("char *buf1 = @encode(typeof(4 * 5));"); - // FIXME: Enable once PR14884 is fixed: - //verifyFormat("char *buf1 = @encode(int **);"); + verifyFormat("char *buf1 = @encode(int **);"); verifyFormat("Protocol *proto = @protocol(p1);"); verifyFormat("SEL s = @selector(foo:);"); verifyFormat("@synchronized(self) {\n" |