]> granicus.if.org Git - clang/commitdiff
Fixes incorrect handling of the declaration context stack.
authorManuel Klimek <klimek@google.com>
Wed, 23 Jan 2013 11:03:04 +0000 (11:03 +0000)
committerManuel Klimek <klimek@google.com>
Wed, 23 Jan 2013 11:03:04 +0000 (11:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173250 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTest.cpp

index 047074135cf175193ee077d2147d9a0d68cf777d..c21fa0d74e5c50da3ea92c0ad0964a4bff3780a3 100644 (file)
@@ -33,12 +33,12 @@ public:
   ScopedDeclarationState(UnwrappedLine &Line, std::vector<bool> &Stack,
                          bool MustBeDeclaration)
       : Line(Line), Stack(Stack) {
-    Stack.push_back(MustBeDeclaration);
     Line.MustBeDeclaration = MustBeDeclaration;
+    Stack.push_back(MustBeDeclaration);
   }
   ~ScopedDeclarationState() {
-    Line.MustBeDeclaration = Stack.back();
     Stack.pop_back();
+    Line.MustBeDeclaration = Stack.back();
   }
 private:
   UnwrappedLine &Line;
index fb5221ee2461647bc8737334ddf1675babe48618..114359d04d1b8d9e51924a05bebbdc0cd98b5723 100644 (file)
@@ -1682,6 +1682,16 @@ TEST_F(FormatTest, BlockComments) {
 TEST_F(FormatTest, FormatStarDependingOnContext) {
   verifyFormat("void f(int *a);");
   verifyFormat("void f() { f(fint * b); }");
+  verifyFormat("class A {\n  void f(int *a);\n};");
+  verifyFormat("class A {\n  int *a;\n};");
+  verifyFormat("namespace a {\n"
+               "namespace b {\n"
+               "class A {\n"
+               "  void f() {}\n"
+               "  int *a;\n"
+               "};\n"
+               "}\n"
+               "}");
 }
 
 TEST_F(FormatTest, SpecialTokensAtEndOfLine) {