http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57199



Paul Pluzhnikov <ppluzhnikov at google dot com> changed:



           What    |Removed                     |Added

----------------------------------------------------------------------------

             Status|RESOLVED                    |REOPENED

         Resolution|INVALID                     |



--- Comment #2 from Paul Pluzhnikov <ppluzhnikov at google dot com> 2013-05-08 
12:55:31 UTC ---

> Thus, the warning, while not 100% helpful, points at a real problem.



There is no real problem in the original source, which reads:



  size_t s = size();

  if (n < s)

    DestroyElements(mutable_array() + n, s - n);

  else ...



and produces the same warning.



Here is updated test with above condition; confirmed to still show the warning

with trunk @r198709.







typedef decltype(sizeof(0)) size_t;



struct Foo {

  ~Foo();      // comment out -> problem disappears

  int x[20];

};



template <typename T, int N>

struct InlinedVector {

  inline InlinedVector() : size_(0) { }

  inline size_t size() const {

    return size_;

  }

  T* mutable_array();

  void resize(size_t n) {

    size_t s = size();

    if (n < s)

      DestroyElements(mutable_array() + n, s - n);

  }

  static void DestroyElements(T* ptr, size_t num) {

    for (size_t i = 0; i < num; i++) {

      ptr[i].~T();

    }

  }



  size_t size_;

};



struct CP {

  void Add();

  InlinedVector<Foo,1> foo_;

};



void CP::Add() {

  foo_.resize(foo_.size() + 1);

}

Reply via email to