Skip to content

Commit 412a4e2

Browse files
committed
Merge branch 'mr/thevenoux/gnatcheck#68' into 'master'
Add detector for KP 20273 Closes eng/codepeer/gnatcheck#68 See merge request eng/libadalang/langkit-query-language!619
2 parents fecd6aa + 75644bd commit 412a4e2

6 files changed

Lines changed: 50 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@check(help="possible occurrence of KP 20273",
2+
message="possible occurrence of KP 20273")
3+
fun kp_20273(node) =
4+
|" Flag any iterated association. A Constraint_Error exception
5+
|" might incorrectly be raised when evaluating an array
6+
|" aggregate written using the Ada 2022 iterated component
7+
|" association syntax and known to be empty at compile time.
8+
node is IteratedAssoc
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
pragma Ada_2022;
2+
3+
procedure Main is
4+
type Class_Settings_Type is record
5+
C : Boolean;
6+
end record;
7+
8+
type Class_Index_Type is range 1 .. 10;
9+
10+
type Obj_Settings_List_Type is
11+
array (Class_Index_Type range <>) of Class_Settings_Type;
12+
13+
Obj_Settings_List : constant Obj_Settings_List_Type := [];
14+
15+
type Class_Type is record
16+
C2 : Boolean;
17+
end record;
18+
19+
function Create_Obj (Setttings : Class_Settings_Type) return Class_Type is
20+
begin
21+
return (C2 => True);
22+
end Create_Obj;
23+
24+
Class_List : array (Obj_Settings_List'Range) of Class_Type :=
25+
[for I in Obj_Settings_List'Range => -- FLAG
26+
Create_Obj (Setttings => Obj_Settings_List (I))];
27+
begin
28+
null;
29+
end Main;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
project Prj is
2+
end Prj;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
main.adb:25:7: rule violation: possible occurrence of KP 20273
2+
25 | [for I in Obj_Settings_List'Range => -- FLAG
3+
| _______^
4+
26 || Create_Obj (Setttings => Obj_Settings_List (I))];
5+
||_______________________________________________________^
6+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
driver: checker
2+
rule_name: kp_20273
3+
project: prj.gpr

testsuite/tests/gnatcheck/xml_help/test.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ testsuite_driver: No output file generated by gnatcheck
103103
<check switch="+Rkp_20186" label="possible occurrence of KP 20186"/>
104104
<check switch="+Rkp_20227" label="possible occurrence of KP 20227"/>
105105
<check switch="+Rkp_20229" label="possible occurrence of KP 20229"/>
106+
<check switch="+Rkp_20273" label="possible occurrence of KP 20273"/>
106107
<check switch="+Rkp_ob03_009" label="possible occurrence of KP OB03-009"/>
107108
<check switch="+Rkp_p226_024" label="possible occurrence of KP P226-024 - global analysis required"/>
108109
<check switch="+Rkp_q309_014" label="possible occurrence of KP Q309-014"/>
@@ -631,6 +632,7 @@ testsuite_driver: No output file generated by gnatcheck
631632
<check switch="+Rkp_20186" label="possible occurrence of KP 20186"/>
632633
<check switch="+Rkp_20227" label="possible occurrence of KP 20227"/>
633634
<check switch="+Rkp_20229" label="possible occurrence of KP 20229"/>
635+
<check switch="+Rkp_20273" label="possible occurrence of KP 20273"/>
634636
<check switch="+Rkp_ob03_009" label="possible occurrence of KP OB03-009"/>
635637
<check switch="+Rkp_p226_024" label="possible occurrence of KP P226-024 - global analysis required"/>
636638
<check switch="+Rkp_q309_014" label="possible occurrence of KP Q309-014"/>

0 commit comments

Comments
 (0)