Skip to content

Latest commit

 

History

History
29 lines (23 loc) · 805 Bytes

compiler-warning-level-1-c4172.md

File metadata and controls

29 lines (23 loc) · 805 Bytes
description title ms.date f1_keywords helpviewer_keywords ms.assetid
Learn more about: Compiler Warning (level 1) C4172
Compiler Warning (level 1) C4172
11/04/2016
C4172
C4172
a8d2bf65-d8b1-4fe3-8340-a223d7e7fde6

Compiler Warning (level 1) C4172

returning address of local variable or temporary

A function returns the address of a local variable or temporary object. Local variables and temporary objects are destroyed when a function returns, so the address returned is not valid.

Redesign the function so that it does not return the address of a local object.

The following sample generates C4172:

// C4172.cpp
// compile with: /W1 /LD
float f = 10;

const double& bar() {
// try the following line instead
// const float& bar() {
   return f;   // C4172
}