https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109720
Bug ID: 109720
Summary: -Wmaybe-uninitialized triggering when I can see no
path that would allow it
Product: gcc
Version: 13.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: psmith at gnu dot org
Target Milestone: ---
I recently upgraded to GCC 13.1 and when building some code that uses
boost::dynamic_bitset I'm seeing the -Wmaybe-ininitialized warning triggering
when it's impossible for any object of the class to be created without the
m_num_bits field being initialized.
I've tried to reduce this without luck. Also if I do other, seemingly
irrelevant things then the warning goes away. I wonder if it's somehow related
to the placement new that we use for the union...?
I'll attach the postprocessed output.
Code:
DynamicBitSet set(200);
size_t setup(size_t ln)
{
size_t count = 0;
DynamicBitSet nbits(set);
for (auto bit: nbits) {
count += bit;
}
return count;
}
I checked and this also failed in GCC 11.3; maybe -Wall didn't used to include
this warning and now it does which is why I didn't notice it before?
Results:
$ /data/src/build/x86_64-linux/bin/x86_64-rl84-linux-gnu-g++
-I/data/src/build/common/boost/include -std=gnu++20 -Wmaybe-uninitialized -O2
-c -o /tmp/bitset.o /tmp/bitset.i
In member function 'boost::dynamic_bitset<Block, Allocator>::size_type
boost::dynamic_bitset<Block, Allocator>::size() const [with Block = long
unsigned int; Allocator = std::allocator<long unsigned int>]',
inlined from 'boost::dynamic_bitset<Block, Allocator>::size_type
boost::dynamic_bitset<Block, Allocator>::find_next(size_type) const [with Block
= long unsigned int; Allocator = std::allocator<long unsigned int>]' at
/tmp/bitset.i:70473:30,
inlined from 'DynamicBitSet::size_type DynamicBitSet::find_next(size_type)
const' at /tmp/bitset.i:77301:44,
inlined from 'DynamicBitSet::Iterator&
DynamicBitSet::Iterator::operator++()' at /tmp/bitset.i:77325:38,
inlined from 'size_t setup(size_t)' at /tmp/bitset.i:77340:20:
/tmp/bitset.i:70355:12: warning: '*(const boost::dynamic_bitset<long unsigned
int, std::allocator<long unsigned int> >*)((char*)&nbits +
offsetof(DynamicBitSet,
DynamicBitSet::<unnamed>)).boost::dynamic_bitset<>::m_num_bits' may be used
uninitialized [-Wmaybe-uninitialized]
70355 | return m_num_bits;
| ^~~~~~~~~~
/tmp/bitset.i: In function 'size_t setup(size_t)':
/tmp/bitset.i:77339:19: note: 'nbits' declared here
77339 | DynamicBitSet nbits(set);
| ^~~~~