|
1 | 1 | ---
|
2 | 2 | description: "Learn more about: C6504"
|
3 | 3 | title: C6504
|
4 |
| -ms.date: 12/19/2019 |
| 4 | +ms.date: 09/22/2022 |
5 | 5 | ms.topic: reference
|
6 |
| -f1_keywords: ["C6504"] |
| 6 | +f1_keywords: ["C6504", "NULL_ON_NON_POINTER", "__WARNING_NULL_ON_NON_POINTER"] |
7 | 7 | helpviewer_keywords: ["C6504"]
|
8 | 8 | ms.assetid: 6baeed46-e73d-4974-af16-7487c55b3473
|
9 | 9 | ---
|
10 | 10 | # C6504
|
11 | 11 |
|
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 |
13 | 13 |
|
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 |
15 | 21 |
|
16 | 22 | ## Example
|
17 | 23 |
|
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`. |
20 | 25 |
|
| 26 | +```cpp |
21 | 27 | class Point
|
22 | 28 | {
|
23 |
| -public: |
24 |
| - // members |
| 29 | + public: |
| 30 | + // members |
25 | 31 | };
|
26 | 32 |
|
27 |
| -// Oops, according to this annotation, pt may be null which does not make sense for a reference types |
28 | 33 | void f(_Pre_ _Maybenull_ Point& pt)
|
29 | 34 | {
|
30 | 35 | // code ...
|
31 | 36 | }
|
32 | 37 |
|
33 |
| -// Oops, according to this annotation, pt cannot be null which does not make sense for a reference types |
34 | 38 | void g(_Pre_ _Notnull_ Point& pt)
|
35 | 39 | {
|
36 | 40 | // code ...
|
37 | 41 | }
|
38 | 42 | ```
|
39 | 43 |
|
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 doesn't 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. |
41 | 45 |
|
42 | 46 | ```cpp
|
43 |
| -#include<sal.h> |
44 |
| -
|
45 | 47 | class Point
|
46 | 48 | {
|
47 |
| -public: |
48 |
| - // members |
| 49 | + public: |
| 50 | + // members |
49 | 51 | };
|
50 | 52 |
|
51 |
| -// Changed to pointer type because it may be null |
52 | 53 | void f(_Pre_ _Maybenull_ Point* pt)
|
53 | 54 | {
|
54 | 55 | // code ...
|
55 | 56 | }
|
56 | 57 |
|
57 |
| -// Removed annotation because it did not apply to reference types. |
58 | 58 | void g(Point& pt)
|
59 | 59 | {
|
60 | 60 | // code ...
|
|
0 commit comments