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.
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

Reply via email to