From f90236a1833ca9cd1f505b2604d59c7b877f1386 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Tue, 30 Nov 2010 19:40:32 +0100 Subject: [PATCH] Fixed #2252 (segmentation fault with enable=all) --- lib/symboldatabase.cpp | 23 ++++++++++++- test/testclass.cpp | 78 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 6fa7b22de..a77b8b20e 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -912,12 +912,24 @@ void SymbolDatabase::SpaceInfo::getVarList() vartok = tok->tokAt(3); tok = vartok->next(); } + else if (Token::Match(tok, ":: %type% :: %type% %var% ;")) + { + isClass = true; + vartok = tok->tokAt(4); + tok = vartok->next(); + } else if (Token::Match(tok, "%type% :: %type% :: %type% %var% ;")) { isClass = true; vartok = tok->tokAt(5); tok = vartok->next(); } + else if (Token::Match(tok, ":: %type% :: %type% :: %type% %var% ;")) + { + isClass = true; + vartok = tok->tokAt(6); + tok = vartok->next(); + } // Structure? else if (Token::Match(tok, "struct|union %type% %var% ;")) @@ -976,8 +988,11 @@ void SymbolDatabase::SpaceInfo::getVarList() } // Container.. - else if (Token::Match(tok, "%type% :: %type% :: %type% <") || + else if (Token::Match(tok, ":: %type% :: %type% :: %type% <") || + Token::Match(tok, "%type% :: %type% :: %type% <") || + Token::Match(tok, ":: %type% :: %type% <") || Token::Match(tok, "%type% :: %type% <") || + Token::Match(tok, ":: %type% <") || Token::Match(tok, "%type% <")) { // got an unhandled template? @@ -1015,6 +1030,12 @@ void SymbolDatabase::SpaceInfo::getVarList() vartok = tok->next(); tok = vartok->next(); } + else if (tok && (Token::Match(tok, "> :: %type% %var% ;") || Token::Match(tok, ">> :: %type% %var% ;"))) + { + isClass = true; + vartok = tok->tokAt(3); + tok = vartok->next(); + } else if (tok && (Token::Match(tok, "> * %var% ;") || Token::Match(tok, ">> * %var% ;"))) { vartok = tok->tokAt(2); diff --git a/test/testclass.cpp b/test/testclass.cpp index 4662bf768..2ee75246a 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -152,6 +152,7 @@ private: TEST_CASE(const38); // ticket #2135 TEST_CASE(const39); TEST_CASE(const40); // ticket #2228 + TEST_CASE(const41); // ticket #2255 TEST_CASE(constoperator1); // operator< can often be const TEST_CASE(constoperator2); // operator<< TEST_CASE(constoperator3); @@ -4434,6 +4435,83 @@ private: ASSERT_EQUALS("", errout.str()); } + void const41() // ticket #2255 + { + checkConst("class Fred\n" + "{\n" + " ::std::string m_name;\n" + "public:\n" + " void SetName(const ::std::string & name)\n" + " {\n" + " m_name = name;\n" + " }\n" + "};\n"); + + ASSERT_EQUALS("", errout.str()); + + checkConst("class SharedPtrHolder\n" + "{\n" + " ::std::tr1::shared_ptr pNum;\n" + " public :\n" + " void SetNum(const ::std::tr1::shared_ptr & apNum)\n" + " {\n" + " pNum = apNum;\n" + " }\n" + "};\n"); + + ASSERT_EQUALS("", errout.str()); + + checkConst("class SharedPtrHolder2\n" + "{\n" + " public:\n" + " typedef ::std::tr1::shared_ptr IntSharedPtr;\n" + " private:\n" + " IntSharedPtr pNum;\n" + " public :\n" + " void SetNum(const IntSharedPtr & apNum)\n" + " {\n" + " pNum = apNum;\n" + " }\n" + "};\n"); + + ASSERT_EQUALS("", errout.str()); + + checkConst("struct IntPtrTypes\n" + "{\n" + " typedef ::std::tr1::shared_ptr Shared;\n" + "};\n" + "class SharedPtrHolder3\n" + "{\n" + " private:\n" + " IntPtrTypes::Shared pNum;\n" + " public :\n" + " void SetNum(const IntPtrTypes::Shared & apNum)\n" + " {\n" + " pNum = apNum;\n" + " }\n" + "};\n"); + + ASSERT_EQUALS("", errout.str()); + + checkConst("template \n" + "struct PtrTypes\n" + "{\n" + " typedef ::std::tr1::shared_ptr Shared;\n" + "};\n" + "class SharedPtrHolder4\n" + "{\n" + " private:\n" + " PtrTypes::Shared pNum;\n" + " public :\n" + " void SetNum(const PtrTypes::Shared & apNum)\n" + " {\n" + " pNum = apNum;\n" + " }\n" + "};\n"); + + ASSERT_EQUALS("", errout.str()); + } + // increment/decrement => not const void constincdec() {