3

I want to have the uninitialized variables in my gnatcheck report but the format of this warning is incompatible with the format:

+RWarnings:xxxx (with xxxx the differents warnings switches)

I have try to write this programming rules like the others: +RWuninitialized but it don't work.

And the switch -Wuninitialized doesn't exist for gnatcheck.

Vasfed
  • 18,013
  • 10
  • 47
  • 53
user1111
  • 33
  • 4

1 Answers1

3

The documentation for adding the results of compiler checks to Gnatcheck’s output says about Warnings (with some editing)

To record compiler warnings (see Warning Message Control section in GNAT User’s Guide), use the Warnings rule with a parameter that is a valid static_string_expression argument of the GNAT pragma Warnings (see “Pragma Warnings” in the GNAT Reference Manual). Note that [the]in case of gnatcheck s parameter, that corresponds to the GNAT -gnatws option, disables all the specific warnings, but [does] not suppresses the warning mode, and [the] e parameter, corresponding to -gnatwe that means "treat warnings as errors", does not have any effect.

If you go to look up "pragma Warnings” in the GNAT Reference Manual, you’ll find it sends you off to the compiler:

The string is a list of letters specifying which warnings are to be activated and which deactivated. The code for these letters is the same as the string used in the command line switch controlling warnings [-gnatw]. For a brief summary, use the gnatmake command with no arguments, which will generate usage information containing the list of warnings switches supported.

Following this advice, there seems to be no -gnatwx to give you the effect of -Wuninitialized. However, if you turn on all warnings

project Checks is
   for Source_Files use ("checks.adb");
   package Check is
   for Default_Switches ("ada") use
     (
      "-rules",
      "+RWarnings:.e"
     );
   end Check;
end Checks;

and run it on

procedure Checks (Input : Integer; Result : out Integer) is
   X : Integer;
   Y : Integer;
   Z : Integer;
begin
   if (Y > 0) = True then
      Result := X;
   end if;
end Checks;

you get

checks.adb:1:19: warning: formal parameter "Input" is not referenced
checks.adb:2:04: warning: variable "X" is read but never assigned
checks.adb:3:04: warning: variable "Y" is read but never assigned
checks.adb:4:04: warning: variable "Z" is never read and never assigned
checks.adb:6:15: warning: comparison with True is redundant

where the warnings on lines 2, 3 (and 4) mean the same as “uninitialized”, I think.

You can then turn off the warnings you don’t want; for example, "+RWarnings:.eF” will "turn off warnings for unreferenced formal”, and suppresses the warning on line 1.

Simon Wright
  • 25,108
  • 2
  • 35
  • 62
  • There are a distinct difference between -gnatwe and -Wuninitialized: in a long procedure you can create an uninitialized variable and after affect a value so the -gnatwe doesn't detect this warning. But thanks to you I understand the whole issue! – user1111 Jul 01 '16 at 07:14
  • `-gnatwe` means “treat all warnings as errors”; `-gnatw.e` is what means “turn on all warnings, even really obscure ones” (I paraphrase :). For most purpose, `-gnatwa` does OK. – Simon Wright Jul 06 '16 at 07:52