This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/70096] New: [Invalid codegen] Read of uninitialized value in ref-qualified pointer to member function
- From: "ldionne.2 at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 05 Mar 2016 18:42:09 +0000
- Subject: [Bug c++/70096] New: [Invalid codegen] Read of uninitialized value in ref-qualified pointer to member function
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70096
Bug ID: 70096
Summary: [Invalid codegen] Read of uninitialized value in
ref-qualified pointer to member function
Product: gcc
Version: 6.0
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ldionne.2 at gmail dot com
Target Milestone: ---
The following code has a codegen issue that causes the read of an uninitialized
value, which can lead to a segfault in some circumstances:
struct Holder {
void operator()() & { int read = data; }
int data;
};
template <typename F = void()&>
void test() {
Holder h{42};
F Holder::* fptr = &Holder::operator();
(h.*fptr)();
}
int main() {
test();
}
> g++ -std=c++11 test/worksheet.cpp
> valgrind --leak-check=full --track-origins=yes ./a.out
==44102== Memcheck, a memory error detector
[...]
==44102== Use of uninitialised value of size 8
==44102== at 0x100000EE6: Holder::operator()() & (in ./a.out)
==44102== by 0x100000F26: void test<void () &>() (in ./a.out)
==44102== by 0x100000ED2: main (in ./a.out)
==44102== Uninitialised value was created by a stack allocation
==44102== at 0x100000F2A: void test<void () &>() (in ./a.out)
I'm not sure, but I think it has something to do with the fact that we're
using `F = void() &` (note the ref-qualifier) and the reading of the `this`
pointer. I'm not sure at all, but just pointing out a possible direction.
Live example: http://melpon.org/wandbox/permlink/kzRh8PNguwrP11lB