Skip to content

Commit c994155

Browse files
Merge pull request #4979 from MicrosoftDocs/main638455189850824515sync_temp
For protected branch, push strategy should use PR and merge to target branch method to work around git push error
2 parents 61d8ea5 + 9c729c1 commit c994155

File tree

3 files changed

+75
-13
lines changed

3 files changed

+75
-13
lines changed

docs/code-quality/c6392.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
description: "Learn more about: Warning C6392"
3+
title: Warning C6392
4+
ms.date: 03/06/2024
5+
f1_keywords: ["C6392", "STREAM_OUTPUT_VOID_PTR", "__STREAM_OUTPUT_VOID_PTR"]
6+
helpviewer_keywords: ["C6392"]
7+
---
8+
# Warning C6392
9+
10+
> This expression writes the value of the pointer to the stream. If this is intentional, add an explicit cast to 'void *'
11+
12+
This rule was added in Visual Studio 2022 17.8.
13+
14+
## Remarks
15+
16+
C++ supports wide character streams such as `std::wostringstream`, and nonwide character streams such as `std::ostringstream`. Trying to print a wide string to a nonwide stream calls the `void*` overload of `operator<<`. This overload prints the address of the wide string instead of the value.
17+
18+
Code analysis name: `STREAM_OUTPUT_VOID_PTR`
19+
20+
## Example
21+
22+
The following code snippet prints the value of the pointer to the standard output instead of the string `"Pear"`:
23+
24+
```cpp
25+
#include <iostream>
26+
27+
int main() {
28+
std::cout << L"Pear\n"; // Warning: C6392
29+
}
30+
```
31+
32+
There are multiple ways to fix this error. If printing the pointer value is unintended, use a nonwide string:
33+
34+
```cpp
35+
#include <iostream>
36+
37+
int main() {
38+
std::cout << "Pear\n"; // No warning.
39+
}
40+
```
41+
42+
Alternatively, use a wide stream:
43+
44+
```cpp
45+
#include <iostream>
46+
47+
int main() {
48+
std::wcout << L"Pear\n"; // No warning.
49+
}
50+
```
51+
52+
If the behavior is intentional, make the intention explicit and silence the warning by using an explicit cast:
53+
54+
```cpp
55+
#include <iostream>
56+
57+
int main() {
58+
std::cout << static_cast<void*>(L"Pear\n"); // No warning.
59+
}
60+
```

docs/code-quality/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,8 @@ items:
481481
href: ../code-quality/c6389.md
482482
- name: Warning C6390
483483
href: ../code-quality/c6390.md
484+
- name: Warning C6392
485+
href: ../code-quality/c6392.md
484486
- name: Warning C6393
485487
href: ../code-quality/c6393.md
486488
- name: Warning C6394

docs/ide/visualize-macro-expansion.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
title: "Visualize C/C++ macro expansion"
33
description: "Learn how to use Visual Studio to visualize C/C++ macro expansion."
4-
ms.date: 02/02/2024
4+
ms.date: 03/07/2024
55
ms.topic: "how-to"
66
f1_keywords: ["macro expansion", "macro visualization"]
77
helpviewer_keywords: ["macro expansion", "macro visualization"]
88
---
99
# Visualize C/C++ macro expansion
1010

11-
Long macros can be difficult to read. Visual Studio can now expand C and C++ macros: you can get a copy on the clipboard of what the expanded macro looks like, replace the macro inline with its expansion, and step-by-step expand a macro so you can see what it looks like at each stage of expansion. This article allows you to experiment with these features.
11+
Long macros can be difficult to read. Visual Studio can now expand C and C++ macros. You can get a copy on the clipboard of what the expanded macro looks like, replace the macro inline with its expansion, and step-by-step expand a macro to see what it looks like at each stage of expansion. In this article, you experiment with all of these features.
1212

1313
## Prerequisites
1414

@@ -33,42 +33,42 @@ Long macros can be difficult to read. Visual Studio can now expand C and C++ mac
3333

3434
int main()
3535
{
36-
std::cout << "Distance: " << DISTANCE() << std::endl;
37-
std::cout << "Force: " << FORCE() << std::endl;
38-
std::cout << "Work: " << WORK() << std::endl;
39-
std::cout << "Power: " << POWER() << std::endl;
36+
std::cout << "Distance: " << DISTANCE() << std::endl;
37+
std::cout << "Force: " << FORCE() << std::endl;
38+
std::cout << "Work: " << WORK() << std::endl;
39+
std::cout << "Power: " << POWER() << std::endl;
4040
}
4141
```
42-
42+
4343
## Copy an expanded macro
4444

4545
You can inspect a macro's expanded value, even when several preprocessor steps are involved, by using the following steps:
4646
47-
1. Place the cursor on the `POWER` a macro in the sample.
47+
1. Place the cursor on the `POWER` macro inside `main()` in the example.
4848
1. As you hover over the macro, options appear to **Copy**, **Expand Inline**, **Visualize Expansion**, and **Search Online**:
4949
5050
:::image type="complex" source="media/visual-studio-2022-hover-macro.png" alt-text="Screenshot of the macro window, showing the POWER macro expansion.":::
5151
The macro window is open on POWER to show that it expands to (((10.0 * 20.0) * (5.0 * 2.0)) / 2.0). Options to copy, expand inline, visual expansion, and search online appear at the bottom of the window.
5252
:::image-end:::
5353
5454
1. Choose **Copy**.
55-
1. Create a comment following the `POWER` line and choose paste (`Ctrl+V`). The expansion of the macro, as a comment near your macro, looks like: ```// (((10.0 * 20.0)* (5.0 * 2.0)) / 2.0)```.
55+
1. Create a comment following the `POWER` line and choose paste (CTRL+V). The expansion of the macro, as a comment near your macro, looks like: `// (((10.0 * 20.0)* (5.0 * 2.0)) / 2.0).` The keyboard shortcut for this action is CTRL+M, CTRL+C.
5656
5757
## Expand a macro inline
5858
5959
Use the following steps to expand a macro inline, which replaces the macro with its expansion:
6060
61-
1. Place the cursor on the `POWER` macro in the previous example.
61+
1. Place the cursor on the `POWER` macro inside `main()` in the example.
6262
1. As you hover over the macro, options appear to **Copy**, **Expand Inline**, **Visualize Expansion**, and **Search Online**
63-
1. Choose **Expand Inline**. The `POWER()` macro is replaced with its expanded value: ```std::cout << "Power: " << (((10.0 * 20.0) * (5.0 * 2.0)) / 2.0) << std::endl;```
63+
1. Choose **Expand Inline**. The `POWER()` macro is replaced with its expanded value: ```std::cout << "Power: " << (((10.0 * 20.0) * (5.0 * 2.0)) / 2.0) << std::endl;```. The keyboard shortcut for this action is CTRL+M, CTRL+I.
6464
6565
## Visualize macro expansion
6666
6767
You can expand a macro one step at a time. This is useful when there are nested macros and you want to see the expansion step-by-step. To visualize the macro expansion for the `WORK` macro, use the following steps:
6868
69-
1. Place the cursor on the `WORK` macro in the previous example.
69+
1. Place the cursor on the `WORK` macro inside `main()` in the example.
7070
1. As you hover over the macro, options appear to **Copy**, **Expand Inline**, **Visualize Expansion**, and **Search Online**.
71-
1. Choose **Visualize Expansion**.
71+
1. Choose **Visualize Expansion**. The keyboard shortcut for this action is CTRL+M followed by CTRL+V.
7272
1. The macro expansion window appears. The first expansion of the `WORK` macro is visible: `(FORCE() * DISTANCE())`:
7373
7474
:::image type="complex" source="media/visual-studio-2022-work-macro-expansion.png" alt-text="Screenshot of the macro expansion window, which allows you to step through the WORK macro expansion one step at a time.":::

0 commit comments

Comments
 (0)