[previous] 1318 [next] Object of enum type is being modified with a compound assignment operator.
C++ compatibility REFERENCE - ISO:C90-6.5.2.2 Enumeration Specifiers

An object of enum type is being modified using a compound assignment operator.

An object of enum type should never be permitted to contain a value which is not one of its defined enumeration constants, but unfortunately the C language imposes no constraints of this nature. If the value of an expression is assigned to an enum object and the expression is not a constant or variable of the same enum type, there is a distinct risk that the assignment will 'corrupt' the enum object with an inappropriate value. This is very possible when a compound assignment operator is used to modify the value of an enum variable (in fact, such operations are not permitted in C++).

For example:


/*PRQA S 2017,2211,2213,3227,3408,3447,3602 ++*/

enum ET { A, B, C };

extern enum ET ex;

extern void foo(int n)
{
    ex += n;                                /* Message 1318 and 1479 */
    ex *= n;                                /* Message 1318 and 1479 */
}

See also:

QA·C Source Code Analyser 8.1.2
© 2013 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index Contents