From b9a44880c782782d63bd7f21288f0b1818872c3a Mon Sep 17 00:00:00 2001 From: Amy Wishnousky Date: Mon, 11 Dec 2023 15:19:29 -0800 Subject: [PATCH 1/6] Update asan-known-issues.md Update known issues page to, instead of describe MFC as a one-off incompatibility, describe the heart of the problem that means MFC might miss some errors. --- docs/sanitizers/asan-known-issues.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/sanitizers/asan-known-issues.md b/docs/sanitizers/asan-known-issues.md index cbf822f6b87..7ddd07c5124 100644 --- a/docs/sanitizers/asan-known-issues.md +++ b/docs/sanitizers/asan-known-issues.md @@ -23,7 +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. ## Standard library support @@ -55,6 +54,12 @@ int main() { } ``` +## Overriding operator new and delete + +AddressSanitizer has a custom version of `operator new` and `operator delete` that are used to provide additional metadata about the allocations to ASan to find more errors, like [`alloc_dealloc_mismatch`](error-alloc-dealloc-mismatch.md). The linker is modified (via [`/INFERASANLIBS`](../build/reference/inferasanlibs.md)) to ensure that ASan's `new`/`delete` override has low precedence, so that any `operator new` or `operator delete` overrides in other libraries will be chosen by the linker over ASan's. When this happens, ASan may not be able to catch some errors that rely on it's custom `operator new` and `operator delete`. + +[MFC](../mfc/mfc-concepts.md) includes custom overrides for `operator new` and `operator delete` and may 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. From 6b2fa95a9d3b7114fc8fb071bd6a05600104db27 Mon Sep 17 00:00:00 2001 From: Tyler Whitney Date: Mon, 11 Dec 2023 16:04:06 -0800 Subject: [PATCH 2/6] Update asan-known-issues.md little edit pass to hopefully save you some ACROLINX noise. Hopefully doesn't cause new noise... --- docs/sanitizers/asan-known-issues.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/sanitizers/asan-known-issues.md b/docs/sanitizers/asan-known-issues.md index 7ddd07c5124..7439476cb1d 100644 --- a/docs/sanitizers/asan-known-issues.md +++ b/docs/sanitizers/asan-known-issues.md @@ -56,9 +56,9 @@ int main() { ## Overriding operator new and delete -AddressSanitizer has a custom version of `operator new` and `operator delete` that are used to provide additional metadata about the allocations to ASan to find more errors, like [`alloc_dealloc_mismatch`](error-alloc-dealloc-mismatch.md). The linker is modified (via [`/INFERASANLIBS`](../build/reference/inferasanlibs.md)) to ensure that ASan's `new`/`delete` override has low precedence, so that any `operator new` or `operator delete` overrides in other libraries will be chosen by the linker over ASan's. When this happens, ASan may not be able to catch some errors that rely on it's custom `operator new` and `operator delete`. +AddressSanitizer (ASAN) has a custom version of `operator new` and `operator delete` that it uses to help ASAN 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 any `operator new` or `operator delete` overrides in other libraries are chosen by the linker over ASan's. 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 may miss errors like [`alloc_dealloc_mismatch`](error-alloc-dealloc-mismatch.md). +[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 From 46fee4d31095d8af2d8c2622374a7c0bf4a46ad2 Mon Sep 17 00:00:00 2001 From: Tyler Whitney Date: Mon, 11 Dec 2023 16:06:54 -0800 Subject: [PATCH 3/6] Update asan-known-issues.md A little more acrolinx --- docs/sanitizers/asan-known-issues.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/sanitizers/asan-known-issues.md b/docs/sanitizers/asan-known-issues.md index 7439476cb1d..162643f22b5 100644 --- a/docs/sanitizers/asan-known-issues.md +++ b/docs/sanitizers/asan-known-issues.md @@ -1,7 +1,7 @@ --- title: "AddressSanitizer known issues" description: "Technical description of the AddressSanitizer for Microsoft C/C++ known issues." -ms.date: 12/1/2023 +ms.date: 12/11/2023 helpviewer_keywords: ["AddressSanitizer known issues"] --- @@ -56,7 +56,7 @@ int main() { ## Overriding operator new and delete -AddressSanitizer (ASAN) has a custom version of `operator new` and `operator delete` that it uses to help ASAN 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 any `operator new` or `operator delete` overrides in other libraries are chosen by the linker over ASan's. When this happens, ASAN may not be able to catch some errors that rely on its custom `operator new` and `operator 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). From b91165c5c6a2f6bf962f556a0e62e8370b9d3cd9 Mon Sep 17 00:00:00 2001 From: TylerMSFT Date: Tue, 4 Mar 2025 15:16:35 -0800 Subject: [PATCH 4/6] fix customer reported issue --- .../compiler-warning-level-4-c4706.md | 30 ++++--------------- 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/docs/error-messages/compiler-warnings/compiler-warning-level-4-c4706.md b/docs/error-messages/compiler-warnings/compiler-warning-level-4-c4706.md index 6fa2feebb00..67dc6d520f6 100644 --- a/docs/error-messages/compiler-warnings/compiler-warning-level-4-c4706.md +++ b/docs/error-messages/compiler-warnings/compiler-warning-level-4-c4706.md @@ -1,23 +1,21 @@ --- description: "Learn more about: Compiler Warning (level 4) C4706" title: "Compiler Warning (level 4) C4706" -ms.date: "11/04/2016" +ms.date: "3/4/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() { @@ -28,24 +26,9 @@ int main() } ``` -The warning will occur even if you double the parentheses around the test condition: +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 -// C4706b.cpp -// compile with: /W4 -int main() -{ - int a = 0, b = 0; - if ( ( a = b ) ) // C4706 - { - } -} -``` - -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: - -```cpp -// C4706c.cpp // compile with: /W4 int main() { @@ -56,15 +39,14 @@ int main() } ``` -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 ) { } } From edc5e7f73900d35bf74a2d585945ad571e340fb2 Mon Sep 17 00:00:00 2001 From: TylerMSFT Date: Wed, 5 Mar 2025 10:12:48 -0800 Subject: [PATCH 5/6] put back (()) example --- .../compiler-warning-level-4-c4706.md | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/docs/error-messages/compiler-warnings/compiler-warning-level-4-c4706.md b/docs/error-messages/compiler-warnings/compiler-warning-level-4-c4706.md index 67dc6d520f6..5c478a5fd94 100644 --- a/docs/error-messages/compiler-warnings/compiler-warning-level-4-c4706.md +++ b/docs/error-messages/compiler-warnings/compiler-warning-level-4-c4706.md @@ -1,7 +1,7 @@ --- description: "Learn more about: Compiler Warning (level 4) C4706" title: "Compiler Warning (level 4) C4706" -ms.date: "3/4/2025" +ms.date: "3/5/2025" f1_keywords: ["C4706"] helpviewer_keywords: ["C4706"] --- @@ -20,7 +20,20 @@ The following sample generates C4706: int main() { int a = 0, b = 0; - if ( a = b ) // C4706 + if (a = b) // C4706 + { + } +} +``` + +Suppress the warning with `((expression))`. For example: + +```cpp +// compile with: /W4 +int main() +{ + int a = 0, b = 0; + if ((a = b)) // No warning { } } @@ -33,7 +46,7 @@ If your intention is to test a relation, not to make an assignment, use the `==` int main() { int a = 0, b = 0; - if ( a == b ) + if (a == b) { } } @@ -46,7 +59,7 @@ If you intend to make your test value the result of an assignment, test to ensur int main() { int a = 0, b = 0; - if (( a = b ) != 0 ) + if ((a = b) != 0) { } } From 0f54a528d5d99f8e32cd0dbdb09b50bdf9e5febd Mon Sep 17 00:00:00 2001 From: TylerMSFT Date: Wed, 5 Mar 2025 10:17:57 -0800 Subject: [PATCH 6/6] nit --- .../compiler-warnings/compiler-warning-level-4-c4706.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/error-messages/compiler-warnings/compiler-warning-level-4-c4706.md b/docs/error-messages/compiler-warnings/compiler-warning-level-4-c4706.md index 5c478a5fd94..d31d01fd410 100644 --- a/docs/error-messages/compiler-warnings/compiler-warning-level-4-c4706.md +++ b/docs/error-messages/compiler-warnings/compiler-warning-level-4-c4706.md @@ -26,7 +26,7 @@ int main() } ``` -Suppress the warning with `((expression))`. For example: +Suppress the warning with `((`*expression*`))`. For example: ```cpp // compile with: /W4