On Thu, Sep 26, 2024 at 2:57 AM Jonathan Wakely via Gcc-bugs <gcc-bugs@gcc.gnu.org> wrote: > > On 26/09/24 04:44 +0000, Jason Mancini wrote: > >Problem happens in 14.2.0, 13.2.0, 12.2.0 > >Doesn't seem to happen in 10.2.0 or 11.2.0 > >Only seems to happen for -std=c++17/14/11, but not for c++20/23/26. > >Only seems to happen for -O2, but not -O0 / -O1 / -O3. > >Happens for vector, but not deque or list. > >Happens for vector<enum>, but not vector<int>. > >Doesn't happen if the enum is declared outside the function. > >Doesn't happen with clang++. > >Issue replicates on godbolt. > > The gcc-bugs mailing list is for automated email from our Bugzilla > database, not for reporting (or asking about) bugs. Emails sent to > this list will often be overlooked, missed, or just ignored. > > This particular problem is a false positive warning (which you've > turned into an error with -Werror, so the solution is to not do that). > > I don't think this false positive is already known, so it would be > great if you could report it as a bug, please see > https://gcc.gnu.org/bugs/
Just a quick follow up, I see Jason did submit a bug report https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116851 . I have not looked into it yet but I suspect it is related to how jump threading is done and then the warning is done way after jump threading and there just happens to be a path somehow that has become a nullptr. Thanks, Andrew > > Thanks! > > > > > >Thanks, > >Jason Mancini > > > >============== > > > >g++ -c source.cc -Werror=nonnull -std=c++17 -O2 > > > >============== > > > >#include <vector> > >void f(bool p) > >{ > > enum e { e1 }; > > std::vector<e> v; > > if (p) { v = { e1 }; } > > else { v = { e1 }; } > >} > > > >======= or even ======= > > > >#include <vector> > >void f(bool p) > >{ > > enum e { }; > > std::vector<e> v; > > if (p) { v = { }; } > > else { v = { }; } > >} > > > >============== > > > >In file included from (...)/gcc-14.2.0/include/c++/14.2.0/vector:62, > > from source.cc:1: > >In static member function 'static _Up* std::__copy_move<_IsMove, true, > >std::random_access_iterator_tag>::__copy_m(_Tp*, _Tp*, _Up*) [with _Tp = > >const f(bool)::e; _Up = f(bool)::e; bool _IsMove = false]', > > inlined from '_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove > > = false; _II = const f(bool)::e*; _OI = f(bool)::e*]' at > > (...)/gcc-14.2.0/include/c++/14.2.0/bits/stl_algobase.h:521:30, > > inlined from '_OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove > > = false; _II = const f(bool)::e*; _OI = f(bool)::e*]' at > > (...)/gcc-14.2.0/include/c++/14.2.0/bits/stl_algobase.h:548:42, > > inlined from '_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = > > false; _II = const f(bool)::e*; _OI = f(bool)::e*]' at > > (...)/gcc-14.2.0/include/c++/14.2.0/bits/stl_algobase.h:555:31, > > inlined from '_OI std::copy(_II, _II, _OI) [with _II = const > > f(bool)::e*; _OI = f(bool)::e*]' at > > (...)/gcc-14.2.0/include/c++/14.2.0/bits/stl_algobase.h:651:7, > > inlined from 'void std::vector<_Tp, > > _Alloc>::_M_assign_aux(_ForwardIterator, _ForwardIterator, > > std::forward_iterator_tag) [with _ForwardIterator = const f(bool)::e*; _Tp > > = f(bool)::e; _Alloc = std::allocator<f(bool)::e>]' at > > (...)/gcc-14.2.0/include/c++/14.2.0/bits/vector.tcc:343:19: > >(...)/gcc-14.2.0/include/c++/14.2.0/bits/stl_algobase.h:452:30: error: > >argument 1 null where non-null expected [-Werror=nonnull] > > 452 | __builtin_memmove(__result, __first, sizeof(_Tp) * _Num); > > | ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > >(...)/gcc-14.2.0/include/c++/14.2.0/bits/stl_algobase.h:452:30: note: in a > >call to built-in function 'void* __builtin_memmove(void*, const void*, long > >unsigned int)' > > > >============== > >EOM > > >