-
Notifications
You must be signed in to change notification settings - Fork 15.6k
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
cannot compile c++ generated code #8484
Comments
Do you see if there is a constexpr constructor for StringMsgDefaultTypeInternal in .pb.cc? |
Could you also paste the full error log? |
There is constexpr constructor, code compiles fine with msvc compiler, only clang-cl (both 11.1 or 12.0) thinks this message variable doesn't satisfy constinit restrictions introduced by PROTOBUF_CONSTINIT (guess it has problems with string type). |
https://godbolt.org/z/75rfhqY4E |
https://godbolt.org/z/j9nv47n5P |
Issue is isolated to |
We ran into the same problem.
I tried using protobuf 3.15.2 and 3.17.1 |
It seems to be an interaction between If I write:
then I think what's happening is that clang is following this behavior but since it also supports the We might want to disable the attribute in clang-for-windows. |
I also checked that if I compile with clang in C++20 mode, then |
I don't know about that. This works fine:
So it can do constant initialization for it, but it just chooses not to when |
I can confirm this issue with clang 12 on Windows.
This fixes the problem for me |
That was my solution. I changed line 571 of port_def.inc to: Same problem on Visual Studio 2019, clang-cl, Windows. |
Will make pull request as suggested by mmurrian, kinda suprised multiple versions were released in last 6 month and nobody was concerned with fact that library is producing not compilable code under msvc clang-cl environment. |
This should be fixed now with #8993. |
I am currently trying to build libquiche for windows with a cmake build and clang as compiler. |
Yey, this is getting ridiculous more and more. I made another pull request, it is not approved yet. #10232 |
@Eddie-cz: Thanks for making the new PR, it much better then mine, and yes using protocol buffers on windows is pretty complicated. |
Version: 3.15.8
Language: C++
Windows 10, MSVC 16.9.3 with clang-cl compiler (LLVM 11.1)
Message definition:
syntax = "proto3";
message StringMsg
{
string value = 1;
}
Compilation of generated pb.cc fails for this message with "error : variable does not have a constant initializer".
Compiles with repeated modifier.
Variable is:
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT StringMsgDefaultTypeInternal StringMsg_default_instance;
The text was updated successfully, but these errors were encountered: