uNetworking / uWebSockets

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

MessageMetadata has no user-provided default constructor #1125

Closed lshamis closed 3 years ago

lshamis commented 3 years ago

The following program fails to compile:

#include <App.h>

int main() {
  struct Unused {};
  uWS::App app;
  app.ws<Unused>("/", uWS::App::WebSocketBehavior{});
}

Compiler output:

INFO: From Compiling example.cc:
In file included from external/uwebsockets/src/WebSocket.h:24:0,
                 from external/uwebsockets/src/HttpResponse.h:30,
                 from external/uwebsockets/src/App.h:25,
                 from example.cc:1:
external/uwebsockets/src/WebSocketContextData.h: In instantiation of 'uWS::WebSocketContextData<<anonymous> >::WebSocketContextData()::<lambda(uWS::Subscriber*, std::pair<std::basic_string_view<char>, std::basic_string_view<char> >)> [with bool SSL = false]':
external/uwebsockets/src/WebSocketContextData.h:73:41:   required from 'struct uWS::WebSocketContextData<<anonymous> >::WebSocketContextData() [with bool SSL = false]::<lambda(struct uWS::Subscriber*, struct std::pair<std::basic_string_view<char>, std::basic_string_view<char> >)>'
external/uwebsockets/src/WebSocketContextData.h:144:6:   required from 'uWS::WebSocketContextData<<anonymous> >::WebSocketContextData() [with bool SSL = false]'
external/uwebsockets/src/WebSocketContext.h:388:9:   required from 'static uWS::WebSocketContext<<anonymous>, <anonymous> >* uWS::WebSocketContext<<anonymous>, <anonymous> >::create(uWS::Loop*, us_socket_context_t*) [with bool SSL = false; bool isServer = true]'
external/uwebsockets/src/App.h:143:69:   required from 'uWS::TemplatedApp<SSL>&& uWS::TemplatedApp<SSL>::ws(std::string, uWS::TemplatedApp<SSL>::WebSocketBehavior&&) [with UserData = main()::Unused; bool SSL = false; std::string = std::basic_string<char>]'
example.cc:6:52:   required from here
external/uwebsockets/src/WebSocketContextData.h:38:12: note: 'struct uWS::WebSocketContextData<false>::MessageMetadata' has no user-provided default constructor
     struct MessageMetadata {
            ^~~~~~~~~~~~~~~
external/uwebsockets/src/WebSocketContextData.h:39:22: note: and the implicitly-defined constructor does not initialize 'unsigned int uWS::WebSocketContextData<false>::MessageMetadata::length'
         unsigned int length;
                      ^~~~~~

This was built with: uwebsockets at commit 2d65df86c7988f5d9afa826cfbceda332f06f6a4 usockets at commit 7683672d87067cd75b854f4e36b9820f4809a4be

but the same error occurs going back at least v18.3.0

This was tested with the default gcc on Ubuntu Bionic (gcc version 7.5.0)

ghost commented 3 years ago

This is not an error - do you compile with warnings as errors?

ghost commented 3 years ago
external/uwebsockets/src/WebSocketContextData.h:39:22: note: and the implicitly-defined constructor does not initialize 'unsigned int uWS::WebSocketContextData<false>::MessageMetadata::length'
         unsigned int length;
                      ^~~~~~

That's the culprit. But this is totally allowed.

lshamis commented 3 years ago

I've gone through and confirmed that you fully populate all instances of MessageMetadata before reading the values, so no uninitialized-memory issues.

@alexhultman are you open to PRs that cleanup warnings?

Thanks, and we can close this.

ghost commented 3 years ago

All warnings (not pedantic) should be fixed, but not at the cost of adding overhead.

ghost commented 3 years ago

GCC 9 does not show this warning in -Wextra

ghost commented 3 years ago

Neither does Clang 10

ghost commented 3 years ago

Fixed on master