Repository navigation
Fix a C++ build failure if the C++17 standard is used - #26359
Conversation
|
@hungptit Could you elaborate why this PR is the right fix? C++17 doesn't allow to use this? |
|
Great question @veblush. This is the only place in the grpc repo that uses |
|
Hmm i checked whether g++ 10.3 can compile the following code similar to the original code. Maybe this was caused by how the build is configured to use C++17. Can you let me how to reproduce this error? |
|
By default abseil aliases absl::optional to std::optional when building in c++ 17 mode. I ran into this same breakage when trying to update Envoy's grpc dependency to a recent grpc release. See envoyproxy/envoy#16687 |
Signed-off-by: Antonio Vicente <[email protected]>
|
@antoniovicente I want to understand why this code causes the breakage with C++17 mode. I checked the code above and it was compiled well. |
I don't understand the interaction. My attempts so far to do a standalone build of the grpc library haven't worked even with default settings. The compile failure seems to trigger in cases where abseil uses std::optional as an alias for absl::optional. This issue prevents dependent packages that build with C++ 17 from updating the grpc library dependency. |
|
@veblush Your concern is valid. The document of std::make_optional is incomplete and my explanation is not 100% correct. I think the move constructor of Tls is somehow not visible to clang++ and I do not have a clear answer for that. You can either try below struct or use this repository to reproduce the error. Let me know if you are unable to reproduce the issue. struct Tls {
Tls(Tls&& val) = delete;
std::string name;
std::string local_certificate;
std::string remote_certificate;
}; |
|
Hi, FWIW, I am also facing this issue and managed to create a minimum reproducible example of the build failure: see this godbolt link: https://godbolt.org/z/M17xc6YbE, which fails on clang (e.g. x86-64 clang 11.0.1) but works fine on gcc (e.g. x86-64 gcc 11.1). Really bizarre: I think this is a bug with clang (or a bug with the standard library, or maybe undefined behavior). |
|
Looks like it's a bug with the standard library (I would guess there's a problem with the implementation of EDIT: Sure enough: it's a known bug when clang, libstdc++, std::optional (used here since absl::optional is an alias for std::optional in >c++17), nested classes, and default member initialization are combined: https://bugs.llvm.org/show_bug.cgi?id=50346. I think the best workaround for this is to explicitly define the empty zero-parameter constructor, rather than relying on implicit generation, so: This makes |
|
@bijanoviedo Great! Thank you for the investigation and explanation. It's now clearly understandable. So this needs some workaround to detour this compiler issue. This can be either an assignment with the value which is suggested by this or having an explicit empty constructor to detour this issue. I think the latter would be clearer to say why this is written like this @hungptit Can you try to update the PR like above? |
|
@veblush Let lay out the pros and cons of both approaches then we can pick our solution. Using assignment operator Pros
Cons We use Adding a non-trivial constructor Pros Show that we need this workaround to bypass the compiler bug. Cons There are a couple of issues with this approach
Let me know your thought so we can merge this change ASAP? |
|
My $0.02: I think both solutions are fine and are certainly better than delaying getting this PR in, but another con of the "assignment operator" approach is that anyone in the future could do As an end user, I personally care more that each grpc release builds reliably than I care that the underlying code is idiomatic, but I do recognize the tradeoffs. |
|
@bijanoviedo Your points are valid. Let me do a quick update so we can merge this PR today. |
|
@hungptit Thank you for the update. @bijanoviedo I agree with your point. |
|
@veblush I cannot merge my changes. Can you merge it? |
|
@hungptit Sure I can do! Thank you! |
What is the issue?
Everything works fine if I compile gRPC using C++14, however, I could not build gRPC if the C++17 is used. Below is the build error:
The solution
Do not use
absl::make_optionaland we can assign thechannelz::SocketNode::Security::Tls()directly to the optional field, i.esecurity->tls.@donnadionne
@veblush