uNetworking / uWebSockets

Simple, secure & standards compliant web server for the most demanding of applications
Apache License 2.0
17.43k stars 1.76k forks source link

Compilation warning [-Wunused-parameter] and [-Wmissing-field-initializers] #1070

Closed xamix closed 4 years ago

xamix commented 4 years ago

Hello,

I compile your library with GCC 9.2.1 on Ubuntu. There are lots of warning with -Wunused-parameter for example:

.../uwebsockets/include/HttpParser.h: In static member function ‘static unsigned int uWS::HttpParser::getHeaders(char*, char*, uWS::HttpRequest::Header*, uWS::BloomFilter*)’:
.../uwebsockets/include/HttpParser.h:150:121: warning: unused parameter ‘bf’ [-Wunused-parameter]
  150 |     static unsigned int getHeaders(char *postPaddedBuffer, char *end, struct HttpRequest::Header *headers, BloomFilter *bf) {

.../uwebsockets/include/HttpContext.h:64:83: warning: unused parameter ‘is_client’ [-Wunused-parameter]
   64 |         us_socket_context_on_open(SSL, getSocketContext(), [](us_socket_t *s, int is_client, char *ip, int ip_length) {
      |                                                                               ~~~~^~~~~~~~~
.../uwebsockets/include/HttpContext.h:64:100: warning: unused parameter ‘ip’ [-Wunused-parameter]
   64 |         us_socket_context_on_open(SSL, getSocketContext(), [](us_socket_t *s, int is_client, char *ip, int ip_length) {
      |                                                                                              ~~~~~~^~
.../uwebsockets/include/HttpContext.h:64:108: warning: unused parameter ‘ip_length’ [-Wunused-parameter]
   64 |         us_socket_context_on_open(SSL, getSocketContext(), [](us_socket_t *s, int is_client, char *ip, int ip_length) {
      |                                                                                                        ~~~~^~~~~~~~~

Also there are some others warning with -Wmissing-field-initializers:

.../uwebsockets/include/HttpRouter.h:64:7: warning: missing initializer for member ‘uWS::HttpRouter<uWS::HttpContextData<false>::RouterData>::Node::children’ [-Wmissing-field-initializers]
   64 |     } root = {"rootNode"};
      |       ^~~~
.../uwebsockets/include/HttpRouter.h:64:7: warning: missing initializer for member ‘uWS::HttpRouter<uWS::HttpContextData<false>::RouterData>::Node::handlers’ [-Wmissing-field-initializers]
.../uwebsockets/include/HttpRouter.h:64:7: warning: missing initializer for member ‘uWS::HttpRouter<uWS::HttpContextData<false>::RouterData>::Node::isHighPriority’ [-Wmissing-field-initializers]
      [...]

Maybe I can work on it (comment the unused parameters) in order to remove the -Wunused-parameter warning

For the -Wmissing-field-initializers maybe check if you want some default values on unitialized fields?

Regards

dvergeylen commented 4 years ago

Apart from solving these warnings, you can get rid of them by considering µWebSockets as a system library, via the -isystem flag. Gcc won't emit these warning messages as it considers you can't do anything about it.

From man gcc:

The -isystem and -idirafter options also mark the directory as a system directory,
so that it gets the same special treatment that is applied to the standard system directories.
ghost commented 4 years ago

You can use clang-tidy to automatically fix these warnings:

http://clang.llvm.org/extra/clang-tidy/checks/misc-unused-parameters.html

but they are not really bugs or issues, so priority is about as low as can be (esp. given they are not turned on in default compilations).

ghost commented 4 years ago

I never got clang-tidy to work properly, it made changes I don't agree with and seemed wrong. If you want to manually comment out unused parameters, you can start with that and PR that alone. I will merge such a change.

ghost commented 4 years ago

Closing, you can send a PR