https://bugs.kde.org/show_bug.cgi?id=391772
Bug ID: 391772 Summary: Memcheck reports conditional jumps if I use raw pointer, but not for std::vector Product: valgrind Version: 3.12.0 Platform: RedHat RPMs OS: Linux Status: UNCONFIRMED Severity: normal Priority: NOR Component: memcheck Assignee: jsew...@acm.org Reporter: ravi.kappiy...@gmail.com Target Milestone: --- Consider the following code: #include <functional> #include <iostream> #include <vector> class A { public: A(int const & val) : test(val) {} int getTest() const { return test.get(); } private: std::reference_wrapper<int const> test; }; std::vector<A> a; void func() { a.push_back(A{2}); } int main() { func(); std::cout << a.back().getTest() << std::endl; } This code is compiled with the following: g++ -g -std=c++14 test.cpp -o a.out Here, the function `func` adds a new object of type `A` to the `std::vector<A>` `a`. However, in doing so, it binds a reference_wrapper to a temporary (`std::reference_wrapper<int const> test` is bound to the integer literal `2`), and, as such, any attempt to use that member variable (such as the print statement in `main`) should result in a memory error. When I run this program under memcheck, however, memcheck reports no errors. If I simply replace `std::vector<A> a;` with `A *a;` (and change `func` to `a = new A(2);`, and the print statement to `std::cout << a->getTest() << std::endl;`), and run that executable with memcheck, I get the expected warnings regarding uninitialized variables. It appears then, that somehow, the use of std::vector is causing memcheck to get confused. -- You are receiving this mail because: You are watching all bug changes.