From 92fe14e7f0fded4f221f8833f1e22a9872b7cb27 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Fri, 19 Mar 2010 17:40:23 +0100 Subject: [PATCH] Fixed #1491 (False positive when putting an access specifier at the end of a class declaration) --- lib/checkclass.cpp | 6 +++++- test/testclass.cpp | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 2323f0670..4bd9b46ad 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1536,7 +1536,11 @@ void CheckClass::checkConst() // skip private: public: etc if (tok2->isName() && tok2->str().find(":") != std::string::npos) - continue; + { + if (tok2->next()->str() == "}") + continue; + tok2 = tok2->next(); + } // static functions can't be const // virtual functions may be non-const for a reason diff --git a/test/testclass.cpp b/test/testclass.cpp index 29a668565..6c26d24d5 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -2093,6 +2093,13 @@ private: "};\n" "void bar() {}"); ASSERT_EQUALS("", errout.str()); + + checkConst("class Fred\n" + "{\n" + "public:\n" + " void foo() { }\n" + "};"); + ASSERT_EQUALS("[test.cpp:4]: (style) The function 'Fred::foo' can be const\n", errout.str()); } void const7()