Skip to content

Commit 2acb092

Browse files
authored
Update compiler-warning-level-1-c4172.md
We demo an unusual case but not perhaps a more common case. Added it.
1 parent 10d9a37 commit 2acb092

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

docs/error-messages/compiler-warnings/compiler-warning-level-1-c4172.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,22 @@ The following example generates C4172:
2222
```cpp
2323
// C4172.cpp
2424
// compile with: /c /W1
25+
26+
const int* func1()
27+
{
28+
int i = 42;
29+
return &i; // C4172
30+
}
31+
2532
float f = 1.f;
2633

27-
const double& func()
34+
const double& func2()
2835
// Try one of the following lines instead:
29-
// const float& func()
30-
// const auto& func()
36+
// const float& func2()
37+
// const auto& func2()
3138
{
39+
// The problem is that a temporary is created to convert f to a double.
40+
// C4172 in this case refers to returning the address of a temporary
3241
return f; // C4172
3342
}
3443
```

0 commit comments

Comments
 (0)