Skip to content

Commit 52f3ca4

Browse files
committed
instrument-c.adb: fix a warning in buffer list units
Building the generated buffer list units for C++ raise warnings because they contain an extern declaration with an initialization expression. First emit an extern declaration, then emit the definition to avoid such warnings. TN: V816-018 Change-Id: I482b4109fa8a10a6fbd303245daa6181d8e79504
1 parent 7f31c04 commit 52f3ca4

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

tools/gnatcov/instrument-c.adb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3667,6 +3667,9 @@ package body Instrument.C is
36673667
end loop;
36683668

36693669
declare
3670+
Buffer_Array_Decl : constant String :=
3671+
"gnatcov_rts_unit_coverage_buffers_array "
3672+
& Unit_Buffers_Array_Name (IC);
36703673
Buffer_Unit_Length : constant String :=
36713674
Count_Type'Image (Instr_Units.Length);
36723675
begin
@@ -3676,16 +3679,22 @@ package body Instrument.C is
36763679

36773680
File_Body.Put_Line ("#include ""gnatcov_rts_c-buffers.h""");
36783681

3682+
-- First create extern declarations for each individual unit buffer
3683+
36793684
for Instr_Unit of Instr_Units loop
36803685
Put_Extern_Decl
36813686
(File_Body,
36823687
Self,
36833688
"gnatcov_rts_unit_coverage_buffers",
36843689
Unit_Buffers_Name (Instr_Unit));
36853690
end loop;
3686-
File_Body.Put (Self.Extern_Prefix);
3687-
File_Body.Put_Line ("gnatcov_rts_unit_coverage_buffers_array "
3688-
& Unit_Buffers_Array_Name (IC) & " = {");
3691+
3692+
-- Then create an extern declaration for the buffer array (necessary
3693+
-- in C++ to set the C linkage), and finally the definition for that
3694+
-- array.
3695+
3696+
File_Body.Put_Line (Self.Extern_Prefix & Buffer_Array_Decl & ";");
3697+
File_Body.Put_Line (Buffer_Array_Decl & " = {");
36893698
File_Body.Put_Line (" " & Buffer_Unit_Length & ",");
36903699
File_Body.Put_Line (" (gnatcov_rts_unit_coverage_buffers *[]) {");
36913700
for Cur in Instr_Units.Iterate loop

0 commit comments

Comments
 (0)