Skip to content

Commit b91165c

Browse files
committed
fix customer reported issue
1 parent addc134 commit b91165c

File tree

1 file changed

+6
-24
lines changed

1 file changed

+6
-24
lines changed

docs/error-messages/compiler-warnings/compiler-warning-level-4-c4706.md

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
---
22
description: "Learn more about: Compiler Warning (level 4) C4706"
33
title: "Compiler Warning (level 4) C4706"
4-
ms.date: "11/04/2016"
4+
ms.date: "3/4/2025"
55
f1_keywords: ["C4706"]
66
helpviewer_keywords: ["C4706"]
7-
ms.assetid: 89cd3f4f-812c-4a4b-9426-65a5a6d1b99c
87
---
98
# Compiler Warning (level 4) C4706
109

11-
assignment within conditional expression
10+
> assignment used as a condition
1211
13-
The test value in a conditional expression was the result of an assignment.
12+
The test value in a conditional expression is the result of an assignment.
1413

1514
An assignment has a value (the value on the left side of the assignment) that can be used legally in another expression, including a test expression.
1615

1716
The following sample generates C4706:
1817

1918
```cpp
20-
// C4706a.cpp
2119
// compile with: /W4
2220
int main()
2321
{
@@ -28,24 +26,9 @@ int main()
2826
}
2927
```
3028

31-
The warning will occur even if you double the parentheses around the test condition:
29+
If your intention is to test a relation, not to make an assignment, use the `==` operator. For example, the following tests whether a and b are equal:
3230

3331
```cpp
34-
// C4706b.cpp
35-
// compile with: /W4
36-
int main()
37-
{
38-
int a = 0, b = 0;
39-
if ( ( a = b ) ) // C4706
40-
{
41-
}
42-
}
43-
```
44-
45-
If your intention is to test a relation and not to make an assignment, use the `==` operator. For example, the following line tests whether a and b are equal:
46-
47-
```cpp
48-
// C4706c.cpp
4932
// compile with: /W4
5033
int main()
5134
{
@@ -56,15 +39,14 @@ int main()
5639
}
5740
```
5841

59-
If you intend to make your test value the result of an assignment, test to ensure that the assignment is non-zero or not null. For example, the following code will not generate this warning:
42+
If you intend to make your test value the result of an assignment, test to ensure that the assignment is non-zero or non-null. For example, the following code doesn't generate this warning:
6043

6144
```cpp
62-
// C4706d.cpp
6345
// compile with: /W4
6446
int main()
6547
{
6648
int a = 0, b = 0;
67-
if ( ( a = b ) != 0 )
49+
if (( a = b ) != 0 )
6850
{
6951
}
7052
}

0 commit comments

Comments
 (0)