Skip to content

Commit 4f28a18

Browse files
Merge pull request #5816 from TylerMSFT/c4706
fix customer reported issue
2 parents b06663e + 0f54a52 commit 4f28a18

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

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

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,65 @@
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/5/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
{
2422
int a = 0, b = 0;
25-
if ( a = b ) // C4706
23+
if (a = b) // C4706
2624
{
2725
}
2826
}
2927
```
3028

31-
The warning will occur even if you double the parentheses around the test condition:
29+
Suppress the warning with `((`*expression*`))`. For example:
3230

3331
```cpp
34-
// C4706b.cpp
3532
// compile with: /W4
3633
int main()
3734
{
3835
int a = 0, b = 0;
39-
if ( ( a = b ) ) // C4706
36+
if ((a = b)) // No warning
4037
{
4138
}
4239
}
4340
```
4441

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:
42+
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:
4643

4744
```cpp
48-
// C4706c.cpp
4945
// compile with: /W4
5046
int main()
5147
{
5248
int a = 0, b = 0;
53-
if ( a == b )
49+
if (a == b)
5450
{
5551
}
5652
}
5753
```
5854

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:
55+
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:
6056

6157
```cpp
62-
// C4706d.cpp
6358
// compile with: /W4
6459
int main()
6560
{
6661
int a = 0, b = 0;
67-
if ( ( a = b ) != 0 )
62+
if ((a = b) != 0)
6863
{
6964
}
7065
}

0 commit comments

Comments
 (0)