Trouble setting default ON_CALL Return value for const string & method: error: size of array is negative

1,666 views
Skip to first unread message

doug livesey

unread,
Sep 8, 2012, 7:19:19 AM9/8/12
to googl...@googlegroups.com
Hi -- I'm trying to stub the value of a const string & method, but it fails to compile with the following error:
  In file included from gmock/include/gmock/gmock.h:58:0,
                   from test/include/mocks/mocks.h:3,
                   from test/persistence/creator_test.cpp:1:
  gmock/include/gmock/gmock-actions.h: In instantiation of 'testing::internal::ReturnAction<R>::operator testing::Action<Func>() const [with F = const std::basic_string<char>&(); R = std::basic_string<char>]':
  test/persistence/creator_test.cpp:158:80:   required from here
  gmock/include/gmock/gmock-actions.h:469:5: error: size of array is negative
  gmock/include/gmock/gmock-actions.h: In instantiation of 'class testing::internal::ReturnAction<std::basic_string<char> >::Impl<const std::basic_string<char>&()>':
  gmock/include/gmock/gmock-actions.h:472:41:   required from 'testing::internal::ReturnAction<R>::operator testing::Action<Func>() const [with F = const std::basic_string<char>&(); R = std::basic_string<char>]'
  test/persistence/creator_test.cpp:158:80:   required from here
  gmock/include/gmock/gmock-actions.h:496:5: error: size of array is negative
  rake aborted!
  Command failed with status (1): [g++-mp-4.7 -c -Igmock/include -Igmock/gtes...]

I've cobbled together a file containing the code that's generating it as best I can -- the offending bit seems to be the call to WillByDefault() on line 74 (in my cobbled-together example file) -- if I comment that bit out (keeping the ON_CALL bit), it compiles just fine.

If anyone could help me, here, I'd be very grateful -- I'm obviously missing something pretty fundamental, but I've no idea what it is & have been chasing myself in futile circles with it for ages.
Thanks,
   Doug.

doug livesey

unread,
Sep 8, 2012, 7:28:47 AM9/8/12
to googl...@googlegroups.com
Sorry! I *promise* I spent ages on this before posting, but on re-reading (for the nth time) the docs, I came across mention of a little function called ReturnRef, and that has solved my problem.
Cheers,
   Doug.

Patricio Astudillo

unread,
Aug 6, 2014, 3:57:53 AM8/6/14
to googl...@googlegroups.com
Thank-you-so-freakin-much!! For updating your post!

Op zaterdag 8 september 2012 13:29:08 UTC+2 schreef doug livesey:
Reply all
Reply to author
Forward
0 new messages