Edit

Share via


Warning C6504

Invalid annotation: property may only be used on values of pointer, pointer-to-member, or array type

This warning indicates the use of a pointer-specific SAL annotation on a non-pointer data type.

Remarks

For more information about what data types are supported by properties, see Annotation Properties.

Code analysis name: NULL_ON_NON_POINTER

Example

The following code generates warning C6504. This issue stems from the use of the pointer-specific _Maybenull_ and _Notnull_ on reference pt.

class Point
{
    public:
        //  members
};

void f(_Pre_ _Maybenull_ Point& pt)
{
    // code ...
}

void g(_Pre_ _Notnull_ Point& pt)
{
    // code ...
}

To correct this warning, remove the annotation if it doesn't make sense. You could also change to an annotation that's 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.

class Point
{
    public:
        //  members
};

void f(_Pre_ _Maybenull_  Point* pt)
{
    // code ...
}

void g(Point& pt)
{
    // code ...
}

See Also

Annotation Properties