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

Activate compiler warnings on unused parameters #697

Closed
ricab opened this issue Mar 27, 2019 · 3 comments · Fixed by #757
Closed

Activate compiler warnings on unused parameters #697

ricab opened this issue Mar 27, 2019 · 3 comments · Fixed by #757

Comments

@ricab
Copy link
Collaborator

ricab commented Mar 27, 2019

We currently add -Wno-unused-parameter in cmake. This makes it easy to leave unused parameters around, sometimes propagating them to a lot of code.

For instance, there is an unused grpc::ServerContext* parameter that is propagated from the Rpc to all daemon handling methods and beyond (this particular case is currently being fixed in #682).

@townsend2010
Copy link
Contributor

I'm not sure we want to do this because DaemonRpc still overrides the Rpc::Service class and ServerContext is not used there as well.

@ricab
Copy link
Collaborator Author

ricab commented Mar 27, 2019

The warning is perfectly compatible with external signatures that can't be changed (it would be pretty useless otherwise) Actually, I think that is when it is most useful.

What you do in those cases is simply not name the parameter. For instance, DaemonRpc would declare:

grpc::Status create(grpc::ServerContext*, const CreateRequest* request,
                    grpc::ServerWriter<CreateReply>* reply) override;
...

This immediately indicates, both to the compiler and the reader, that the parameter is not used. And it actually prevents it from being used inadvertently (like passing it around, as happened there).

IOW, the warning exists to promote an explicit decision: you either detect the param is a leftover and should be removed, or explicitly indicate it needs to be maintained as part of the signature even though it is not used.

In the cases when one feels the param name conveys relevant information even when unused, that information can be put in a comment. It is not the case in the current example, as the name simply repeats what the type already says, but if it were, one should do simply

grpc::Status create(grpc::ServerContext* /*context*/, const CreateRequest* request,
                    grpc::ServerWriter<CreateReply>* reply) override;
...

@townsend2010
Copy link
Contributor

@ricab,

Ok, thanks for the explanation and makes perfect sense.

@ricab ricab self-assigned this Apr 30, 2019
ricab added a commit that referenced this issue Apr 30, 2019
Fixes #697. Keeps deactivation for gRPC. Causes compilation to fail
until current errors are fixed.
bors bot added a commit that referenced this issue May 2, 2019
757: Warn unused param r=gerboland a=ricab

Activates unused parameter warnings. Fixes all such cases, homogenizing implicated code.

Fixes #697 

Co-authored-by: Ricardo Abreu <[email protected]>
townsend2010 pushed a commit that referenced this issue May 2, 2019
757: Warn unused param r=gerboland a=ricab

Activates unused parameter warnings. Fixes all such cases, homogenizing implicated code.

Fixes #697

Co-authored-by: Ricardo Abreu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants