r175960 - Don't recognize unnamed pointer parameters as casts.
Daniel Jasper
djasper at google.com
Sat Feb 23 00:07:18 PST 2013
Author: djasper
Date: Sat Feb 23 02:07:18 2013
New Revision: 175960
URL: http://llvm.org/viewvc/llvm-project?rev=175960&view=rev
Log:
Don't recognize unnamed pointer parameters as casts.
This fixes llvm.org/PR15061.
Before: virtual void f(int *)const;
After: virtual void f(int *) const;
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=175960&r1=175959&r2=175960&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Sat Feb 23 02:07:18 2013
@@ -602,7 +602,8 @@ private:
!Current.Children.empty() && (Current.Children[0].is(tok::equal) ||
Current.Children[0].is(tok::semi) ||
Current.Children[0].is(tok::l_brace));
- if (ParensNotExpr && !ParensCouldEndDecl)
+ if (ParensNotExpr && !ParensCouldEndDecl &&
+ Contexts.back().IsExpression)
// FIXME: We need to get smarter and understand more cases of casts.
Current.Type = TT_CastRParen;
} else if (Current.is(tok::at) && Current.Children.size()) {
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=175960&r1=175959&r2=175960&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sat Feb 23 02:07:18 2013
@@ -1728,10 +1728,12 @@ TEST_F(FormatTest, UndestandsOverloadedO
}
TEST_F(FormatTest, UnderstandsNewAndDelete) {
- verifyFormat("A *a = new A;");
- verifyFormat("A *a = new (placement) A;");
- verifyFormat("delete a;");
- verifyFormat("delete (A *)a;");
+ verifyFormat("void f() {\n"
+ " A *a = new A;\n"
+ " A *a = new (placement) A;\n"
+ " delete a;\n"
+ " delete (A *)a;\n"
+ "}");
}
TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
@@ -1895,6 +1897,11 @@ TEST_F(FormatTest, FormatsCasts) {
verifyFormat("void f(int i = (kA * kB) & kMask) {}");
verifyFormat("int a = sizeof(int) * b;");
verifyFormat("int a = alignof(int) * b;");
+
+ // These are not casts, but at some point were confused with casts.
+ verifyFormat("virtual void foo(int *) override;");
+ verifyFormat("virtual void foo(char &) const;");
+ verifyFormat("virtual void foo(int *a, char *) const;");
}
TEST_F(FormatTest, FormatsFunctionTypes) {
More information about the cfe-commits
mailing list