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 unreachable code warning in buffers_cat.hpp #2803

Conversation

ashtum
Copy link
Collaborator

@ashtum ashtum commented Jan 19, 2024

It seems we can't simply assume that the code for past_end::operator*() will never compile, as the following code clearly needs to handle that case:

return mp11::mp_with_index<
    sizeof...(Bn) + 2>(
        it_.index(), // Considering the index is a runtime value, the compiler needs to generate code for when it points to `past_end`
        dereference{*this});

Fixes #2678

Copy link

codecov bot commented Jan 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (6adca47) 93.01% compared to head (9c773e7) 93.04%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2803      +/-   ##
===========================================
+ Coverage    93.01%   93.04%   +0.02%     
===========================================
  Files          178      178              
  Lines        13688    13688              
===========================================
+ Hits         12732    12736       +4     
+ Misses         956      952       -4     
Files Coverage Δ
include/boost/beast/core/impl/buffers_cat.hpp 98.42% <100.00%> (ø)

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6adca47...9c773e7. Read the comment docs.

@vinniefalco
Copy link
Member

Interesting, is this why we keep getting that damn warning !?

@ashtum
Copy link
Collaborator Author

ashtum commented Jan 21, 2024

Interesting, is this why we keep getting that damn warning !?

I believe so. The reason we are getting those warnings is that the returned net::mutable_buffer from the past_end::operator* function (which is marked unreachable) implicitly converts to net::const_buffer. For example, the following generates the warning:
https://godbolt.org/z/83G5f4Wx7

auto buf = buffers_cat(net::const_buffer{}, net::const_buffer{});
auto it  = buf.begin();
*it;

However, this doesn't:
https://godbolt.org/z/WePad646W

auto buf = buffers_cat(net::mutable_buffer{}, net::mutable_buffer{});
auto it  = buf.begin();
*it;

This is quite comparable to this example:
https://godbolt.org/z/8fMroWh54

[[noreturn]] const char * f1()
{
  __assume(false);
}

const char * f2()
{
  return f1(); // Fine
}

std::string f3()
{
  return f1(); // warning C4702: unreachable code
}

MSVC is correctly warning us that we are doing something after unreachable code (in this case, the implicit conversion is what we are doing).

@ashtum ashtum merged commit 3b837c6 into boostorg:develop Jan 22, 2024
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

unreachable code in asio/buffer.hpp with optimizations
2 participants