From 24bd1baa3abd4cdc8cb8192382fc2df7602f656d Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Fri, 20 Jun 2025 18:11:54 +0800 Subject: [PATCH 1/4] Add blockquotes for C4172 warning message --- .../compiler-warnings/compiler-warning-level-1-c4172.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4172.md b/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4172.md index 45e27ccfbd..3131aa03a7 100644 --- a/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4172.md +++ b/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4172.md @@ -8,7 +8,7 @@ ms.assetid: a8d2bf65-d8b1-4fe3-8340-a223d7e7fde6 --- # Compiler Warning (level 1) C4172 -returning address of local variable or temporary +> 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. From 9bc3a15a52b729ecfe28aca5be2170820fc014f9 Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Fri, 20 Jun 2025 18:13:14 +0800 Subject: [PATCH 2/4] Add "Remarks" and "Example" headings in C4172 warning reference --- .../compiler-warnings/compiler-warning-level-1-c4172.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4172.md b/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4172.md index 3131aa03a7..82155536f0 100644 --- a/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4172.md +++ b/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4172.md @@ -10,10 +10,14 @@ ms.assetid: a8d2bf65-d8b1-4fe3-8340-a223d7e7fde6 > returning address of local variable or temporary +## Remarks + 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. +## Example + The following sample generates C4172: ```cpp From dadf77144a4a85ccf671a7b7dfd6db52d94aaa7e Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Fri, 20 Jun 2025 18:23:23 +0800 Subject: [PATCH 3/4] Tweak example in C4172 warning reference --- .../compiler-warning-level-1-c4172.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4172.md b/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4172.md index 82155536f0..11be7a98ed 100644 --- a/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4172.md +++ b/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4172.md @@ -18,16 +18,18 @@ Redesign the function so that it does not return the address of a local object. ## Example -The following sample generates C4172: +The following example generates C4172: ```cpp // C4172.cpp -// compile with: /W1 /LD -float f = 10; - -const double& bar() { -// try the following line instead -// const float& bar() { - return f; // C4172 +// compile with: /c /W1 +float f = 1.f; + +const double& func() +// Try one of the following lines instead: +// const float& func() +// const auto& func() +{ + return f; // C4172 } ``` From 10d9a37576ef8f22094047e67171fce990ac399a Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Fri, 20 Jun 2025 18:24:35 +0800 Subject: [PATCH 4/4] Update metadata in C4172 warning reference --- .../compiler-warnings/compiler-warning-level-1-c4172.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4172.md b/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4172.md index 11be7a98ed..e2e00b8b21 100644 --- a/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4172.md +++ b/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4172.md @@ -1,10 +1,9 @@ --- -description: "Learn more about: Compiler Warning (level 1) C4172" title: "Compiler Warning (level 1) C4172" -ms.date: "11/04/2016" +description: "Learn more about: Compiler Warning (level 1) C4172" +ms.date: 06/20/2025 f1_keywords: ["C4172"] helpviewer_keywords: ["C4172"] -ms.assetid: a8d2bf65-d8b1-4fe3-8340-a223d7e7fde6 --- # Compiler Warning (level 1) C4172