Skip to content

Conversation

@bjeurissen
Copy link
Member

Replaces deprecated unique() (https://en.cppreference.com/w/cpp/memory/shared_ptr/unique) with use_count() == 1 (https://en.cppreference.com/w/cpp/memory/shared_ptr/use_count.html). Avoids deprecation warnings on modern compilers.

@github-actions
Copy link

clang-tidy review says "All clean, LGTM! 👍"

@daljit46
Copy link
Member

I'm not opposed to this change as a temporary solution, but as mentioned in #2894, perhaps we should take a moment to check why we need this in the first place.

@bjeurissen
Copy link
Member Author

bjeurissen commented Oct 14, 2025

I'm not opposed to this change as a temporary solution, but as mentioned in #2894, perhaps we should take a moment to check why we need this in the first place.

The main purpose of this change would be to silence the deprecation warnings on recent compilers and avoid compilation failures on even newer ones.

As far as I can tell .use_count()==1 and .unique() are identical, apart from the deprecation (warning). This also means that it does not alleviate potential issues with unique() in multi-threaded environments.

@daljit46
Copy link
Member

The main purpose of this change would be to silence the deprecation warnings on recent compilers and avoid compilation failures on even newer ones.

Yes, I understand, but I think the compiler warnings and the deprecation of unique() point out that we should not rely on these functions. Substituting with use_count() == 1 just sweeps the issue under the rug without having to deal with the problem.

@bjeurissen
Copy link
Member Author

That is exactly what I meant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants