SourceForge has been redesigned. Learn more.

#44 Mocking private member function, adding signature to MOCK_METHOD does not fix

Bret Kuhns

I was attempting to mock a private function when I ran into the accessibility issue. The Turtle documentation states to explicitly state the signature in MOCK_METHOD's third parameter. When I do that (in Visual Studio 2012), I get the following warning:

warning C4002: too many actual parameters for macro 'MOCK_METHOD'

Followed by the inaccessble member error:

error C2248: 'MyClass::someFunctionName' : cannot access private member declared in class 'MyClass'

So, the suggestion in the documentation doesn't seem to fix the problem, and the three parameter variant of MOCK_METHOD causes the extra warning.

Luckily using MOCK_METHOD_EXT and including the signature and a custom identifier fixes the problem, but this is not the documented solution.


  • Mathieu Champlon

    Hi Bret,

    The following compiles fine with MSVC 2010

    struct base
        virtual void m() = 0;
    MOCK_BASE_CLASS( derived, base )
        MOCK_METHOD( m, 0, void() )

    Sadly I don't have MSVC 2012 available, but it seems for some reason MOCK_VARIADIC_MACROS doesn't get defined for that compiler.
    This is how it's done (in config.hpp):

    #      define MOCK_VARIADIC_MACROS
    #   endif

    Which version of boost are you using ?

    Thanks for reporting this !

  • Bret Kuhns

    Bret Kuhns - 2014-01-08

    I'm using boost 1.53. VS2012 (MSVC11) qualifies as an "additional test" compiler for 1.53.

    • Mathieu Champlon

      I downloaded and tested with VS2012 Express and both boost 1.50 and 1.55 and the code compiles fine.
      I'll give it a go with boost 1.53 later today but I'm a bit at loss right now.
      I suppose you don't manually deactivate variadic macros?


  • Mathieu Champlon

    It indeed compiles with boost 1.53.
    Would you be able to provide me with a test case ?

  • Bret Kuhns

    Bret Kuhns - 2014-01-14

    I'll try to come up with a bare minimum example and duplicate it on my dev machine as soon as I get a chance. I'll also try it on another machine and see if maybe it's a configuration issue. Thanks for investigating this on your end.

  • Bret Kuhns

    Bret Kuhns - 2014-01-29

    Sorry for the delay. I finally got a chance to test this on a separate machine. Visual Studio 2012 Ultimate Update 3. I copied and pasted your example above rather than my own and I get the same error message. I don't think express vs. ultimate edition should matter here.

    I'm attaching my example project so you can give it a try. You'll just need to add the include/lib paths for turtle and boost and it should compile enough to fail to compile main.cpp. If it compiles for you, then I'm very confused.

    I'm using turtle 1.2.4 with boost 1.53 (my team won't update boost until after this release).

    • Mathieu Champlon

      Well, it does compile for me, but I might not use the exact versions, I'll double check.
      In the meanwhile what happens if you force this right before including turtle in your pch.h

      #include <turtle/mock.hpp>



  • Bret Kuhns

    Bret Kuhns - 2014-01-29

    I added MOCK_VARIADIC_MACROS before the include and still get the same errors. I pulled boost and I get the same errors both with and without the macro.

    • Mathieu Champlon

      I had to remove boost and turtle props files from the solution because MSVC was complaining about not finding them when loading the project file:

          <Import Project="..\..\..\..\..\..\..\dev\ThirdParty\turtle-1.2.4\turtle.props" />
          <Import Project="..\..\..\..\..\..\..\dev\ThirdParty\boost_1_53_0\boost.props" />

      Would you care to share them ? Maybe there's something in them which causes the issue ?


  • Bret Kuhns

    Bret Kuhns - 2014-01-30

    Sorry about that. They're very simple property sheets that I make so it's easy to add a third party library to my projects. I've attached them, though you'll find they simple add the include/lib paths for boost, and the include path for turtle. I drop them in the root directory of each library, respectively, then reference them in my projects that need them.

    • Mathieu Champlon

      Well yes, they are indeed quite simple.

      Here is the command line for main.cpp (Properties, C/C++, Command Line) I have:

      /Yu"pch.h" /GS /analyze- /W3 /Zc:wchar_t /ZI /Gm /Od /sdl /Fd"Debug\vc110.pdb" /fp:precise /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /Oy- /MDd /Fa"Debug\" /EHsc /nologo /Fo"Debug\" /Fp"Debug\CppSandbox.pch"

      Do you see any difference with yours ?

      Also could you preprocess main.cpp to a file (Properties, C/C++, Preprocessor, Preprocess to a File -> Yes) and attach the resulting dump ?
      This would be the main.i file in CppSandbox/Debug.

      Thanks !

  • Bret Kuhns

    Bret Kuhns - 2014-01-30

    The command looks identical. I've attached the main.i result.

    I noticed from your first response in this ticket that you show how MOCK_VARIADIC_MACRO gets set. I looked in config.hpp and I don't see that #define anywhere. I added your snippet to no effect. I did a search for MOCK_VARIADIC_MACRO in all of my turtle-1.2.4 directory and got no results.

    Last edit: Bret Kuhns 2014-01-30
  • Mathieu Champlon

    Ah that does explain this, then ! :)

    It looks like something went terribly wrong with the latest release which appears to not be 1.2.4 but an earlier version (probably 1.2.2 as far as I can tell). I don't really have a clue about what happened, I have a build server which I get the latest version from, so this should minimize that sort of hazard, in theory.
    That's great to notice this about 6 months later...

    Well, I suppose a release has been long overdue anyway so I'll try and push one shortly.

    Sorry about that, and thanks for your help !


  • Mathieu Champlon


    I just released turtle 1.2.5 sorry about all the trouble...


  • Mathieu Champlon

    • status: open --> closed

Log in to post a comment.