Skip to content

Commit d1ccf69

Browse files
committed
Add documentation for C6390.
1 parent d07907b commit d1ccf69

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

‎docs/code-quality/c6389.md‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ The rule is an experimental rule that must be explicitly enabled in a rule set f
1919
```cpp
2020
// A.h
2121
struct X;
22-
```
2322

24-
```cpp
2523
// A.cpp
2624
#include "A.h"
2725

@@ -39,9 +37,7 @@ One way to resolve these issues is to move `struct Y` into an anonymous namespac
3937
// A.h
4038
struct X;
4139
void f();
42-
```
4340
44-
```cpp
4541
// A.cpp
4642
#include "A.h"
4743

‎docs/code-quality/c6390.md‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: C6390
3+
description: "Describes the Microsoft C/C++ code analysis warning C6390, its causes, and how to address it."
4+
ms.date: 06/17/2022
5+
f1_keywords: ["C6390"]
6+
helpviewer_keywords: ["C6390"]
7+
---
8+
9+
# C6390: NO_NULLCHECK_FOR_THIS
10+
11+
According to the C++ standard, the value of `this` is never null; some compilers will optimize null checks for `this` out. While MSVC is not doing such optimizations, code relying on null-valued `this` can trigger unexpected behavior when compiled with other compilers. This warning helps detect these portability problems.
12+
13+
## Example
14+
15+
```cpp
16+
struct X
17+
{
18+
void m()
19+
{
20+
if(!this) // Warning: According to the C++ standard, the value of 'this' is never null; some compilers will optimize this check out
21+
return;
22+
}
23+
};
24+
```
25+
26+
To solve this problem, rewrite the code to never call non-static member functions on null pointers.

‎docs/code-quality/toc.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,8 @@ items:
465465
href: ../code-quality/c6388.md
466466
- name: C6389
467467
href: ../code-quality/c6389.md
468+
- name: C6390
469+
href: ../code-quality/c6390.md
468470
- name: C6400
469471
href: ../code-quality/c6400.md
470472
- name: C6401

0 commit comments

Comments
 (0)