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

Fix -Wundefined-inline error when using SharedCtor() or SharedDtor() #8532

Merged

Conversation

georgthegreat
Copy link
Contributor

@georgthegreat georgthegreat commented Apr 26, 2021

protoc marks SharedCtor and SharedDtor as inline in .h file being generated, but does not define them in this header.
An attempt to use these symbols causes compiler to issue -Wundefined-inline warning / error if -Werror is enabled.

@google-cla google-cla bot added the cla: yes label Apr 26, 2021
@georgthegreat
Copy link
Contributor Author

georgthegreat commented Apr 26, 2021

NB: I do not know if there is any procedure behind pregenerated .pb.h files update for well known types.
I have just used sed to fix them.

@acozzette acozzette merged commit a48e005 into protocolbuffers:master Apr 28, 2021
@acozzette
Copy link
Member

Thanks @georgthegreat

@georgthegreat georgthegreat deleted the fix-undefined-inline branch April 30, 2021 10:27
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants