Fix -Wundefined-inline error when using SharedCtor() or SharedDtor()#8532
Merged
acozzette merged 1 commit intoprotocolbuffers:masterfrom Apr 28, 2021
Merged
Conversation
Contributor
Author
|
NB: I do not know if there is any procedure behind pregenerated .pb.h files update for well known types. |
|
Thanks @georgthegreat |
georgthegreat
added a commit
to georgthegreat/protobuf
that referenced
this pull request
Jul 19, 2021
Apparentle, protocolbuffers#8532 was incorrect if applied to 3.17.x branch. 3.17.x changed code generation to mark SharedCtor and SharedDtor as inline in .pb.cc. It looks like we have a compile-time undefined behavior in C++ now. As cppreferences [says](https://en.cppreference.com/w/cpp/language/inline): _The definition of an inline function or variable (since C++17) must be reachable in the translation unit where it is accessed (not necessarily before the point of access). _ As protobuf allows custom plugins to generate custom code, there is no limitation on where SharedCtor couble be possible referenced from. In our case we have SharedCtor invoked from corresponding `.pb.h` code, thus triggering: ``` ld: error: undefined symbol: package::Message::SharedCtor()` >>> referenced by file.pb.h:$$$$ ``` If this patch is not applicable, I can take a look into changing the code generation, but doing this will be harder then removing _inline_.
georgthegreat
added a commit
to georgthegreat/protobuf
that referenced
this pull request
Jul 20, 2021
Apparently, protocolbuffers#8532 was incorrect if applied to 3.17.x branch. 3.17.x changed code generation to mark `SharedCtor()` and `SharedDtor()` as inline in .pb.cc. It looks like we have a compile-time undefined behavior in C++ now. As cppreference.com [says](https://en.cppreference.com/w/cpp/language/inline): _The definition of an inline function <...> must be reachable in the translation unit where it is accessed (not necessarily before the point of access)._ As protobuf allows custom plugins to generate custom code, there is no limitation on where SharedCtor couble be possible referenced from. In our case we have SharedCtor invoked from corresponding `.pb.h` code, thus triggering: ``` ld: error: undefined symbol: package::Message::SharedCtor()` >>> referenced by file.pb.h:$$$$ ``` If this patch is not applicable, I can take a look into changing the code generation, but doing this will be harder then removing _inline_.
acozzette
pushed a commit
that referenced
this pull request
Jul 29, 2021
* Fix undefined symbol error around SharedCtor() Apparently, #8532 was incorrect if applied to 3.17.x branch. 3.17.x changed code generation to mark `SharedCtor()` and `SharedDtor()` as inline in .pb.cc. It looks like we have a compile-time undefined behavior in C++ now. As cppreference.com [says](https://en.cppreference.com/w/cpp/language/inline): _The definition of an inline function <...> must be reachable in the translation unit where it is accessed (not necessarily before the point of access)._ As protobuf allows custom plugins to generate custom code, there is no limitation on where SharedCtor couble be possible referenced from. In our case we have SharedCtor invoked from corresponding `.pb.h` code, thus triggering: ``` ld: error: undefined symbol: package::Message::SharedCtor()` >>> referenced by file.pb.h:$$$$ ``` If this patch is not applicable, I can take a look into changing the code generation, but doing this will be harder then removing _inline_. * Regenerate checked-in generated .pb.cc files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
protoc marks SharedCtor and SharedDtor as inline in
.hfile being generated, but does not define them in this header.An attempt to use these symbols causes compiler to issue
-Wundefined-inlinewarning / error if-Werroris enabled.