What is going on: C++ std::move on std::shared_ptr increases use_count?

What is going on, here?

On MacOS, it seems that you must explicitly enable move-sematics with -std=c++11 (or later standards)¹. Otherwise, the example happens to compile (i.e., std::shared_ptr from the related library implementation is usable) but doesn’t work correctly as the required language features aren’t enabled. This results in actual copies being made instead of move constructions. It would have been better if the AppleClang package didn’t even allow an instantiation of std::shared_ptr when the required language features isn’t enabled.

¹) Thanks to @t.niese for testing the given compiler/platform.

Leave a Comment

tech