diff mbox

[Ada] New switch -gnateP to warn on Pure/Preelaborate errors

Message ID 20101026124553.GA10943@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Oct. 26, 2010, 12:45 p.m. UTC
This patch implements a new switch -gnateP which causes the
compiler to warn on categorization errors (most notably those
involving pragma Pure/Preelaborate, hence the P). Normally
these are errors, but with this switch set they are treated
as warnings. This has always been true in -gnatg mode, and
this behavior is retained.

The following is a test program:

package ignorecatimpure is
end;

with ignorecatimpure;
package ignorecatpure is
   pragma Pure;
end;

compiling ignorecatpure with -gnatj60 -gnatld7 -gnateP gives:

     1. with ignorecatimpure;
             |
        >>> warning: cannot depend on "ignorecatimpure"
            (wrong categorization), pure unit cannot depend
            on non-pure unit

     2. package ignorecatpure is
     3.    pragma Pure;
     4. end;

Tested on x86_64-pc-linux-gnu, committed on trunk

2010-10-26  Robert Dewar  <dewar@adacore.com>

	* opt.ads (Treat_Categorization_Errors_As_Warnings): New flag
	* sem_cat.adb (Check_Categorization_Dependencies):
	Use Check_Categorization_Dependencies
	* switch-c.adb: GNAT Mode sets Treat_Categorization_Errors_As_Warnings
	-gnateP sets Treat_Categorization_Errors_As_Warnings
	* usage.adb: Add line for -gnateP switch
diff mbox

Patch

Index: switch-c.adb
===================================================================
--- switch-c.adb	(revision 165935)
+++ switch-c.adb	(working copy)
@@ -495,6 +495,11 @@  package body Switch.C is
 
                      Ptr := Max + 1;
 
+                  --  -gnateP (Treat pragma Pure/Preelaborate errs as warnings)
+
+                  when 'P' =>
+                     Treat_Categorization_Errors_As_Warnings := True;
+
                   --  -gnatez (final delimiter of explicit switches)
 
                   --  All switches that come after -gnatez have been added by
@@ -562,6 +567,10 @@  package body Switch.C is
                Set_GNAT_Mode_Warnings;
                Set_GNAT_Style_Check_Options;
 
+               --  Other special modes set by -gnatg
+
+               Treat_Categorization_Errors_As_Warnings := True;
+
             --  Processing for G switch
 
             when 'G' =>
Index: usage.adb
===================================================================
--- usage.adb	(revision 165935)
+++ usage.adb	(working copy)
@@ -207,6 +207,11 @@  begin
    Write_Switch_Char ("ep=?");
    Write_Line ("Specify preprocessing data file, e.g. -gnatep=prep.data");
 
+   --  Line for -gnateP switch
+
+   Write_Switch_Char ("eP");
+   Write_Line ("Pure/Prelaborate errors generate warnings rather than errors");
+
    --  Line for -gnateS switch
 
    Write_Switch_Char ("eS");
Index: opt.ads
===================================================================
--- opt.ads	(revision 165951)
+++ opt.ads	(working copy)
@@ -1230,6 +1230,11 @@  package Opt is
    --  Tolerate time stamp and other consistency errors. If this flag is set to
    --  True (-t), then inconsistencies result in warnings rather than errors.
 
+   Treat_Categorization_Errors_As_Warnings : Boolean := False;
+   --  Normally categorization errors are true illegalities. If this switch
+   --  is set, then such errors result in warning messages rather than error
+   --  messages. Set True by -gnatg or -gnateP (P for Pure/Preelaborate).
+
    Treat_Restrictions_As_Warnings : Boolean := False;
    --  GNAT
    --  Set True to treat pragma Restrictions as Restriction_Warnings. Set by
Index: sem_cat.adb
===================================================================
--- sem_cat.adb	(revision 165935)
+++ sem_cat.adb	(working copy)
@@ -226,10 +226,10 @@  package body Sem_Cat is
 
       if Err then
 
-         --  These messages are warnings in GNAT mode, to allow it to be
-         --  judiciously turned off. Otherwise it is a real error.
+         --  These messages are warnings in GNAT mode or if the -gnateC switch
+         --  was set. Otherwise these are real errors for real illegalities.
 
-         Error_Msg_Warn := GNAT_Mode;
+         Error_Msg_Warn := Treat_Categorization_Errors_As_Warnings;
 
          --  Don't give error if main unit is not an internal unit, and the
          --  unit generating the message is an internal unit. This is the