Patchwork [Ada] Issue warning for missing -gnat2012 switch on aspect X'Class

login
register
mail settings
Submitter Arnaud Charlet
Date Aug. 4, 2011, 9:18 a.m.
Message ID <20110804091821.GA5328@adacore.com>
Download mbox | patch
Permalink /patch/108388/
State New
Headers show

Comments

Arnaud Charlet - Aug. 4, 2011, 9:18 a.m.
When encountering aspect syntax in a mode where aspects are not allowed
(language version < Ada 2012), the compiler was issuing a useful warning in
most cases, but not on aspects X'Class. This is now fixed.

Compiling the following code raises the error:

$ gcc -c p.ads
p.ads:3:06: aspect specification is an Ada 2012 feature
p.ads:3:06: unit must be compiled with -gnat2012 switch

package P is
   procedure Proc (X : out Boolean)
     with Post'Class => X;
end P;

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

2011-08-04  Yannick Moy  <moy@adacore.com>

	* par-ch13.adb (Aspect_Specifications_Present): recognize
	"with Identifier'Class =>" as an aspect, so that a meaningful warning
	is issued in Strict mode.
	* par.adb: Fix typos in comments.

Patch

Index: par-ch13.adb
===================================================================
--- par-ch13.adb	(revision 177274)
+++ par-ch13.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2010, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2011, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -89,9 +89,9 @@ 
             Result := Token = Tok_Arrow;
          end if;
 
-      --  If earlier than Ada 2012, check for valid aspect identifier followed
-      --  by an arrow, and consider that this is still an aspect specification
-      --  so we give an appropriate message.
+      --  If earlier than Ada 2012, check for valid aspect identifier (possibly
+      --  completed with 'CLASS) followed by an arrow, and consider that this
+      --  is still an aspect specification so we give an appropriate message.
 
       else
          if Get_Aspect_Id (Token_Name) = No_Aspect then
@@ -100,10 +100,26 @@ 
          else
             Scan; -- past aspect name
 
-            if Token /= Tok_Arrow then
-               Result := False;
+            Result := False;
 
-            else
+            if Token = Tok_Arrow then
+               Result := True;
+
+            elsif Token = Tok_Apostrophe then
+               Scan; -- past apostrophe
+
+               if Token = Tok_Identifier
+                 and then Token_Name = Name_Class
+               then
+                  Scan; -- past CLASS
+
+                  if Token = Tok_Arrow then
+                     Result := True;
+                  end if;
+               end if;
+            end if;
+
+            if Result then
                Restore_Scan_State (Scan_State);
                Error_Msg_SC ("|aspect specification is an Ada 2012 feature");
                Error_Msg_SC ("\|unit must be compiled with -gnat2012 switch");
Index: par.adb
===================================================================
--- par.adb	(revision 177337)
+++ par.adb	(working copy)
@@ -858,8 +858,8 @@ 
       --  attempt at an aspect specification. The default is more strict for
       --  Ada versions before Ada 2012 (where aspect specifications are not
       --  permitted). Note: this routine never checks the terminator token
-      --  for aspects so it does not matter whether the aspect speficiations
-      --  are terminated by semicolon or some other character
+      --  for aspects so it does not matter whether the aspect specifications
+      --  are terminated by semicolon or some other character.
 
       procedure P_Aspect_Specifications
         (Decl      : Node_Id;