diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 86320d232..217d036c7 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1805,6 +1805,9 @@ void CheckClass::checkConst() const std::string& opName = func->tokenDef->str(); if (opName.compare(8, 5, "const") != 0 && (endsWith(opName,'&') || endsWith(opName,'*'))) continue; + } else if (Token::simpleMatch(func->retDef, "std :: shared_ptr <")) { + // Don't warn if a std::shared_ptr is returned + continue; } else { // don't warn for unknown types.. // LPVOID, HDC, etc diff --git a/test/testclass.cpp b/test/testclass.cpp index 632cb097c..32114e6e4 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -195,6 +195,7 @@ private: TEST_CASE(constUnion); // ticket #2111 - fp when there is a union TEST_CASE(constArrayOperator); // #4406 TEST_CASE(constRangeBasedFor); // #5514 + TEST_CASE(const_shared_ptr); TEST_CASE(initializerListOrder); TEST_CASE(initializerListUsage); @@ -6199,6 +6200,18 @@ private: ASSERT_EQUALS("[test.cpp:8]: (style, inconclusive) Technically the member function 'Fred::f2' can be const.\n", errout.str()); } + void const_shared_ptr() { // #8674 + checkConst("class Fred {\n" + "public:\n" + " std::shared_ptr getData();\n" + "private:\n" + " std::shared_ptr data;\n" + "};\n" + "\n" + "std::shared_ptr Fred::getData() { return data; }"); + ASSERT_EQUALS("", errout.str()); + } + void checkInitializerListOrder(const char code[]) { // Clear the error log errout.str("");