Skip to content
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

Windows compilation of RetryStateImpl::shouldHedgeRetryPerTryTimeout impl fails #7736

Closed
wrowe opened this issue Jul 26, 2019 · 6 comments · Fixed by #7930
Closed

Windows compilation of RetryStateImpl::shouldHedgeRetryPerTryTimeout impl fails #7736

wrowe opened this issue Jul 26, 2019 · 6 comments · Fixed by #7930

Comments

@wrowe
Copy link
Contributor

wrowe commented Jul 26, 2019

Windows compilation using MSBuild 15.9, we cannot get this simple line of code, introduced two months ago, to compile;

return shouldRetry([]() -> bool { return true; }, callback);

source/common/router/retry_state_impl.cc(228): error C2664: 'Envoy::Router::RetryStatus Envoy::Router::RetryStateImpl::shouldRetry(bool,Envoy::Router::RetryState::DoRetryCallback)': cannot convert argument 1 from 'Envoy::Router::RetryStateImpl::shouldHedgeRetryPerTryTimeout::<lambda_f5b81d16bf43f4b112188693c10b6098>' to 'bool'
source/common/router/retry_state_impl.cc(228): note: Ambiguous user-defined-conversion

@mattklein123
Copy link
Member

@wrowe FWIW, I would just submit PRs to fix any Windows compile issues as I'm pretty sure you are the only person compiling on Windows. :)

@wrowe
Copy link
Contributor Author

wrowe commented Jul 26, 2019

Thanks @mattklein123, those that we can resolve we will escalate strait to a PR. Why this compilation is failing is a mystery to me, so far. Looking for extra C++ savvy eyeballs.

@wrowe
Copy link
Contributor Author

wrowe commented Aug 2, 2019

Ping; still looking for a c++ guru to suggest how Win32 CL.exe fails to interpret this correctly.

@zuercher
Copy link
Member

zuercher commented Aug 2, 2019

Given

RetryStatus RetryStateImpl::shouldRetry(bool would_retry, DoRetryCallback callback)

It seems that we're passing a lamba to a function that takes a bool. And I guess gcc and clang implicitly convert it and MSVC doesn't? Seems like the line should just be shouldRetry(true, callback).

@mergeconflict
Copy link
Member

I agree with @zuercher, we should just be passing true to shouldRetry, which raises the question of why other compilers accept this code. I think it's because the lambda expression is converted to a std::function<bool()>, which has an explicit operator bool that, for some reason I can't explain, is being used. Try this experiment:

#include <iostream>

void foo(bool b) {
  std::cout << b << std::endl;
}

int main(int argc, char** argv) {
  foo([]() -> bool { return false; });
}

With clang, this prints 1 regardless of the false in the lambda.

@zuercher
Copy link
Member

I'm going to go ahead and submit a PR to fix this, since it makes me anxious, even if it works.

zuercher added a commit to zuercher/envoy that referenced this issue Aug 14, 2019
Per envoyproxy#7736, we're inadvertently casting a lambda expression to
bool. Fortunately, the code is attempting to pass true, so it
works.

Risk Level: low
Testing: n/a
Docs Changes: n/a
Release Notes: n/a
Fixes: envoyproxy#7736

Signed-off-by: Stephan Zuercher <zuercher@gmail.com>
mattklein123 pushed a commit that referenced this issue Aug 15, 2019
Per #7736, we're inadvertently casting a lambda expression to
bool. Fortunately, the code is attempting to pass true, so it
works.

Risk Level: low
Testing: n/a
Docs Changes: n/a
Release Notes: n/a
Fixes: #7736

Signed-off-by: Stephan Zuercher <zuercher@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants