Dela via


C6507

warning C6507: annotation conflict: Null property at Deref=0 on a post condition must be a subset of the Null property on the precondition

This warning indicates that conflicting values for the Null property were used in Pre- and Post- conditions at default dereference level 0. In this case the Pre condition specifies Null=No, and the Post condition specifies Null=Yes. Because the parameter is not passed by reference it cannot be changed; therefore, the Post condition cannot use Null=Yes.

Example

The following code generates this warning because Deref=0 applies to the pointer and not the pointer to character:

// C
#include <CodeAnalysis\SourceAnnotations.h>
void f ([SA_Pre(Null=SA_No)] [SA_Post(Null=SA_Yes)] char *pc); 

// C++
#include <CodeAnalysis\SourceAnnotations.h>
using namespace vc_attributes;
void f([Pre(Null=No)] [Post(Null=Yes)] char *pc); 

To correct this warning, either modify the Pre attribute or use double indirection if you want to change the pointer that points to the characters, as shown in the following code:

// C
#include <CodeAnalysis\SourceAnnotations.h>
void f1 ([SA_Pre(Null=SA_Maybe)] [SA_Post(Null=SA_Yes)] char *pc); 
// or
void f2 ([SA_Pre(Deref=1, Null=SA_No)] [SA_Post(Null=SA_Yes)] char **pc);

// C++
#include <CodeAnalysis\SourceAnnotations.h>
using namespace vc_attributes;
void f1([Pre(Null=Maybe)] [Post(Null=Yes)] char *pc);
// or 
void f2 ([Pre(Deref=1, Null=No)] [Post(Null=Yes)] char **pc);

It is valid to specify Pre ( Null=Maybe ) and Post( Null=No ). This is useful for functions that might throw exceptions if the pointer is null:

See Also

Other Resources

Annotation Properties