diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 39b9bc3ce..96b3ff3ec 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2249,6 +2249,12 @@ void Tokenizer::setVarId() if (Token::Match(tok, "class|struct %type% :|{|;")) continue; + if (Token::Match(tok, "using namespace %type% ;")) + { + tok = tok->next(); + continue; + } + if (Token::Match(tok, "else|return|typedef|delete|sizeof")) continue; diff --git a/test/testclass.cpp b/test/testclass.cpp index 61c3d7ac8..4d153532c 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -113,6 +113,7 @@ private: TEST_CASE(const16); // ticket #1551 TEST_CASE(const17); // ticket #1552 TEST_CASE(const18); // ticket #1563 + TEST_CASE(const19); // ticket #1612 TEST_CASE(constoperator1); // operator< can often be const TEST_CASE(constoperator2); // operator<< TEST_CASE(constincdec); // increment/decrement => non-const @@ -3217,6 +3218,19 @@ private: ASSERT_EQUALS("", errout.str()); } + void const19() + { + // ticket #1612 + checkConst("using namespace std;\n" + "class Fred {\n" + "private:\n" + " std::string s;\n" + "public:\n" + " void set(std::string ss) { s = ss; }\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + } + // increment/decrement => not const void constincdec() {