public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108089] New: False positive for -Wfree-nonheap-object when using std::variant
@ 2022-12-13 19:09 falemagn at gmail dot com
2022-12-13 19:11 ` [Bug c++/108089] " falemagn at gmail dot com
2022-12-13 20:46 ` redi at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: falemagn at gmail dot com @ 2022-12-13 19:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108089
Bug ID: 108089
Summary: False positive for -Wfree-nonheap-object when using
std::variant
Product: gcc
Version: 12.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: falemagn at gmail dot com
Target Milestone: ---
The following is the most reduced example I could come up with.
#include <variant>
#include <string>
#include <vector>
using variant = std::variant<
std::string,
std::vector<char>
>;
extern std::size_t &ext_index;
void func() {
ext_index = variant(std::string()).index();
}
"ext_index" being a reference is all it takes to trigger the issue. If it'd be
an object, the issue would not triggered. The issue would be triggered also if
ext_index were a pointer.
As far as I could tell, ff "std::string" is substituted with a type whose
destructor doesn't involve any deallocation, then the issue is not triggered.
The issue is also not triggered if std::string is substituted with another
std::vector specialization.
You can see it all on godbolt: https://godbolt.org/z/aaxY1jW1q
This is the error (unecessary lines removed):
In member function 'void std::__new_allocator<_Tp>::deallocate(_Tp*,
size_type) [with _Tp = char]',
inlined from 'static void
std::allocator_traits<std::allocator<_CharT> >::deallocate(allocator_type&,
pointer, size_type) [with _Tp = char]' at /opt/compiler-explorer/gcc-12.1.0/
[...]
inlined from 'std::variant<_Types>::~variant() [with _Types =
{std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>
>, std::vector<char, std::allocator<char> >}]' at
/opt/compiler-explorer/gcc-12.1.0/include/c++/12.1.0/variant:1407:28,
inlined from 'void func()' at <source>:14:17:
/opt/compiler-explorer/gcc-12.1.0/include/c++/12.1.0/bits/new_allocator.h:158:33:
error: 'void operator delete(void*, std::size_t)' called on unallocated object
'<anonymous>' [-Werror=free-nonheap-object]
158 | _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(__p,
__n));
| ^
<source>: In function 'void func()':
<source>:14:38: note: declared here
14 | ext_index = variant(std::string()).index();
| ^
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/108089] False positive for -Wfree-nonheap-object when using std::variant
2022-12-13 19:09 [Bug c++/108089] New: False positive for -Wfree-nonheap-object when using std::variant falemagn at gmail dot com
@ 2022-12-13 19:11 ` falemagn at gmail dot com
2022-12-13 20:46 ` redi at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: falemagn at gmail dot com @ 2022-12-13 19:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108089
Fabio Alemagna <falemagn at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to work| |11.3.0
Known to fail| |12.1.0
--- Comment #1 from Fabio Alemagna <falemagn at gmail dot com> ---
To be noted that the issue doesn't happen on gcc v11.3.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/108089] False positive for -Wfree-nonheap-object when using std::variant
2022-12-13 19:09 [Bug c++/108089] New: False positive for -Wfree-nonheap-object when using std::variant falemagn at gmail dot com
2022-12-13 19:11 ` [Bug c++/108089] " falemagn at gmail dot com
@ 2022-12-13 20:46 ` redi at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2022-12-13 20:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108089
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |DUPLICATE
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
.
*** This bug has been marked as a duplicate of bug 108088 ***
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-12-13 20:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-13 19:09 [Bug c++/108089] New: False positive for -Wfree-nonheap-object when using std::variant falemagn at gmail dot com
2022-12-13 19:11 ` [Bug c++/108089] " falemagn at gmail dot com
2022-12-13 20:46 ` redi 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).