public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "steveire at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/108385] New: false positive -Wfree-nonheap-object Date: Thu, 12 Jan 2023 15:27:53 +0000 [thread overview] Message-ID: <bug-108385-4@http.gcc.gnu.org/bugzilla/> (raw) 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
next reply other threads:[~2023-01-12 15:27 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-01-12 15:27 steveire at gmail dot com [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-108385-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).