From 7c18ece65d166ace384f541c2f1d0466a104d509 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Sat, 14 Aug 2010 08:16:53 +0200 Subject: [PATCH] Symbol database: Fixed bug when end of namespace wasn't found. Ticket: #1895 --- lib/checkclass.cpp | 10 ++++++---- test/testclass.cpp | 12 ++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index e279e1969..dae88f2f7 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -85,15 +85,17 @@ void CheckClass::createSymbolDatabase() tok = tok2; } - // check if in class - else if (info && !info->isNamespace) + // check if in space + else if (info) { - // check for end of class + // check for end of space if (tok == info->classEnd) { info = info->nest; } - else + + // check if in class or structure + else if (!info->isNamespace) { // What section are we in.. if (tok->str() == "private:") diff --git a/test/testclass.cpp b/test/testclass.cpp index b8d2aa153..ed52adf00 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -135,6 +135,7 @@ private: TEST_CASE(const28); // ticket #1883 TEST_CASE(const29); // ticket #1922 TEST_CASE(const30); + TEST_CASE(const31); TEST_CASE(constoperator1); // operator< can often be const TEST_CASE(constoperator2); // operator<< TEST_CASE(constincdec); // increment/decrement => non-const @@ -3852,6 +3853,17 @@ private: ASSERT_EQUALS("", errout.str()); } + void const31() + { + checkConst("namespace std { }\n" + "class Fred {\n" + "public:\n" + " int a;\n" + " int get() { return a; }\n" + "};\n"); + ASSERT_EQUALS("[test.cpp:5]: (style) The function 'Fred::get' can be const\n", errout.str()); + } + // increment/decrement => not const void constincdec() {