Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9192937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:02:51+00:00 2026-06-17T21:02:51+00:00

I am using googlemock to mock out an std::fstream object in my unit tests,

  • 0

I am using googlemock to mock out an std::fstream object in my unit tests, like this:

TEST_F(SomeTest, SomethingIsDoneCorrectly)
{
    class MockFstream : public std::fstream {};
    MockFstream lMockFstream;
    // Expectations and assertions here
}

When I compile I get the following warnings:

Warning 1 warning C4250: ‘SomeTest_SomethingIsDoneCorrectly_Test::TestBody::MockFstream’ : inherits ‘std::basic_istream<_Elem,_Traits>::std::basic_istream<_Elem,_Traits>::_Add_vtordisp1’ via dominance

Warning 2 warning C4250: ‘SomeTest_SomethingIsDoneCorrectly_Test::TestBody::MockFstream’ : inherits ‘std::basic_ostream<_Elem,_Traits>::std::basic_ostream<_Elem,_Traits>::_Add_vtordisp2’ via dominance

I’d prefer clean build output, so I want to suppress these specific warnings, but I’m writing cross-platform code, so I’d also prefer to avoid compiler-specific #pragmas.

Is there something I can do in the googlemock object that will hide these warnings?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:02:52+00:00Added an answer on June 17, 2026 at 9:02 pm

    It turns out that these warnings are a side-effect from some quirks in the Microsoft C++ STL. I’ve quoted an explanation from the relevant Microsoft Connect issue below.

    My solution was simply to implement empty versions of the inherited functions in my mock:

    TEST_F(SomeTest, SomethingIsDoneCorrectly)
    {
        class MockFstream : public std::fstream
        {
            void _Add_vtordisp1() { } // Required to avoid VC++ warning C4250
            void _Add_vtordisp2() { } // Required to avoid VC++ warning C4250
        };
        MockFstream lMockFstream;
        // Expectations and assertions here
    }
    

    An explanation from Microsoft about why the warning occurs:

    The story here is somewhat complicated. VC has an obscure compiler option, /vd2 (documented at http://msdn.microsoft.com/en-us/library/7sf3txa8.aspx), that fixes an obscure bug involving virtual base classes. By default, VC does something that’s slightly nonconformant to the C++ Standard. /vd2 changes VC’s behavior to be conformant, but this inherently affects class layout. (This layout difference is why the default hasn’t been changed to be conformant – that would break users attempting to mix code compiled with different major versions of VC. Our C++ Standard Library implementation forbids such mixing, but the compiler itself is somewhat more permissive.) So if users want /vd2, they have to compile everything that way.

    The twist is that the layout bug (which /vd2 fixes) affects iostreams, which uses virtual base classes, and our iostreams implementation has a separately compiled component (in msvcp100.dll/libcpmt.lib/etc.). When MS builds the STL’s DLL/LIB, they’re compiled the default way, without /vd2. As a result, people using /vd2 couldn’t use iostreams, or they’d get bizarre crashes. Yuck.

    So, we added the do-nothing virtual functions _Add_vtordisp1() and _Add_vtordisp2(). Their presence makes VC perform layout completely conformantly, regardless of /vd2 being used or not, and therefore makes iostreams usable both ways.

    _Add_vtordisp1() and _Add_vtordisp2() trigger warning C4250, talking about dominance. This warning is actually completely useless – it’s saying that the compiler will do exactly what the Standard requires it to do. Therefore, we suppress it in the STL’s headers (which must be /W4 /analyze clean). If you’re deriving from fstream, you’ll need to suppress this warning in your own code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using googlemock for unit tests and I try to mock a method that
I'm using Google Test and Google Mock frameworks for a project's unit tests. I
I am using google mock library in my unit tests, and I am trying
Using range() in Underscore I can make something like this: _.range(10); >> [0, 1,
After reading this , it sounds like a great idea to store files using
Using Visual Studio 2010 C++ with googlemock. I'm trying to use a mock I
using this code: Java Server side: ... out = new PrintWriter(this.client.getOutputStream(), true); ... public
In our project we are using Google Mock, but in multiple places we are
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using CI for the first time and i'm smashing my head with this seemingly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.