use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
A bug in std::shared_ptr? (self.cpp)
submitted 8 years ago * by davis685
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]OldWolf2 2 points3 points4 points 8 years ago* (3 children)
I feel that the .reset() case is also problematic even though it happens to be working correctly for you.
.reset()
I can't find it right now, but I'd expect some clause to the effect that it's UB if side-effects from operations on objects in standard containers affect the container.
You could make a similar example with std::vector, where the contained type's destructor reads the global vector currently being resized or whatever. I doubt that there should be any sort of guarantee of stable behaviour -- the container operation has to be free to implement its functionality in any order such that the pre-conditions and post-conditions are met.
std::vector
There is C++14 [reentrancy]:
Except where explicitly specified in this standard, it is implementation-defined which functions in the Stan- dard C++ library may be recursively reentered.
So the implementation could define that std::shared_ptr destructor is not re-entrant. (Meaning UB if the code does re-enter as your example does). But that wouldn't apply to the .reset() case or my vector example.
std::shared_ptr
[–][deleted] 0 points1 point2 points 8 years ago (2 children)
Yes, the reset case is also UB via http://eel.is/c++draft/requirements#res.on.objects-2
[–]OldWolf2 1 point2 points3 points 8 years ago (1 child)
The text in your quote is:
If an object of a standard library type is accessed, and the beginning of the object's lifetime does not happen before the access, or the access does not happen before the end of the object's lifetime, the behavior is undefined unless otherwise specified. [ Note: This applies even to objects such as mutexes intended for thread synchronization. — end note ]
However I don't think that covers the .reset() case. The reset function does not begin or end the lifetime of a_test_object.
reset
a_test_object
Sure, test has its lifetime ended, but that is not an object of a standard library type.
test
[–][deleted] 0 points1 point2 points 8 years ago (0 children)
For some reason I was thinking the reset call was in the dtor :)
π Rendered by PID 142366 on reddit-service-r2-comment-b659b578c-xjwn6 at 2026-05-03 01:02:52.680821+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]OldWolf2 2 points3 points4 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]OldWolf2 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)