Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Latest commit

 

History

History
33 lines (24 loc) · 2.07 KB

c26410.md

File metadata and controls

33 lines (24 loc) · 2.07 KB
description title ms.date f1_keywords helpviewer_keywords ms.assetid
Learn more about: Warning C26410 NO_REF_TO_CONST_UNIQUE_PTR
Warning C26410
07/21/2017
C26410
NO_REF_TO_CONST_UNIQUE_PTR
C26410
d1547faf-96c6-48da-90f5-841154d0e878

Warning C26410

The parameter 'parameter' is a reference to const unique pointer, use const T* or const T& instead (r.32)

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.

Remarks

  • 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 that defines either operator-> or operator*. A copy-able type (shared pointer) must have either a public copy constructor or an overloaded assignment operator that deals with a non-Rvalue reference parameter.

  • Template code may produce noisy warnings. 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.

Code analysis name: NO_REF_TO_CONST_UNIQUE_PTR

Example

Unnecessary reference:

std::vector<std::unique_ptr<Tree>> roots = GetRoots();
std::for_each(
    roots.begin(),
    roots.end(),
    [](const auto &root) { Rebalance(root.get()); });   // C26410