Missing examples for Visual C++ compiler warnings

89 Views Asked by At

I cannot figure out under what circumstances these two compiler warnings would be indicated:

C28206:

<expression> : left operand points to a struct, use ->

This warning is reported when the struct pointer dereference notation -> was expected.

C28207:

<expression>: left operand is a struct, use .

This warning is reported when a struct dereference dot (.) was expected.

Could someone please provide examples?

I tried the following examples. The code analysis was carried out using the Native Recommended Rules ruleset (which includes both warnings) and with warning level /Wall (all warnings enabled).

struct SomeStruct
{
    int value;
};
SomeStruct* foo = new SomeStruct();
(*foo).value = 2; // Would have expected C28206 to be detected here.
SomeStruct foo = SomeStruct();
(&foo)->value = 2; // Would have expected C28207 to be detected here.

Other warnings are detected (e.g. C6001):

SomeStruct foobar()
{
    SomeStruct foo;
    return foo; // C6001 is detected here.
}
0

There are 0 best solutions below