Skip to content

Commit 911222a

Browse files
Updated C6504
Updated to new format, matched example format to previous PRs
1 parent b6d3188 commit 911222a

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

docs/code-quality/c6504.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
11
---
22
description: "Learn more about: C6504"
33
title: C6504
4-
ms.date: 12/19/2019
4+
ms.date: 09/22/2022
55
ms.topic: reference
6-
f1_keywords: ["C6504"]
6+
f1_keywords: ["C6504", "NULL_ON_NON_POINTER", "__WARNING_NULL_ON_NON_POINTER"]
77
helpviewer_keywords: ["C6504"]
88
ms.assetid: 6baeed46-e73d-4974-af16-7487c55b3473
99
---
1010
# C6504
1111

12-
> warning C6504: invalid annotation: property may only be used on values of pointer, pointer-to-member, or array type
12+
> Invalid annotation: property may only be used on values of pointer, pointer-to-member, or array type
1313
14-
This warning indicates the use of a pointer-specific SAL annotation on a non-pointer data type. For more information about what data types are supported by properties, see [Annotation Properties](using-sal-annotations-to-reduce-c-cpp-code-defects.md).
14+
This warning indicates the use of a pointer-specific SAL annotation on a non-pointer data type.
15+
16+
## Remarks
17+
18+
For more information about what data types are supported by properties, see [Annotation Properties](using-sal-annotations-to-reduce-c-cpp-code-defects.md).
19+
20+
Code analysis name: NULL_ON_NON_POINTER
1521

1622
## Example
1723

18-
```cpp
19-
#include<sal.h>
24+
The following code generates this warning. This issue stems from the use of the pointer-specific `_Maybenull_` and `_Notnull_` on reference `pt`.
2025

26+
```cpp
2127
class Point
2228
{
23-
public:
24-
// members
25-
};
29+
public:
30+
// members
31+
};
2632

27-
// Oops, according to this annotation, pt may be null which does not make sense for a reference types
2833
void f(_Pre_ _Maybenull_ Point& pt)
2934
{
3035
// code ...
3136
}
3237

33-
// Oops, according to this annotation, pt cannot be null which does not make sense for a reference types
3438
void g(_Pre_ _Notnull_ Point& pt)
3539
{
3640
// code ...
3741
}
3842
```
3943
40-
To correct this warning remove the annotation if it does not make sense. You could also change to an annotation to be applicable to the type used, or change to type to match the annotation.
44+
To correct this warning, remove the annotation if it does not make sense. You could also change to an annotation to be applicable to the type used, or change the type to match the annotation. The following code remediates this warning by changing the first instance of `pt` to a pointer and by removing the second annotation to match the reference type.
4145
4246
```cpp
43-
#include<sal.h>
44-
4547
class Point
4648
{
47-
public:
48-
// members
49-
};
49+
public:
50+
// members
51+
};
5052
51-
// Changed to pointer type because it may be null
5253
void f(_Pre_ _Maybenull_ Point* pt)
5354
{
5455
// code ...
5556
}
5657
57-
// Removed annotation because it did not apply to reference types.
5858
void g(Point& pt)
5959
{
6060
// code ...

0 commit comments

Comments
 (0)