Skip to content

Conversation

@PiotrNycz
Copy link
Contributor

Fixed issue: 2471

@sbenzaquen
Copy link
Collaborator

Please include a test that triggers the bug and gets fixed with this change.

@kuzkry
Copy link
Contributor

kuzkry commented Oct 22, 2019

How is he going to test non-compiling code? It isn't run-time.

@sbenzaquen
Copy link
Collaborator

You can use decltype testing to evaluate the validity of an expression.
Similar to how std::is_detected is meant to work (but we can't use that because it is not available in C++11).

Example:

template <typename T, typename = decltype(ReturnRef(std::declval<T&&>()))>
bool CanCallReturnRef(T&&) { return true; }
bool CanCallReturnRef(Unused) { return false; }

...
int i = 0;
EXPECT_TRUE(CanCallReturnRef(i));
EXPECT_FALSE(CanCallReturnRef(i + 1));

@kuzkry
Copy link
Contributor

kuzkry commented Oct 22, 2019

Ah, ok. I know this trick. Though I think the standard way of doing this is by using void_t, isn't it?

@sbenzaquen
Copy link
Collaborator

Ah, ok. I know this trick. Though I think the standard way of doing this is by using void_t, isn't it?

void_t is not available in C++11, but you can do without it too.

@PiotrNycz
Copy link
Contributor Author

"POD" is not really a relevant concept since C++11.
Also, this bug was not related to pod-ness afaik. POD structs would still have triggered the bug.

You are right. The difference is between basic (integral) types and more complex classes. I'll change that (the names).

@PiotrNycz
Copy link
Contributor Author

This is redundant with CanCallReturnRef.
We should only have one.
Is HasReturnRefAction giving something that CanCallReturnRef wasn't?

IMHO HasReturnRefAction adding more information to these tests - it is somehow easier to get the difference. But if you think it is redundant I can remove it, no problem at all.

@sbenzaquen
Copy link
Collaborator

This is redundant with CanCallReturnRef.
We should only have one.
Is HasReturnRefAction giving something that CanCallReturnRef wasn't?

IMHO HasReturnRefAction adding more information to these tests - it is somehow easier to get the difference. But if you think it is redundant I can remove it, no problem at all.

I see it as a different way of asking the same question.

@PiotrNycz
Copy link
Contributor Author

This is redundant with CanCallReturnRef.
We should only have one.
Is HasReturnRefAction giving something that CanCallReturnRef wasn't?

IMHO HasReturnRefAction adding more information to these tests - it is somehow easier to get the difference. But if you think it is redundant I can remove it, no problem at all.

I see it as a different way of asking the same question.

Ok, I'll remove HasReturnRefAction with next commit.

@kuzkry
Copy link
Contributor

kuzkry commented Oct 25, 2019

Do we really need 6 commits for that? :D I suggest squashing them all into one.

@gennadiycivil gennadiycivil self-assigned this Oct 25, 2019
@gennadiycivil
Copy link
Contributor

Thank you, we have started internal review. Please don't push any more changes into this PR as they might be overwritten.
(276737278)

vslashg added a commit that referenced this pull request Oct 28, 2019
…tore_temporaries_2

PiperOrigin-RevId: 277061341
vslashg added a commit that referenced this pull request Oct 29, 2019
…tore_temporaries_2

PiperOrigin-RevId: 277061341
vslashg added a commit that referenced this pull request Oct 29, 2019
…tore_temporaries_2

PiperOrigin-RevId: 277061341
@vslashg vslashg merged commit 208c2f6 into google:master Oct 29, 2019
@PiotrNycz PiotrNycz deleted the gmock_prevent_return_ref_to_store_temporaries_2 branch October 30, 2019 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants