diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 9694827ec..7f662b5aa 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1734,7 +1734,7 @@ void CheckClass::checkConst() continue; } else if (func->isOperator() && Token::Match(previous, ";|{|}|public:|private:|protected:")) { // Operator without return type: conversion operator const std::string& opName = func->tokenDef->str(); - if (opName.compare(8, 5, "const") != 0 && opName.back() == '&') + if (opName.compare(8, 5, "const") != 0 && (opName.back() == '&' || opName.back() == '*')) continue; } else { // don't warn for unknown types.. diff --git a/test/testclass.cpp b/test/testclass.cpp index 3e1539cae..95b95242f 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -3320,12 +3320,28 @@ private: } void constoperator4() { + // #7953 + checkConst("class A {\n" + " int c;\n" + "public:\n" + " operator int*() { return &c; };\n" + "};"); + ASSERT_EQUALS("", errout.str()); + + checkConst("class A {\n" + " int c;\n" + "public:\n" + " operator const int*() { return &c; };\n" + "};"); + ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::operatorconstint*' can be const.\n", errout.str()); + + // #2375 checkConst("struct Fred {\n" " int array[10];\n" " typedef int* (Fred::*UnspecifiedBoolType);\n" " operator UnspecifiedBoolType() { };\n" "};"); - ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::operatorint**' can be const.\n", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::operatorint**' can be const.\n", "", errout.str()); checkConst("struct Fred {\n" " int array[10];\n"