Opened 7 years ago
Last modified 7 years ago
#11879 new Bugs
Incorrect use of reset cause unexpected impact on previous code segment
Reported by: | anonymous | Owned by: | Peter Dimov |
---|---|---|---|
Milestone: | To Be Determined | Component: | smart_ptr |
Version: | Boost 1.57.0 | Severity: | Problem |
Keywords: | Cc: |
Description
#include <boost/scoped_ptr.hpp> #include <iostream>
int main() {
boost::scoped_ptr<int> p{new int{1}}; std::cout << *p << '\n'; std::cout << p.get() << '\n'; p.reset(new int{2}); std::cout << *p.get() << '\n'; std::cout << p.get() << '\n';
p.reset((int *)4); Problem: Because of this statement std::cout of above lines are not printing anything. When this line is commented the program works fine. I understand I have used reset function incorrectly but it should impact to the next statements but it is also impacting above statements too. Please explain the cause.
std::cout << *p.get() << '\n'; std::cout << p.get() << '\n';
p.reset(); std::cout << std::boolalpha << static_cast<bool>(p) << '\n';
}
Change History (6)
comment:1 by , 7 years ago
comment:3 by , 7 years ago
Version: | Boost 1.61.0 → Boost 1.57.0 |
---|
comment:4 by , 7 years ago
std::cout is buffered. You'll get the result you expect, if you add a flush before the incorrect code.
comment:5 by , 7 years ago
Component: | None → smart_ptr |
---|---|
Owner: | set to |
I forgot to use wiki formatting. Comment start is missing from the statement p.reset((int *)4);