Visual C++ Compiler Warning C4091

Message Text

'attributes' : ignored on left of 'type' when no variable is declared

The product documentation names the first placeholder as extended-attribute, but there need not be just the one attribute (or, indeed, any attribute) and neither need the attributes be extended (in the sense of being specified through a __declspec).

Severity

This is a level 1 or level 2 warning, depending on the circumstances. The product documentation speaks only of level 2, but describes only the case that actually triggers at level 1.

Warning C4091 can occur at level 2 only if the Microsoft language extensions are enabled (as by /Ze, which is the default). Under /Za, the condition for warning C4091 at level 2 is instead just a particular case of the syntax error C2059.

Circumstances

Whether at level 1 or level 2, warning C4091 is concerned with the specification of storage attributes in a declaration that names a type but does not proceed to declare an instance of that type.

Thus, with type-specifier either naming an already-defined type else also defining the type,

attributes type-specifier instance-name; 

is expected as declaring an instance of the type and assigning the storage attributes to that instance. Warning C4091 may occur when instance-name is omitted.

Level 1

For warning C4091 at level 1, the type must be a composed type, i.e., a class, struct, union or __interface, but not anonymous. Warning C4091 then occurs if the attributes do not include friend but do include any of

(or two more that have not yet been identified).

Level 2

For warning C4091 at level 2, the type must be fundamental (i.e., integral, floating or void) or directly derived (i.e., a pointer, reference, array or even a function). Any storage attribute offends.