Skip to content

Latest commit

 

History

History
49 lines (36 loc) · 1.69 KB

c26444.md

File metadata and controls

49 lines (36 loc) · 1.69 KB
title description ms.date f1_keywords helpviewer_keywords
Warning C26444
Learn more about: Warning C26444 NO_UNNAMED_RAII_OBJECTS.
05/11/2023
C26444
NO_UNNAMED_RAII_OBJECTS
C26444

Warning C26444

Don't try to declare a local variable with no name (es.84).

C++ Core Guidelines

ES.84: Don't (try to) declare a local variable with no name

An unnamed variable declaration creates a temporary object that is discarded at the end of the statement. Such temporary objects with nontrivial behavior may point to either inefficient code that allocates and immediately throws away resources or to the code that unintentionally ignores nonprimitive data. Sometimes it may also indicate plainly wrong declaration.

Remarks

  • This rule detects types with a hand-written destructor or a compiler-generated destructor that transitively calls a hand-written destructor.
  • This rule can flag code that invokes a nontrivial constructor of a RAII type.
  • The logic skips temporaries if they're used in higher-level expressions. One example is temporaries that are passed as arguments or used to invoke a function.

Code analysis name: NO_UNNAMED_RAII_OBJECTS

Examples

struct A { A(int i); ~A(); };
void Foo()
{
    A{42}; // warning C26444: Don't try to declare a local variable with no name (es.84).
}

To fix the issue, convert the temporary object to a local.

struct A { A(int i); ~A(); };
void Foo()
{
    A guard{42}; // OK.
}

See also

C26441
ES.84: Don't (try to) declare a local variable with no name