public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101781] New: make_unique generating a warning with -fanalyzer
@ 2021-08-04 20:04 deco33000 at yandex dot com
2021-08-05 11:07 ` [Bug analyzer/101781] " redi at gcc dot gnu.org
2021-08-06 11:18 ` deco33000 at yandex dot com
0 siblings, 2 replies; 3+ messages in thread
From: deco33000 at yandex dot com @ 2021-08-04 20:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101781
Bug ID: 101781
Summary: make_unique generating a warning with -fanalyzer
Product: gcc
Version: 11.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: deco33000 at yandex dot com
Target Milestone: ---
Hi,
given the following code
// Type your code here, or load an example.
#include <iostream>
#include <vector>
#include <memory>
using namespace std;
int main() {
auto res = make_unique<int>();
auto ptr = res.get();
if (ptr) {
*ptr = 5;
cout << *ptr << endl;
}
return 0;
}
I get warning: dereference of possibly-NULL 'operator new(4)' [CWE-690]
[-Wanalyzer-possible-null-dereference]
Whereas I check sufficiently not to dereference that pointer if not set.
Apparently, the compiler doesn't like that make_unique doesn't check the return
of new. Even then, the code avoiding make_unique:
int main() {
auto i = new int(0);
if (!i) {
return 1;
}
unique_ptr<int> res(i);
auto ptr = res.get();
if (!ptr) {
return 1;
}
*ptr = 5;
cout << *ptr << endl;
return 0;
}
Still gives the same warning.
try on Godbolt:
https://godbolt.org/z/8399T1511
and
https://godbolt.org/z/5jjM4E5Ec
Thanks
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug analyzer/101781] make_unique generating a warning with -fanalyzer
2021-08-04 20:04 [Bug c++/101781] New: make_unique generating a warning with -fanalyzer deco33000 at yandex dot com
@ 2021-08-05 11:07 ` redi at gcc dot gnu.org
2021-08-06 11:18 ` deco33000 at yandex dot com
1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2021-08-05 11:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101781
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The analyzer doesn't really support C++ yet.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug analyzer/101781] make_unique generating a warning with -fanalyzer
2021-08-04 20:04 [Bug c++/101781] New: make_unique generating a warning with -fanalyzer deco33000 at yandex dot com
2021-08-05 11:07 ` [Bug analyzer/101781] " redi at gcc dot gnu.org
@ 2021-08-06 11:18 ` deco33000 at yandex dot com
1 sibling, 0 replies; 3+ messages in thread
From: deco33000 at yandex dot com @ 2021-08-06 11:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101781
KL <deco33000 at yandex dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |WORKSFORME
--- Comment #2 from KL <deco33000 at yandex dot com> ---
Ok I will wait then. Thanks!
Solved
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-08-06 11:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-04 20:04 [Bug c++/101781] New: make_unique generating a warning with -fanalyzer deco33000 at yandex dot com
2021-08-05 11:07 ` [Bug analyzer/101781] " redi at gcc dot gnu.org
2021-08-06 11:18 ` deco33000 at yandex dot com
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).