-
Notifications
You must be signed in to change notification settings - Fork 660
Fix uninitialized variable #3019
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
base: develop
Are you sure you want to change the base?
Conversation
Error manifests when using GCC 15.1 with the following flags '-Wall Werror=uninitialized -fhardened'
d3dc2d5
to
834ba23
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #3019 +/- ##
========================================
Coverage 93.11% 93.11%
========================================
Files 176 176
Lines 13643 13647 +4
========================================
+ Hits 12704 12708 +4
Misses 939 939
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
The following is minimal reproducible example of the same warning: #include <boost/beast.hpp>
using namespace boost;
std::uint16_t
fun(
asio::const_buffer const& cb,
system::error_code& ec)
{
if(cb.size() < 2)
return 0;
ec = {}; // commenting this line resolves warning
std::uint16_t result;
asio::buffer_copy(
asio::mutable_buffer(&result, sizeof(result)),
cb);
return endian::big_to_native(result);
}
It seems the compiler thinks assigning to |
For the record, I couldn't get the compiler to reason correctly about #include <boost/beast.hpp>
using namespace boost;
std::uint16_t
fun(
asio::const_buffer const& cb,
system::error_code& ec)
{
if(cb.size() < 2)
return 0;
ec = {};
if(beast::buffer_bytes(cb) < 2) __builtin_unreachable();
std::uint16_t result;
asio::buffer_copy(
asio::mutable_buffer(&result, sizeof(result)),
cb);
return endian::big_to_native(result);
} |
These warnings are only triggered when a combination of `-Wmaybe-uninitialized` and `-ftrivial-auto-var-init=zero` is used with GCC 14.2 or later.
44bc18a
to
bc1fcf4
Compare
An automated preview of the documentation is available at https://3019.beast.prtest.cppalliance.org/libs/beast/doc/html/index.html |
Have run into a very peculiar error on GCC 15.1 which only manifests when using with the following flags
'-Wall Werror=uninitialized -fhardened' and only under Release mode compilation.
The -fhardened flag is critical, as without it the compiler will happily compile the code. No idea what trips the compiler, but the fix is trivial.
The issue is reproducible on the WebSocket server, asynchronous example.
The full compiler output is as follows: