Skip to content

Commit 3987a29

Browse files
committed
Add missing documentation for a recently introduced check.
1 parent f90ea56 commit 3987a29

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
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 will write 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+
In C++, we have streams of wide characters, like `std::wostringstream`, and streams of non-wide characters like `std::ostringstream`. Trying to print a wide character literal to a non-wide string will call the `void*` overload of `operator<<`. This results in printing the address of the wide character literal instead of the value.
17+
18+
Code analysis name: `STREAM_OUTPUT_VOID_PTR`
19+
20+
## Example
21+
22+
In the following code snippet, we will print the value of the pointer to the standard output instead of the string `"Foo"`:
23+
24+
```cpp
25+
#include <iostream>
26+
27+
int main() {
28+
std::cout << L"Foo\n"; // Warning: C6392
29+
}
30+
```
31+
32+
There are multiple ways to fix this error. If printing the pointer value is unintended, we can use a non-wide string literal:
33+
34+
```cpp
35+
#include <iostream>
36+
37+
int main() {
38+
std::cout << "Foo\n"; // No warning.
39+
}
40+
```
41+
42+
Alternatively, we can use a wide stream:
43+
44+
```cpp
45+
#include <iostream>
46+
47+
int main() {
48+
std::wcout << L"Foo\n"; // No warning.
49+
}
50+
```
51+
52+
If the behavior is intentional, we can silence the warning using an explicit cast:
53+
54+
```cpp
55+
#include <iostream>
56+
57+
int main() {
58+
std::cout << static_cast<void*>(L"Foo\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

0 commit comments

Comments
 (0)