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 Wpedantic warning 'extra ;' for c++ #10385

Merged
merged 10 commits into from
Aug 17, 2022

Conversation

marjoleinheyndrickx
Copy link
Contributor

Fixing a few "extra ‘;’ [-Wpedantic]" I got when compiling with gcc 10.3.0. This is simply removal of a few extra semicolons, does not affect the functionality of anything.
This is in c++

@google-cla
Copy link

google-cla bot commented Aug 10, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@marjoleinheyndrickx
Copy link
Contributor Author

I signed the CLA now. I can not seem to add labels but would like to add "c++" and probably "release notes:no".

@@ -615,7 +615,7 @@ class PROTOBUF_EXPORT Descriptor : private internal::SymbolBase {
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Descriptor);
};

PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(Descriptor, 136);
PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(Descriptor, 136)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix this macro to not end with a ; instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The macro is defined empty:
#if !defined(PROTOBUF_INTERNAL_CHECK_CLASS_SIZE) #define PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(t, expected) #endif

which means the double ; comes from the fact that we have a regular statement before the macro, then emptyness (the macro) and then another ; after that.

Copy link
Contributor Author

@marjoleinheyndrickx marjoleinheyndrickx Aug 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see that the removal of the ; from my patch would be problematic for anyone who has defined PROTOBUF_INTERNAL_CHECK_CLASS_SIZE as something which has content but doesn't end in ;
If it is the case that this macro is actually used, this pull request should probably be rejected or the macro definition there adapted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could change the empty definition to

do {} while (false)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the macro's are used outside of a function scope, a regular function calling or piece of code won't compile there ("expected constructor, destructor, or type conversion before ';' token"). Putting an empty class or struct definition is also not possible since the macro is used multiple times so then you get redefinition errors.
The macro seems like something used internally by google, is that correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can change them to static_assert(true, "") which will be valid at all scopes.

marjoleinheyndrickx and others added 7 commits August 11, 2022 12:56
* Disabling upb tests in python_cpp builds

* Adding comment about upb
* Reverting changes to ruby aarch64 build.

* Adding IN_DOCKER environment variable to prevent codegen

* Pass the cmake-built protoc to the ruby runner
…ocolbuffers#10393)

* Upgrade third_party/googletest submodule to current main branch

We can finally do this upgrade now that we have dropped our autotools
build. Googletest recommends living at head, so let's go straight to the
most recent commit on main. For some reason the googletest archive is
not present in the Bazel build mirror, so I removed that entry and just
left the GitHub download link in our WORKSPACE file.

Googletest now requires C++14, so I updated all the C++11 flags I could
find to C++14 instead. I added a .bazelrc file to add -std=c++14 for all
our Bazel builds.

* Delete the empty //src/google/protobuf:protobuf_test target

* Avoid building C++ unit tests in aarch64 jobs for Python and Ruby
@marjoleinheyndrickx
Copy link
Contributor Author

I changed the macro as suggested

@fowles
Copy link
Contributor

fowles commented Aug 16, 2022

Thanks for the PR. I will merge this after our CI system processes it.

@killerbot242
Copy link

killerbot242 commented Aug 17, 2022

can somebody please explain what the purpose is of this empty macro, it seems rather strange, and added value for now is negative it creates problems, and why are there even still macros in use ? Wouldn't it be better if such a bad habit would be removed completely ?

@fowles fowles merged commit 4dbf4e5 into protocolbuffers:main Aug 17, 2022
@fowles
Copy link
Contributor

fowles commented Aug 17, 2022

@killerbot242 the macro is not empty inside google's codebase. We use it to verify invariants that we don't externalize

bithium pushed a commit to bithium/protobuf that referenced this pull request Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants