public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108385] New: false positive -Wfree-nonheap-object
@ 2023-01-12 15:27 steveire at gmail dot com
  2023-01-12 16:39 ` [Bug tree-optimization/108385] " pinskia at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: steveire at gmail dot com @ 2023-01-12 15:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108385

            Bug ID: 108385
           Summary: false positive -Wfree-nonheap-object
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: steveire at gmail dot com
  Target Milestone: ---

Sorry I was not able to reduce this further. Changing almost anything makes the
bug no-longer reproduce:


```

#include <vector>
#include <cstdint>
#include <cstring>

class DataType {
 public:
  DataType() {
   }

  DataType get() const;

 private:
  double v = 0.0;
  char values[41];
};

class ptrType {
 public:
  DataType someMethod() const {
    DataType t;
    t = t.get();
    return t;
  }
};

class AnotherDataType {
 public:
  typedef uint32_t size_type;

  AnotherDataType() : _size(0), _data(new double[0]) {}

  explicit AnotherDataType(size_type size) : _size(size), _data(new
double[size]) {}

  virtual ~AnotherDataType() { delete[] _data; }

  uint32_t size() const { return _size; }

  double& operator()(size_type i) { return _data[i]; }

  AnotherDataType get(const AnotherDataType& b) const
  {
    AnotherDataType c(size());

    auto aItr = _data;
    auto cItr = c.begin();
    auto endp = _data + _size;

    for (; aItr != endp; ++aItr, ++cItr) {
      (*cItr) = (*aItr);
    }
    return c;
  }

  double sum() const {
    double sum = *_data;
    auto aItr = _data;
    for (; aItr != _data + _size; ++aItr) {
      sum = (*aItr);
    }
    return sum;
  }

  double* begin() { return _data; }

 private:
  size_type _size;
  double* _data;
};

AnotherDataType anotherMethod(const ptrType* ptrType1) {
  ptrType1->someMethod();
  return {};
}

struct otherStruct {
  const ptrType* ptrType1;
  std::vector<double> q1;
};

static double minF(otherStruct* params) {
  auto err = anotherMethod(params->ptrType1);

  return (err.get(err)).sum();
}

struct someStruct {
  double (*f)(otherStruct* params);
  otherStruct* params;
};

void foo(someStruct function) {
  std::vector<double> v;

  minF(function.params);
}

void why() {
  someStruct func;
  func.f = &minF;
  foo(func);
}
```

Godbolt link: https://godbolt.org/z/nqvsezj49

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

end of thread, other threads:[~2023-05-08 12:26 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-12 15:27 [Bug c++/108385] New: false positive -Wfree-nonheap-object steveire at gmail dot com
2023-01-12 16:39 ` [Bug tree-optimization/108385] " pinskia at gcc dot gnu.org
2023-01-12 16:44 ` pinskia at gcc dot gnu.org
2023-01-13  8:12 ` [Bug tree-optimization/108385] [12 Regression] " marxin at gcc dot gnu.org
2023-01-13  9:09 ` rguenth at gcc dot gnu.org
2023-01-13  9:13 ` rguenth at gcc dot gnu.org
2023-01-13  9:26 ` rguenth at gcc dot gnu.org
2023-01-13 20:59 ` amacleod at redhat dot com
2023-01-16  8:11 ` rguenth at gcc dot gnu.org
2023-01-31 14:58 ` cvs-commit at gcc dot gnu.org
2023-01-31 14:59 ` amacleod at redhat dot com
2023-02-01 15:02 ` amacleod at redhat dot com
2023-05-08 12:26 ` rguenth at gcc dot gnu.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).