|
| 1 | +package Test_5_4_1 is |
| 2 | + |
| 3 | + type Number_List is array (Integer range <>) of Integer; |
| 4 | + |
| 5 | + -- Violation: discriminant typed with unconstrained Natural |
| 6 | + type Number_Holder_1 (Current_Length : Natural := 0) is -- UndCC_Violation |
| 7 | + record |
| 8 | + Numbers : Number_List (1 .. Current_Length); |
| 9 | + end record; |
| 10 | + |
| 11 | + -- Valid: discriminant typed with constrained subtype |
| 12 | + subtype Max_Numbers is Natural range 0 .. 42; |
| 13 | + type Number_Holder_2 (Current_Length : Max_Numbers := 0) is -- UndCC_Valid |
| 14 | + record |
| 15 | + Numbers : Number_List (1 .. Current_Length); |
| 16 | + end record; |
| 17 | + |
| 18 | + -- Violation: discriminant typed with unconstrained Integer |
| 19 | + type Holder_3 (Size : Integer := 0) is -- UndCC_Violation |
| 20 | + record |
| 21 | + Data : Number_List (1 .. Size); |
| 22 | + end record; |
| 23 | + |
| 24 | + -- Valid: discriminant typed with constrained subtype of Integer |
| 25 | + subtype Small_Size is Integer range 1 .. 100; |
| 26 | + type Holder_4 (Size : Small_Size := 1) is -- UndCC_Valid |
| 27 | + record |
| 28 | + Data : Number_List (1 .. Size); |
| 29 | + end record; |
| 30 | + |
| 31 | + -- Violation: discriminant typed with Positive (predefined, unconstrained) |
| 32 | + type Holder_5 (Count : Positive := 1) is -- UndCC_Violation |
| 33 | + record |
| 34 | + Data : Number_List (1 .. Count); |
| 35 | + end record; |
| 36 | + |
| 37 | + -- Valid: discriminant typed with enumeration (already constrained by values) |
| 38 | + type Color is (Red, Green, Blue); |
| 39 | + type Color_Record (C : Color := Red) is -- UndCC_Valid |
| 40 | + record |
| 41 | + Value : Integer; |
| 42 | + end record; |
| 43 | + |
| 44 | + -- Valid: discriminant typed with a Float subtype with digits constraint |
| 45 | + subtype Precise_Float is Float digits 6; |
| 46 | + type Float_Record (F : Precise_Float := 0.0) is -- UndCC_Valid |
| 47 | + record |
| 48 | + Value : Integer; |
| 49 | + end record; |
| 50 | + |
| 51 | + -- Violation: discriminant typed with unconstrained Float |
| 52 | + type Float_Holder (F : Float := 0.0) is -- UndCC_Violation |
| 53 | + record |
| 54 | + Value : Integer; |
| 55 | + end record; |
| 56 | + |
| 57 | + -- Violation: discriminant typed with Long_Integer (predefined, unconstrained) |
| 58 | + type Long_Holder (N : Long_Integer := 0) is -- UndCC_Violation |
| 59 | + record |
| 60 | + Value : Integer; |
| 61 | + end record; |
| 62 | + |
| 63 | + -- Violation: discriminant typed with Duration (predefined, unconstrained) |
| 64 | + type Timed_Record (T : Duration := 0.0) is -- UndCC_Violation |
| 65 | + record |
| 66 | + Value : Integer; |
| 67 | + end record; |
| 68 | + |
| 69 | + -- Valid: discriminant typed with Boolean (predefined enumeration) |
| 70 | + type Bool_Record (Flag : Boolean := False) is -- UndCC_Valid |
| 71 | + record |
| 72 | + Value : Integer; |
| 73 | + end record; |
| 74 | + |
| 75 | + -- Valid: discriminant typed with Character (predefined enumeration) |
| 76 | + type Char_Record (Ch : Character := ' ') is -- UndCC_Valid |
| 77 | + record |
| 78 | + Value : Integer; |
| 79 | + end record; |
| 80 | + |
| 81 | + -- Valid: named constrained subtype of Integer used as discriminant |
| 82 | + subtype Tiny_Int is Integer range 1 .. 10; |
| 83 | + type Int_Constrained (D : Tiny_Int := 1) is -- UndCC_Valid |
| 84 | + record |
| 85 | + Value : Integer; |
| 86 | + end record; |
| 87 | + |
| 88 | + -- Valid: fixed-point subtype with delta+range constraint |
| 89 | + subtype Small_Delta is Duration delta 0.001 range 0.0 .. 1.0; |
| 90 | + type Delta_Record (T : Small_Delta := 0.0) is -- UndCC_Valid |
| 91 | + record |
| 92 | + Value : Integer; |
| 93 | + end record; |
| 94 | + |
| 95 | + -- Valid: variant record with enumeration discriminant |
| 96 | + type Shape_Kind is (Circle, Rectangle); |
| 97 | + type Shape (Kind : Shape_Kind := Circle) is -- UndCC_Valid |
| 98 | + record |
| 99 | + case Kind is |
| 100 | + when Circle => |
| 101 | + Radius : Float; |
| 102 | + when Rectangle => |
| 103 | + Width : Float; |
| 104 | + Height : Float; |
| 105 | + end case; |
| 106 | + end record; |
| 107 | + |
| 108 | + -- Multiple discriminants: one unconstrained, one constrained |
| 109 | + subtype Max_Cols is Natural range 1 .. 80; |
| 110 | + type Grid (Rows : Natural := 0; Cols : Max_Cols := 1) is -- UndCC_Violation |
| 111 | + record |
| 112 | + Value : Integer; |
| 113 | + end record; |
| 114 | + |
| 115 | + -- Violation: tagged type with unconstrained discriminant |
| 116 | + type Tagged_T (N : Natural := 0) is tagged -- UndCC_Violation |
| 117 | + record |
| 118 | + Value : Integer; |
| 119 | + end record; |
| 120 | + |
| 121 | + -- Violation: unconstrained subtype of Integer resolves to "Integer" |
| 122 | + subtype Bare_Int is Integer; |
| 123 | + type Bare_Holder (D : Bare_Int := 0) is -- UndCC_Violation |
| 124 | + record |
| 125 | + Value : Integer; |
| 126 | + end record; |
| 127 | + |
| 128 | + -- Violation: discriminant with no default value, unconstrained Natural |
| 129 | + type No_Default_Holder (N : Natural) is -- UndCC_Violation |
| 130 | + record |
| 131 | + Data : Number_List (1 .. N); |
| 132 | + end record; |
| 133 | + |
| 134 | + -- Valid: discriminant with no default value, constrained subtype |
| 135 | + type No_Default_Constrained (N : Max_Numbers) is -- UndCC_Valid |
| 136 | + record |
| 137 | + Data : Number_List (1 .. N); |
| 138 | + end record; |
| 139 | + |
| 140 | + -- Valid: modular type discriminant (constrained by its modulus) |
| 141 | + type Byte is mod 256; |
| 142 | + type Byte_Record (B : Byte := 0) is -- UndCC_Valid |
| 143 | + record |
| 144 | + Value : Integer; |
| 145 | + end record; |
| 146 | + |
| 147 | + -- Valid: discriminant typed with a user modular subtype |
| 148 | + subtype Half_Byte is Byte range 0 .. 15; |
| 149 | + type Half_Record (H : Half_Byte := 0) is -- UndCC_Valid |
| 150 | + record |
| 151 | + Value : Integer; |
| 152 | + end record; |
| 153 | + |
| 154 | + -- Violation: multiple unconstrained discriminants — each is flagged |
| 155 | + type Multi_Bad (Rows : Natural := 0; Cols : Natural := 0) is -- UndCC_Violation |
| 156 | + record |
| 157 | + Value : Integer; |
| 158 | + end record; |
| 159 | + |
| 160 | + -- Valid: multiple discriminants all constrained |
| 161 | + subtype Row_Count is Natural range 1 .. 100; |
| 162 | + subtype Col_Count is Natural range 1 .. 200; |
| 163 | + type Multi_Good (Rows : Row_Count := 1; Cols : Col_Count := 1) is -- UndCC_Valid |
| 164 | + record |
| 165 | + Value : Integer; |
| 166 | + end record; |
| 167 | + |
| 168 | +private |
| 169 | + |
| 170 | + -- Violation: private type with unconstrained discriminant |
| 171 | + type Private_Holder (N : Natural := 0) is -- UndCC_Violation |
| 172 | + record |
| 173 | + Value : Integer; |
| 174 | + end record; |
| 175 | + |
| 176 | + -- Valid: private type with constrained discriminant |
| 177 | + subtype Private_Size is Natural range 0 .. 10; |
| 178 | + type Private_Constrained (N : Private_Size := 0) is -- UndCC_Valid |
| 179 | + record |
| 180 | + Value : Integer; |
| 181 | + end record; |
| 182 | + |
| 183 | +end Test_5_4_1; |
0 commit comments