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 8427679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:50:39+00:00 2026-06-10T04:50:39+00:00

gmock does not support rvalue reference as parameter of mocked function ( issue report

  • 0

gmock does not support rvalue reference as parameter of mocked function (issue report).

For example the following code will not compile:

MOCK_METHOD1(foo,void(std::string&&));

I can’t find information on when gmock will add support to this.

  • 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-10T04:50:41+00:00Added an answer on June 10, 2026 at 4:50 am

    I figured out a workaround: use a non-mocked function foo(std::string&& s){foo_rvr(s)} to relay the function to a mocked function foo_rvr(std::string). Here is the complete program.

    #include <string>
    #include <gtest/gtest.h>
    #include <gmock/gmock.h>
    
    class RvalueRef
    {
    public:
        virtual void foo(const std::string&)=0;
        virtual void foo(std::string&&)=0;
    };
    
    class MockRvalueRef : public RvalueRef
    {
    public:
        void foo(std::string&& s){foo_rvr(s);}
        MOCK_METHOD1(foo,void(const std::string&));
        MOCK_METHOD1(foo_rvr,void(std::string));
    };
    
    TEST(RvalueRef, foo)
    {
        MockRvalueRef r;
        {
            ::testing::InSequence sequence;
            EXPECT_CALL(r,foo("hello"));
            EXPECT_CALL(r,foo_rvr("hi"));
        }
    
        std::string hello("hello");
        r.foo(hello);
        r.foo("hi");    
    }
    
    int main(int argc, char* argv[])
    {
        ::testing::InitGoogleMock(&argc,argv);
    
        int rc=RUN_ALL_TESTS();
    
        getchar();
        return rc;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using gmock for unit testing C++ code . I am not using
I have a sudden issue in Production code which was not happening since the
I wrote the following piece of code to test Xyz::xyz_func by mocking Abc::abc_func using
I am using gmock in my project and I meet a problem to set
I'm using GMock to add some unit testing to our existing Java projects. We
I find that when running multiple gmock tests using and in memory database I
Using Visual Studio 2010 C++ with GMock. Trying to create a stub object for
I asked this question on the Google Group but I think I will get
Has anyone successfully built gmock and gtest in Visual Studio 2010? I've tried with
I'm playing around with gmock and noticed it contains this line: #include <tuple> I

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.