googletest
googletest copied to clipboard
SetArrayArgument regression with array reference
trafficstars
Describe the bug
In previous versions of gmock SetArrayArgument could be used with array references. In newer version it is compile error. Tested passing: 1.8.0 Tested failing: 1.11.0
Steps to reproduce the bug
Godbolt simple reproducer: https://gcc.godbolt.org/z/6Tbsja473
Simple reproducer:
#include "gmock/gmock.h"
#include <array>
using ::testing::_;
using ::testing::SetArrayArgument;
class TestMock {
public:
TestMock(){
ON_CALL(*this, fooArray(_)).WillByDefault(SetArrayArgument<0>(vals.begin(), vals.end())); // works fine
ON_CALL(*this, fooArrayReference(_)).WillByDefault(SetArrayArgument<0>(vals.begin(), vals.end())); // compile error. Works on gmock 1.8.0
}
MOCK_METHOD1(fooArray, void(uint8_t v [8]));
MOCK_METHOD1(fooArrayReference, void(uint8_t(&v)[8]));
std::array<uint8_t, 8> vals;
};
Compilation error:
In file included from <source>:1:
In file included from /opt/compiler-explorer/libs/googletest/trunk/googlemock/include/gmock/gmock.h:57:
/opt/compiler-explorer/libs/googletest/trunk/googlemock/include/gmock/gmock-actions.h:1129:14: error: read-only variable is not assignable
*value = *it;
~~~~~~ ^
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.0/../../../../include/c++/12.0.0/bits/invoke.h:61:14: note: in instantiation of function template specialization 'testing::internal::SetArrayArgumentAction<0, unsigned char *, unsigned char *>::operator()<unsigned char [8]>' requested here
{ return std::forward<_Fn>(__f)(std::forward<_Args>(__args)...); }
^
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.0/../../../../include/c++/12.0.0/bits/std_function.h:451:35: note: in instantiation of member function 'std::_Function_handler<void (unsigned char (&)[8]), testing::internal::SetArrayArgumentAction<0, unsigned char *, unsigned char *>>::_M_invoke' requested here
_M_invoker = &_My_handler::_M_invoke;
^
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.0/../../../../include/c++/12.0.0/bits/std_function.h:534:4: note: in instantiation of function template specialization 'std::function<void (unsigned char (&)[8])>::function<testing::internal::SetArrayArgumentAction<0, unsigned char *, unsigned char *>, void>' requested here
function(std::forward<_Functor>(__f)).swap(*this);
^
/opt/compiler-explorer/libs/googletest/trunk/googlemock/include/gmock/gmock-actions.h:505:10: note: in instantiation of function template specialization 'std::function<void (unsigned char (&)[8])>::operator=<testing::internal::SetArrayArgumentAction<0, unsigned char *, unsigned char *>>' requested here
fun_ = ::std::forward<G>(g);
^
/opt/compiler-explorer/libs/googletest/trunk/googlemock/include/gmock/gmock-actions.h:470:5: note: in instantiation of function template specialization 'testing::Action<void (unsigned char (&)[8])>::Init<testing::internal::SetArrayArgumentAction<0, unsigned char *, unsigned char *>>' requested here
Init(::std::forward<G>(fun), IsCompatibleFunctor<G>());
^
<source>:12:60: note: in instantiation of function template specialization 'testing::Action<void (unsigned char (&)[8])>::Action<testing::internal::SetArrayArgumentAction<0, unsigned char *, unsigned char *>, void>' requested here
ON_CALL(*this, fooArrayReference(_)).WillByDefault(SetArrayArgument<0>(vals.begin(), vals.end())); // compile error
^
1 error generated.
Compiler returned: 1
Compiler Explorer uses cookies and other related techs to serve you