Skip to content

Repo sync for protected branch #5224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 6, 2025
Original file line number Diff line number Diff line change
@@ -1,70 +1,65 @@
---
description: "Learn more about: Compiler Warning (level 4) C4706"
title: "Compiler Warning (level 4) C4706"
ms.date: "11/04/2016"
ms.date: "3/5/2025"
f1_keywords: ["C4706"]
helpviewer_keywords: ["C4706"]
ms.assetid: 89cd3f4f-812c-4a4b-9426-65a5a6d1b99c
---
# Compiler Warning (level 4) C4706

assignment within conditional expression
> assignment used as a condition

The test value in a conditional expression was the result of an assignment.
The test value in a conditional expression is the result of an assignment.

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.

The following sample generates C4706:

```cpp
// C4706a.cpp
// compile with: /W4
int main()
{
int a = 0, b = 0;
if ( a = b ) // C4706
if (a = b) // C4706
{
}
}
```

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

```cpp
// C4706b.cpp
// compile with: /W4
int main()
{
int a = 0, b = 0;
if ( ( a = b ) ) // C4706
if ((a = b)) // No warning
{
}
}
```

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:
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:

```cpp
// C4706c.cpp
// compile with: /W4
int main()
{
int a = 0, b = 0;
if ( a == b )
if (a == b)
{
}
}
```

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:
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:

```cpp
// C4706d.cpp
// compile with: /W4
int main()
{
int a = 0, b = 0;
if ( ( a = b ) != 0 )
if ((a = b) != 0)
{
}
}
Expand Down
10 changes: 7 additions & 3 deletions docs/sanitizers/asan-known-issues.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "AddressSanitizer known issues"
description: "Technical description of the AddressSanitizer for Microsoft C/C++ known issues."
ms.date: 1/28/2025
ms.date: 3/5/2025
helpviewer_keywords: ["AddressSanitizer known issues"]
---

Expand All @@ -23,8 +23,6 @@ These options and functionality are incompatible with [`/fsanitize=address`](../
- [C++ AMP](../parallel/amp/cpp-amp-overview.md) is unsupported, and should be disabled.
- [Universal Windows Platform](../cppcx/universal-windows-apps-cpp.md) (UWP) applications are unsupported.
- [Special case list](https://clang.llvm.org/docs/SanitizerSpecialCaseList.html) files are unsupported.
- [MFC](../mfc/mfc-concepts.md) using the optional [`alloc_dealloc_mismatch`](error-alloc-dealloc-mismatch.md) runtime option is unsupported.
- [`_CrtDumpMemoryLeaks`](../c-runtime-library/reference/crtdumpmemoryleaks.md) is unsupported, and should be disabled.

## Standard library support

Expand Down Expand Up @@ -56,6 +54,12 @@ int main() {
}
```

## Overriding operator new and delete

AddressSanitizer (ASAN) has a custom version of `operator new` and `operator delete` that it uses to find more allocation errors like [`alloc_dealloc_mismatch`](error-alloc-dealloc-mismatch.md). Running the linker with [`/INFERASANLIBS`](../build/reference/inferasanlibs.md) ensures that ASAN's `new`/`delete` override has low precedence, so that the linker chooses any `operator new` or `operator delete` overrides in other libraries over ASAN's custom versions. When this happens, ASAN may not be able to catch some errors that rely on its custom `operator new` and `operator delete`.

[MFC](../mfc/mfc-concepts.md) includes custom overrides for `operator new` and `operator delete` and so might miss errors like [`alloc_dealloc_mismatch`](error-alloc-dealloc-mismatch.md).

## Windows versions

As there are dependencies with specific Windows versions, support is focused on Windows 10. MSVC AddressSanitizer was tested on 10.0.14393 (RS1), and 10.0.21323 (prerelease insider build). [Report a bug](https://aka.ms/feedback/report?space=62) if you run into issues.
Expand Down