Skip to content

Commit

Permalink
async_promise_type possibly unitialized value
Browse files Browse the repository at this point in the history
The std::variant for callback or future/promise with gcc-13 seems to be
triggering an uninitialized value warning. We can tell it isn't
uninitialized but the compiler seems to be thinking the 2nd type in the
variant, which is the callback type, is unitialized _when_ the promise
type, 3rd type in the variant, is the one being initialized.

Closes #153
  • Loading branch information
jbaldwin committed Oct 3, 2024
1 parent 8582dbd commit 9a9ada6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
15 changes: 12 additions & 3 deletions inc/lift/request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ class request
return std::make_unique<request>(std::move(url), std::move(timeout));
}

request(const request&) = default;
request(request&&) = default;
request(const request&) = default;
request(request&&) = default;
auto operator=(const request&) noexcept -> request& = default;
auto operator=(request&&) noexcept -> request& = default;
auto operator=(request&&) noexcept -> request& = default;

/**
* Synchronously executes this request.
Expand Down Expand Up @@ -538,7 +538,16 @@ class request
*/
auto async_future() -> async_future_type
{
// gcc-13 is incorrectly thinking the 2nd type in the async_handlers_type is uninitialized.
// Its correct since it isn't used on this code path, but it isn't a warning/error.
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
m_on_complete_handler.m_object = {async_promise_type{}};
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
return std::get<async_promise_type>(m_on_complete_handler.m_object.value()).get_future();
}

Expand Down
7 changes: 7 additions & 0 deletions src/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ auto executor::prepare() -> void

switch (m_request->method())
{
default:
/* INTENTIONAL FALLTHROUGH */
case http::method::unknown: // default to GET on unknown/bad value.
/* INTENTIONAL FALLTHROUGH */
case http::method::get:
Expand Down Expand Up @@ -103,6 +105,8 @@ auto executor::prepare() -> void

switch (m_request->version())
{
default:
/* INTENTIONAL FALLTHROUGH */
case http::version::unknown: // default to USE_BEST on unknown/bad value.
/* INTENTIONAL FALLTHROUGH */
case http::version::use_best:
Expand Down Expand Up @@ -223,6 +227,9 @@ auto executor::prepare() -> void
{
switch (auth_type)
{
default:
// CURLAUTH_BASIC is the default per docs https://curl.se/libcurl/c/CURLOPT_PROXYAUTH.html.
/* INTENTIONAL FALLTHROUGH */
case http_auth_type::basic:
auth_types |= CURLAUTH_BASIC;
break;
Expand Down

0 comments on commit 9a9ada6

Please sign in to comment.