-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MockFunction improvements #2319
Conversation
It seems the change 3d70a6b (Add MockFunction::AsLambda (#2278)) will not build since it contains: template <typename R, typename... Args>
class MockFunction<R(Args...)> {
/* ... */
auto AsLambda() {
return [this](Args... args) -> R {
return this->Call(std::forward<Args>(args)...);
};
}
/* ... */
}; This form of If this cannot be changed (seems reasonable to not require too much) then the code either would have to use preprocessor for providing I was using CMake while developing. (I tried the Bazel but didn't understand it at all...) This means that probably CMake is under-configured by not being strict on the language standard as use. Otherwise, I would see the error immediately. If C++11 is indeed the required standard I will try to update CMake correspondingly. |
This seems more complicated. The main if (CMAKE_VERSION VERSION_LESS "3.1")
add_definitions(-std=c++11)
else()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(NOT CYGWIN)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
endif() It seems to be an issue between CMake and Visual C++, even though I have recent versions of both (3.14.0 and 19.21.27702.2 respectively) and this Visual C++ does support specifying language standard. Maybe the issue is that it does not support specifying C++11, only C++14 or higher. The C++11 config does work with Cygwin. |
gmock-spec-builders.h uses std::function (in MockFunction) but did not include <functional> to provide it. Apparently, it worked since the header must have been included by something else but better be safe than sorry.
Use of the = default instead of {} provides some advantages like proper constexpr or noexcept support. Furthermore, it keeps the type aggregate and trivial if it otherwise would be. MockFunction doesn’t truly benefit from those. However, it doesn’t also lose anything on using = default instead of {}. While it does add uniformity, follows guidelines (for example Chromium style guide), and protects against eager static checkers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw. recently there's been some rename of GoogleMock docs but your change should easily rebase onto it.
|
||
std::function<R(Args...)> AsStdFunction() { | ||
return [this](Args... args) -> R { | ||
return this->Call(std::forward<Args>(args)...); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and other std::forwards won't forward anything. args
can never be variadic universal references here as they are not function template parameters. Imo, std::move works better here (as it will try to move, unless not possible (l-refs and nonmovable types)).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Firstly, note that I haven't written it so. I only moved it a bit. It was so before.
Secondly, I think you are not right about it anyway. This was originally std::move
back in time when the class was still located in gmock-generated-function-mockers.h
but was corrected to std::forward
by 7796273 related to #1867.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry then, thanks for a good reference to another PR.
Thank your for this contribution. Could you please elaborate and provide more information on exactly the issue / problems this is trying to address. |
Well, it was rebased over the |
Essentially there are three changes here:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw. recently there's been some rename of GoogleMock docs but your change should easily rebase onto it.
Well, it was rebased over the
HEAD
until your changes got merged in. ;)
It's only a kind conflict reminder of mine ;)
|
||
std::function<R(Args...)> AsStdFunction() { | ||
return [this](Args... args) -> R { | ||
return this->Call(std::forward<Args>(args)...); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry then, thanks for a good reference to another PR.
@adambadura Thank you for this request. There are too many things going on at the same time here. |
No description provided.