public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109720] New: -Wmaybe-uninitialized triggering when I can see no path that would allow it
@ 2023-05-03 20:40 psmith at gnu dot org
  2023-05-03 20:56 ` [Bug tree-optimization/109720] " psmith at gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: psmith at gnu dot org @ 2023-05-03 20:40 UTC (permalink / raw)
  To: gcc-bugs

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);
      |                   ^~~~~

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-05-15 21:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-03 20:40 [Bug c++/109720] New: -Wmaybe-uninitialized triggering when I can see no path that would allow it psmith at gnu dot org
2023-05-03 20:56 ` [Bug tree-optimization/109720] " psmith at gnu dot org
2023-05-03 20:59 ` pinskia at gcc dot gnu.org
2023-05-03 21:39 ` psmith at gnu dot org
2023-05-03 21:58 ` pinskia at gcc dot gnu.org
2023-05-04 11:28 ` rguenth at gcc dot gnu.org
2023-05-04 13:23 ` psmith at gnu dot org
2023-05-15 21:44 ` psmith at gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).