description | title | ms.date | ms.topic | f1_keywords | helpviewer_keywords | ms.assetid | ||
---|---|---|---|---|---|---|---|---|
Learn more about: C26410 NO_REF_TO_CONST_UNIQUE_PTR |
C26410 |
07/21/2017 |
conceptual |
|
|
d1547faf-96c6-48da-90f5-841154d0e878 |
Generally, references to const unique pointer are meaningless. They can safely be replaced by a raw reference or a pointer. This warning enforces C++ Core Guidelines rule R.32.
-
Unique pointer checks have rather broad criteria to identify smart pointers. The C++ Core Guidelines rule R.31: If you have non-std smart pointers, follow the basic pattern from std describes the unique pointer and shared pointer concepts. The heuristic is simple, but may lead to surprises: a smart pointer type is any type which defines either operator-> or operator*; a copy-able type (shared pointer) must have either public copy constructor or overloaded assignment operator which deals with a non-R-value reference parameter.
-
Template code may produce a lot of noise. Keep in mind that templates can be instantiated with various type parameters with different levels of indirection, including references. Some warnings may not be obvious and fixes may require some rework of templates (for example, explicit removal of reference indirection). If template code is intentionally generic, the warning can be suppressed.
std::vector<std::unique_ptr<Tree>> roots = GetRoots();
std::for_each(
roots.begin(),
roots.end(),
[](const auto &root) { Rebalance(root.get()); }); // C26410