1 // RUN: %clang_analyze_cc1 \
2 // RUN:   -analyzer-checker=core,alpha.cplusplus.EnumCastOutOfRange \
3 // RUN:   -verify %s
4 
5 enum En_t {
6   En_0 = -4,
7   En_1,
8   En_2 = 1,
9   En_3,
10   En_4 = 4
11 };
12 
unscopedUnspecifiedCStyle()13 void unscopedUnspecifiedCStyle() {
14   enum En_t Below = (enum En_t)(-5);    // expected-warning {{not in the valid range}}
15   enum En_t NegVal1 = (enum En_t)(-4);  // OK.
16   enum En_t NegVal2 = (enum En_t)(-3);  // OK.
17   enum En_t InRange1 = (enum En_t)(-2); // expected-warning {{not in the valid range}}
18   enum En_t InRange2 = (enum En_t)(-1); // expected-warning {{not in the valid range}}
19   enum En_t InRange3 = (enum En_t)(0);  // expected-warning {{not in the valid range}}
20   enum En_t PosVal1 = (enum En_t)(1);   // OK.
21   enum En_t PosVal2 = (enum En_t)(2);   // OK.
22   enum En_t InRange4 = (enum En_t)(3);  // expected-warning {{not in the valid range}}
23   enum En_t PosVal3 = (enum En_t)(4);   // OK.
24   enum En_t Above = (enum En_t)(5);     // expected-warning {{not in the valid range}}
25 }
26 
27 enum En_t unused;
unusedExpr()28 void unusedExpr() {
29   // Following line is not something that EnumCastOutOfRangeChecker should
30   // evaluate.  Checker should either ignore this line or process it without
31   // producing any warnings.  However, compilation will (and should) still
32   // generate a warning having nothing to do with this checker.
33   unused; // expected-warning {{expression result unused}}
34 }
35