"Fossies" - the Fresh Open Source Software Archive

Member "cppcheck-1.89/test/testunusedprivfunc.cpp" (1 Sep 2019, 24358 Bytes) of package /windows/misc/cppcheck-1.89.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "testunusedprivfunc.cpp": 1.88_vs_1.89.

    1 /*
    2  * Cppcheck - A tool for static C/C++ code analysis
    3  * Copyright (C) 2007-2019 Cppcheck team.
    4  *
    5  * This program is free software: you can redistribute it and/or modify
    6  * it under the terms of the GNU General Public License as published by
    7  * the Free Software Foundation, either version 3 of the License, or
    8  * (at your option) any later version.
    9  *
   10  * This program is distributed in the hope that it will be useful,
   11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13  * GNU General Public License for more details.
   14  *
   15  * You should have received a copy of the GNU General Public License
   16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   17  */
   18 
   19 #include "checkclass.h"
   20 #include "platform.h"
   21 #include "settings.h"
   22 #include "testsuite.h"
   23 #include "tokenize.h"
   24 
   25 #include <simplecpp.h>
   26 #include <map>
   27 #include <vector>
   28 
   29 class TestUnusedPrivateFunction : public TestFixture {
   30 public:
   31     TestUnusedPrivateFunction() : TestFixture("TestUnusedPrivateFunction") {
   32     }
   33 
   34 private:
   35     Settings settings;
   36 
   37     void run() OVERRIDE {
   38         settings.addEnabled("style");
   39 
   40         TEST_CASE(test1);
   41         TEST_CASE(test2);
   42         TEST_CASE(test3);
   43         TEST_CASE(test4);
   44         TEST_CASE(test5);
   45         TEST_CASE(test6); // ticket #2602
   46 
   47         // [ 2236547 ] False positive --style unused function, called via pointer
   48         TEST_CASE(func_pointer1);
   49         TEST_CASE(func_pointer2);
   50         TEST_CASE(func_pointer3);
   51         TEST_CASE(func_pointer4); // ticket #2807
   52         TEST_CASE(func_pointer5); // ticket #2233
   53         TEST_CASE(func_pointer6); // ticket #4787
   54 
   55         TEST_CASE(ctor);
   56         TEST_CASE(ctor2);
   57 
   58         TEST_CASE(classInClass);
   59         TEST_CASE(sameFunctionNames);
   60         TEST_CASE(incompleteImplementation);
   61 
   62         TEST_CASE(derivedClass);   // skip warning for derived classes. It might be a virtual function.
   63 
   64         TEST_CASE(friendClass);
   65 
   66         TEST_CASE(borland1);     // skip FP when using __property
   67         TEST_CASE(borland2);     // skip FP when using __published
   68 
   69         // No false positives when there are "unused" templates that are removed in the simplified token list
   70         TEST_CASE(template1);
   71 
   72         // #2407 - FP when called from operator()
   73         TEST_CASE(fp_operator);
   74         TEST_CASE(testDoesNotIdentifyMethodAsFirstFunctionArgument); // #2480
   75         TEST_CASE(testDoesNotIdentifyMethodAsMiddleFunctionArgument);
   76         TEST_CASE(testDoesNotIdentifyMethodAsLastFunctionArgument);
   77 
   78         TEST_CASE(multiFile);
   79         TEST_CASE(unknownBaseTemplate); // ticket #2580
   80         TEST_CASE(hierarchie_loop); // ticket 5590
   81 
   82         TEST_CASE(staticVariable); //ticket #5566
   83 
   84         TEST_CASE(templateSimplification); //ticket #6183
   85     }
   86 
   87 
   88     void check(const char code[], Settings::PlatformType platform = Settings::Native) {
   89         // Clear the error buffer..
   90         errout.str("");
   91 
   92         settings.platform(platform);
   93 
   94         // Raw tokens..
   95         std::vector<std::string> files(1, "test.cpp");
   96         std::istringstream istr(code);
   97         const simplecpp::TokenList tokens1(istr, files, files[0]);
   98 
   99         // Preprocess..
  100         simplecpp::TokenList tokens2(files);
  101         std::map<std::string, simplecpp::TokenList*> filedata;
  102         simplecpp::preprocess(tokens2, tokens1, files, filedata, simplecpp::DUI());
  103 
  104         // Tokenize..
  105         Tokenizer tokenizer(&settings, this);
  106         tokenizer.createTokens(&tokens2);
  107         tokenizer.simplifyTokens1("");
  108 
  109         // Check for unused private functions..
  110         CheckClass checkClass(&tokenizer, &settings, this);
  111         checkClass.privateFunctions();
  112     }
  113 
  114 
  115 
  116     void test1() {
  117         check("class Fred\n"
  118               "{\n"
  119               "private:\n"
  120               "    unsigned int f();\n"
  121               "public:\n"
  122               "    Fred();\n"
  123               "};\n"
  124               "\n"
  125               "Fred::Fred()\n"
  126               "{ }\n"
  127               "\n"
  128               "unsigned int Fred::f()\n"
  129               "{ }");
  130 
  131         ASSERT_EQUALS("[test.cpp:4]: (style) Unused private function: 'Fred::f'\n", errout.str());
  132 
  133         check("#line 1 \"p.h\"\n"
  134               "class Fred\n"
  135               "{\n"
  136               "private:\n"
  137               "    unsigned int f();\n"
  138               "public:\n"
  139               "    Fred();\n"
  140               "};\n"
  141               "\n"
  142               "#line 1 \"p.cpp\"\n"
  143               "Fred::Fred()\n"
  144               "{ }\n"
  145               "\n"
  146               "unsigned int Fred::f()\n"
  147               "{ }");
  148 
  149         ASSERT_EQUALS("[p.h:4]: (style) Unused private function: 'Fred::f'\n", errout.str());
  150 
  151         check("#line 1 \"p.h\"\n"
  152               "class Fred\n"
  153               "{\n"
  154               "private:\n"
  155               "void f();\n"
  156               "};\n"
  157               "\n"
  158               "\n"
  159               "#line 1 \"p.cpp\"\n"
  160               "\n"
  161               "void Fred::f()\n"
  162               "{\n"
  163               "}");
  164         ASSERT_EQUALS("[p.h:4]: (style) Unused private function: 'Fred::f'\n", errout.str());
  165 
  166         // Don't warn about include files which implementation we don't see
  167         check("#line 1 \"p.h\"\n"
  168               "class Fred\n"
  169               "{\n"
  170               "private:\n"
  171               "void f();\n"
  172               "void g() {}\n"
  173               "};\n"
  174               "\n"
  175               "#line 1 \"p.cpp\"\n"
  176               "\n"
  177               "int main()\n"
  178               "{\n"
  179               "}");
  180         ASSERT_EQUALS("", errout.str());
  181     }
  182 
  183 
  184     void test2() {
  185         check("class A {\n"
  186               "public:\n"
  187               "    A();\n"
  188               "\n"
  189               "    void a() const\n"
  190               "    { b(); }\n"
  191               "private:\n"
  192               "    void b( ) const\n"
  193               "    { }\n"
  194               "};\n"
  195               "\n"
  196               "A::A()\n"
  197               "{ }");
  198         ASSERT_EQUALS("", errout.str());
  199     }
  200 
  201 
  202     void test3() {
  203         check("class A {\n"
  204               "public:\n"
  205               "    A() { }\n"
  206               "    ~A();\n"
  207               "private:\n"
  208               "    void B() { }\n"
  209               "};\n"
  210               "\n"
  211               "A::~A()\n"
  212               "{ B(); }");
  213         ASSERT_EQUALS("", errout.str());
  214     }
  215 
  216 
  217     void test4() {
  218         check("class A {\n"
  219               "public:\n"
  220               "    A();\n"
  221               "private:\n"
  222               "    bool _owner;\n"
  223               "    void b() { }\n"
  224               "};\n"
  225               "\n"
  226               "A::A() : _owner(false)\n"
  227               "{ b(); }");
  228         ASSERT_EQUALS("", errout.str());
  229     }
  230 
  231 
  232     void test5() {
  233         check("class A {\n"
  234               "private:\n"
  235               "    A() : lock(new Lock())\n"
  236               "    { }\n"
  237               "    Lock *lock;\n"
  238               "};");
  239         ASSERT_EQUALS("", errout.str());
  240     }
  241 
  242     void test6() { // ticket #2602 segmentation fault
  243         check("class A {\n"
  244               "    A& operator=(const A&);\n"
  245               "};");
  246         ASSERT_EQUALS("", errout.str());
  247     }
  248 
  249 
  250 
  251 
  252 
  253     void func_pointer1() {
  254         check("class Fred\n"
  255               "{\n"
  256               "private:\n"
  257               "    typedef void (*testfp)();\n"
  258               "\n"
  259               "    testfp get()\n"
  260               "    {\n"
  261               "        return test;\n"
  262               "    }\n"
  263               "\n"
  264               "    static void test()\n"
  265               "    { }\n"
  266               "\n"
  267               "public:\n"
  268               "    Fred();\n"
  269               "};\n"
  270               "\n"
  271               "Fred::Fred()\n"
  272               "{}");
  273 
  274         ASSERT_EQUALS("[test.cpp:6]: (style) Unused private function: 'Fred::get'\n", errout.str());
  275     }
  276 
  277 
  278 
  279     void func_pointer2() {
  280         check("class UnusedPrivateFunctionMemberPointer\n"
  281               "{\n"
  282               "public:\n"
  283               "    UnusedPrivateFunctionMemberPointer()\n"
  284               "    :   mObserver(this, &UnusedPrivateFunctionMemberPointer::callback)\n"
  285               "    {}\n"
  286               "\n"
  287               "private:\n"
  288               "    void callback(const& unsigned) const {}\n"
  289               "\n"
  290               "    Observer<UnusedPrivateFunctionMemberPointer, unsigned> mObserver;\n"
  291               "};");
  292         ASSERT_EQUALS("", errout.str());
  293     }
  294 
  295 
  296     void func_pointer3() {
  297         check("class c1\n"
  298               "{\n"
  299               "public:\n"
  300               "    c1()\n"
  301               "    { sigc::mem_fun(this, &c1::f1); }\n"
  302               "\n"
  303               "private:\n"
  304               "    void f1() const {}\n"
  305               "};");
  306         ASSERT_EQUALS("", errout.str());
  307     }
  308 
  309 
  310     void func_pointer4() { // ticket #2807
  311         check("class myclass {\n"
  312               "public:\n"
  313               "    myclass();\n"
  314               "private:\n"
  315               "    static void f();\n"
  316               "    void (*fptr)();\n"
  317               "};\n"
  318               "myclass::myclass() { fptr = &f; }\n"
  319               "void myclass::f() {}");
  320         ASSERT_EQUALS("", errout.str());
  321     }
  322 
  323 
  324     void func_pointer5() {
  325         check("class A {\n"
  326               "public:\n"
  327               "    A() { f = A::func; }\n"
  328               "    void (*f)();\n"
  329               "private:\n"
  330               "    static void func() { }\n"
  331               "};");
  332         ASSERT_EQUALS("", errout.str());
  333     }
  334 
  335 
  336     void func_pointer6() { // #4787
  337         check("class Test {\n"
  338               "private:\n"
  339               "    static void a(const char* p) { }\n"
  340               "public:\n"
  341               "    void test(void* f = a) {\n"
  342               "        f(\"test\");\n"
  343               "    }\n"
  344               "};");
  345         ASSERT_EQUALS("", errout.str());
  346     }
  347 
  348 
  349     void ctor() {
  350         check("class PrivateCtor\n"
  351               "{\n"
  352               "private:\n"
  353               "    PrivateCtor(int threadNum) :\n"
  354               "        numOfThreads(threadNum)\n"
  355               "    {\n"
  356               "    }\n"
  357               "\n"
  358               "    int numOfThreads;\n"
  359               "};");
  360 
  361         ASSERT_EQUALS("", errout.str());
  362     }
  363 
  364     void ctor2() {
  365         check("struct State {\n"
  366               "  State(double const totalWeighting= TotalWeighting()) :\n"
  367               "    totalWeighting_(totalWeighting) {}\n"
  368               "private:\n"
  369               "  double TotalWeighting() { return 123.0; }\n"  // called from constructor
  370               "public:\n"
  371               "  double totalWeighting_;\n"
  372               "};");
  373         ASSERT_EQUALS("", errout.str());
  374     }
  375 
  376 
  377     void classInClass() {
  378         check("class A\n"
  379               "{\n"
  380               "public:\n"
  381               "\n"
  382               "    class B\n"
  383               "    {\n"
  384               "    private:\n"
  385               "    };\n"
  386               "private:\n"
  387               "    static void f()\n"
  388               "    { }\n"
  389               "};");
  390         ASSERT_EQUALS("[test.cpp:10]: (style) Unused private function: 'A::f'\n", errout.str());
  391 
  392         check("class A\n"
  393               "{\n"
  394               "public:\n"
  395               "    A()\n"
  396               "    { }\n"
  397               "\n"
  398               "private:\n"
  399               "    void f()\n"
  400               "    { }\n"
  401               "\n"
  402               "    class B\n"
  403               "    {\n"
  404               "    public:\n"
  405               "        B(A *a)\n"
  406               "        { a->f(); }\n"
  407               "    };\n"
  408               "};");
  409         ASSERT_EQUALS("", errout.str());
  410 
  411         check("class A {\n"  // #6968 - outer definition
  412               "public:\n"
  413               "  class B;\n"
  414               "private:\n"
  415               "  void f() {}\n"
  416               "}\n"
  417               "class A::B {"
  418               "  B() { A a; a.f(); }\n"
  419               "}\n");
  420         ASSERT_EQUALS("", errout.str());
  421     }
  422 
  423 
  424     void sameFunctionNames() {
  425         check("class A\n"
  426               "{\n"
  427               "public:\n"
  428               "    void a()\n"
  429               "    {\n"
  430               "        f(1);\n"
  431               "    }\n"
  432               "\n"
  433               "private:\n"
  434               "    void f() { }\n"
  435               "    void f(int) { }\n"
  436               "};");
  437         ASSERT_EQUALS("", errout.str());
  438     }
  439 
  440     void incompleteImplementation() {
  441         // The implementation for "A::a" is missing - so don't check if
  442         // "A::b" is used or not
  443         check("#file \"test.h\"\n"
  444               "class A\n"
  445               "{\n"
  446               "public:\n"
  447               "    A();\n"
  448               "    void a();\n"
  449               "private:\n"
  450               "    void b();\n"
  451               "};\n"
  452               "#endfile\n"
  453               "A::A() { }\n"
  454               "void A::b() { }");
  455         ASSERT_EQUALS("", errout.str());
  456     }
  457 
  458     void derivedClass() {
  459         // skip warning in derived classes in case the base class is invisible
  460         check("class derived : public base\n"
  461               "{\n"
  462               "public:\n"
  463               "    derived() : base() { }\n"
  464               "private:\n"
  465               "    void f();\n"
  466               "};");
  467         ASSERT_EQUALS("", errout.str());
  468 
  469         check("class base {\n"
  470               "public:\n"
  471               "    virtual void foo();\n"
  472               "    void bar();\n"
  473               "};\n"
  474               "class derived : public base {\n"
  475               "private:\n"
  476               "    void foo() {}\n" // Skip for overrides of virtual functions of base
  477               "    void bar() {}\n" // Don't skip if no function is overridden
  478               "};");
  479         ASSERT_EQUALS("[test.cpp:9]: (style) Unused private function: 'derived::bar'\n", errout.str());
  480 
  481         check("class Base {\n"
  482               "private:\n"
  483               "    virtual void func() = 0;\n"
  484               "public:\n"
  485               "    void public_func() {\n"
  486               "        func();\n"
  487               "    };\n"
  488               "};\n"
  489               "\n"
  490               "class Derived1: public Base {\n"
  491               "private:\n"
  492               "    void func() {}\n"
  493               "};\n"
  494               "class Derived2: public Derived1 {\n"
  495               "private:\n"
  496               "    void func() {}\n"
  497               "};");
  498         ASSERT_EQUALS("", errout.str());
  499 
  500         check("class Base {\n"
  501               "public:\n"
  502               "    void dostuff() {\n"
  503               "      f();\n"
  504               "    }\n"
  505               "\n"
  506               "private:\n"
  507               "    virtual Base* f() = 0;\n"
  508               "};\n"
  509               "\n"
  510               "class Derived : public Base {\n"
  511               "private:\n"
  512               "    Derived* f() {\n"
  513               "      return 0;\n"
  514               "    }\n"
  515               "};");
  516         ASSERT_EQUALS("", errout.str());
  517     }
  518 
  519     void friendClass() {
  520         // ticket #2459 - friend class
  521         check("class Foo {\n"
  522               "private:\n"
  523               "    friend Bar;\n" // Unknown friend class
  524               "    void f() { }\n"
  525               "};");
  526         ASSERT_EQUALS("", errout.str());
  527 
  528         check("struct Bar {\n"
  529               "    void g() { f(); }\n" // Friend class seen, but f not seen
  530               "};\n"
  531               "class Foo {\n"
  532               "private:\n"
  533               "    friend Bar;\n"
  534               "    void f();\n"
  535               "};");
  536         ASSERT_EQUALS("", errout.str());
  537 
  538         check("struct Bar {\n"
  539               "    void g() { f(); }\n" // Friend class seen, but f() used in it
  540               "};\n"
  541               "class Foo {\n"
  542               "private:\n"
  543               "    friend Bar;\n"
  544               "    void f() { }\n"
  545               "};");
  546         ASSERT_EQUALS("", errout.str());
  547 
  548         check("class Bar {\n" // Friend class seen, f() not used in it
  549               "};\n"
  550               "class Foo {\n"
  551               "    friend Bar;\n"
  552               "    void f() { }\n"
  553               "};");
  554         ASSERT_EQUALS("[test.cpp:5]: (style) Unused private function: 'Foo::f'\n", errout.str());
  555     }
  556 
  557     void borland1() {
  558         // ticket #2034 - Borland C++ __property
  559         check("class Foo {\n"
  560               "private:\n"
  561               "    int getx() {\n"
  562               "        return 123;\n"
  563               "    }\n"
  564               "public:\n"
  565               "    Foo() { }\n"
  566               "    __property int x = {read=getx}\n"
  567               "};", Settings::Win32A);
  568         ASSERT_EQUALS("", errout.str());
  569     }
  570 
  571     void borland2() {
  572         // ticket #3661 - Borland C++ __published
  573         check("class Foo {\n"
  574               "__published:\n"
  575               "    int getx() {\n"
  576               "        return 123;\n"
  577               "    }\n"
  578               "public:\n"
  579               "    Foo() { }\n"
  580               "};", Settings::Win32A);
  581         ASSERT_EQUALS("", errout.str());
  582     }
  583 
  584     void template1() {
  585         // ticket #2067 - Template methods do not "use" private ones
  586         check("class A {\n"
  587               "public:\n"
  588               "    template <class T>\n"
  589               "    T getVal() const;\n"
  590               "\n"
  591               "private:\n"
  592               "    int internalGetVal() const { return 8000; }\n"
  593               "};\n"
  594               "\n"
  595               "template <class T>\n"
  596               "T A::getVal() const {\n"
  597               "    return internalGetVal();\n"
  598               "};");
  599         ASSERT_EQUALS("", errout.str());
  600     }
  601 
  602     void fp_operator() {
  603         // #2407 - FP when function is called from operator()
  604         check("class Fred\n"
  605               "{\n"
  606               "public:\n"
  607               "    void operator()(int x) {\n"
  608               "        startListening();\n"
  609               "    }\n"
  610               "\n"
  611               "private:\n"
  612               "    void startListening() {\n"
  613               "    }\n"
  614               "};");
  615         ASSERT_EQUALS("", errout.str());
  616 
  617         check("class Fred\n"
  618               "{\n"
  619               "public:\n"
  620               "    void operator()(int x) {\n"
  621               "    }\n"
  622               "\n"
  623               "private:\n"
  624               "    void startListening() {\n"
  625               "    }\n"
  626               "};");
  627         ASSERT_EQUALS("[test.cpp:8]: (style) Unused private function: 'Fred::startListening'\n", errout.str());
  628 
  629         // #5059
  630         check("class Fred {\n"
  631               "    void* operator new(size_t obj_size, size_t buf_size) {}\n"
  632               "};");
  633         TODO_ASSERT_EQUALS("[test.cpp:2]: (style) Unused private function: 'Fred::operatornew'\n", "", errout.str()); // No message for operators - we currently cannot check their usage
  634 
  635         check("class Fred {\n"
  636               "    void* operator new(size_t obj_size, size_t buf_size) {}\n"
  637               "public:\n"
  638               "    void* foo() { return new(size) Fred(); }\n"
  639               "};");
  640         ASSERT_EQUALS("", errout.str());
  641     }
  642 
  643     void testDoesNotIdentifyMethodAsFirstFunctionArgument() {
  644         check("void callback(void (*func)(int), int arg)"
  645               "{"
  646               "    (*func)(arg);"
  647               "}"
  648               "class MountOperation"
  649               "{"
  650               "    static void Completed(int i);"
  651               "public:"
  652               "    MountOperation(int i);"
  653               "};"
  654               "void MountOperation::Completed(int i)"
  655               "{"
  656               "    std::cerr << i << std::endl;"
  657               "}"
  658               "MountOperation::MountOperation(int i)"
  659               "{"
  660               "    callback(MountOperation::Completed, i);"
  661               "}"
  662               "int main(void)"
  663               "{"
  664               "    MountOperation aExample(10);"
  665               "}"
  666              );
  667         ASSERT_EQUALS("", errout.str());
  668     }
  669 
  670     void testDoesNotIdentifyMethodAsMiddleFunctionArgument() {
  671         check("void callback(char, void (*func)(int), int arg)"
  672               "{"
  673               "    (*func)(arg);"
  674               "}"
  675               "class MountOperation"
  676               "{"
  677               "    static void Completed(int i);"
  678               "public:"
  679               "    MountOperation(int i);"
  680               "};"
  681               "void MountOperation::Completed(int i)"
  682               "{"
  683               "    std::cerr << i << std::endl;"
  684               "}"
  685               "MountOperation::MountOperation(int i)"
  686               "{"
  687               "    callback('a', MountOperation::Completed, i);"
  688               "}"
  689               "int main(void)"
  690               "{"
  691               "    MountOperation aExample(10);"
  692               "}"
  693              );
  694         ASSERT_EQUALS("", errout.str());
  695     }
  696 
  697     void testDoesNotIdentifyMethodAsLastFunctionArgument() {
  698         check("void callback(int arg, void (*func)(int))"
  699               "{"
  700               "    (*func)(arg);"
  701               "}"
  702               "class MountOperation"
  703               "{"
  704               "    static void Completed(int i);"
  705               "public:"
  706               "    MountOperation(int i);"
  707               "};"
  708               "void MountOperation::Completed(int i)"
  709               "{"
  710               "    std::cerr << i << std::endl;"
  711               "}"
  712               "MountOperation::MountOperation(int i)"
  713               "{"
  714               "    callback(i, MountOperation::Completed);"
  715               "}"
  716               "int main(void)"
  717               "{"
  718               "    MountOperation aExample(10);"
  719               "}"
  720              );
  721         ASSERT_EQUALS("", errout.str());
  722     }
  723 
  724     void multiFile() { // ticket #2567
  725         check("#file \"test.h\"\n"
  726               "struct Fred\n"
  727               "{\n"
  728               "    Fred()\n"
  729               "    {\n"
  730               "        Init();\n"
  731               "    }\n"
  732               "private:\n"
  733               "    void Init();\n"
  734               "};\n"
  735               "#endfile\n"
  736               "void Fred::Init()\n"
  737               "{\n"
  738               "}");
  739 
  740         ASSERT_EQUALS("", errout.str());
  741     }
  742 
  743     void unknownBaseTemplate() { // ticket #2580
  744         check("class Bla : public Base2<Base> {\n"
  745               "public:\n"
  746               "    Bla() {}\n"
  747               "private:\n"
  748               "    virtual void F() const;\n"
  749               "};\n"
  750               "void Bla::F() const { }");
  751 
  752         ASSERT_EQUALS("", errout.str());
  753     }
  754 
  755     void hierarchie_loop() {
  756         check("class InfiniteB : InfiniteA {\n"
  757               "    class D {\n"
  758               "    };\n"
  759               "};\n"
  760               "namespace N {\n"
  761               "    class InfiniteA : InfiniteB {\n"
  762               "    };\n"
  763               "}\n"
  764               "class InfiniteA : InfiniteB {\n"
  765               "    void foo();\n"
  766               "};\n"
  767               "void InfiniteA::foo() {\n"
  768               "    C a;\n"
  769               "}");
  770 
  771         ASSERT_EQUALS("", errout.str());
  772     }
  773 
  774     void staticVariable() {
  775         check("class Foo {\n"
  776               "    static int i;\n"
  777               "    static int F() const { return 1; }\n"
  778               "};\n"
  779               "int Foo::i = Foo::F();");
  780         ASSERT_EQUALS("", errout.str());
  781 
  782         check("class Foo {\n"
  783               "    static int i;\n"
  784               "    int F() const { return 1; }\n"
  785               "};\n"
  786               "Foo f;\n"
  787               "int Foo::i = f.F();");
  788         ASSERT_EQUALS("", errout.str());
  789 
  790         check("class Foo {\n"
  791               "    static int i;\n"
  792               "    static int F() const { return 1; }\n"
  793               "};\n"
  794               "int Foo::i = sth();"
  795               "int i = F();");
  796         ASSERT_EQUALS("[test.cpp:3]: (style) Unused private function: 'Foo::F'\n", errout.str());
  797     }
  798 
  799     void templateSimplification() { //ticket #6183
  800         check("class CTest {\n"
  801               "public:\n"
  802               "    template <typename T>\n"
  803               "    static void Greeting(T val) {\n"
  804               "        std::cout << val << std::endl;\n"
  805               "    }\n"
  806               "private:\n"
  807               "    static void SayHello() {\n"
  808               "        std::cout << \"Hello World!\" << std::endl;\n"
  809               "    }\n"
  810               "};\n"
  811               "template<>\n"
  812               "void CTest::Greeting(bool) {\n"
  813               "    CTest::SayHello();\n"
  814               "}\n"
  815               "int main() {\n"
  816               "    CTest::Greeting<bool>(true);\n"
  817               "    return 0;\n"
  818               "}");
  819         ASSERT_EQUALS("", errout.str());
  820     }
  821 };
  822 
  823 REGISTER_TEST(TestUnusedPrivateFunction)