[odb-users] gcc 13.2: vector.ixx: warning: ‘i’ may be used uninitialized

Siegmund, Harald Harald.Siegmund at isotravel.com
Thu Sep 5 09:11:39 EDT 2024


gcc 13.2 seems to be more sensitive when recognizing potentially uninitialized variables and prints a warning when inserting elements into an odb::vector.

/usr/local/include/odb/vector.ixx:246:20: warning: ‘i’ may be used uninitialized [-Wmaybe-uninitialized]
  246 |       impl_.insert (i, v_.size () - n);
      |       ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
/usr/local/include/odb/vector.ixx: In static member function […]
/usr/local/include/odb/vector.ixx:236:15: note: ‘i’ was declared here
  236 |     size_type i, n;
      |               ^

The code from vector.ixx:

  template <class T, class A LIBODB_VECTOR_ARG_DECL>
  template <class I>
  inline void vector<T, A LIBODB_VECTOR_ARG_USE>::
  insert (iterator p, I f, I l)
  {
    size_type i, n;
    if (_tracking ())
    {
      i = static_cast<size_type> (p.base () - v_.begin ());
      n = v_.size ();
    }

    v_.insert (p.base (), f, l);

    if (_tracking ())
      impl_.insert (i, v_.size () - n);
  }

I can see the compiler's point: Function _tracking() could hypothetically return different results in each invocation, so IMHO the warning message is appropriate.
It would be nice if you could change that piece of code to get rid of the warning.

$ gcc --version
gcc (Ubuntu 13.2.0-23ubuntu4) 13.2.0
$ odb --version
ODB object-relational mapping (ORM) compiler for C++ 2.5.0-b.27



More information about the odb-users mailing list