This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Refine error messages for illegal placement of [Type_]Invariant aspect


Aspect/pragma [Type_]Invariant may be placed illegally on a public type or
a private type without public declaration. This patch gives a different error
message for each case. Now, compiling the following code generates 4 different
messages:

$ gcc -c -gnat12 inv.ads
inv.ads:5:11: aspect "Type_Invariant" only allowed for private type
inv.ads:9:11: aspect "Invariant" only allowed for private type
inv.ads:14:11: aspect "Type_Invariant" only allowed for private type declared in visible part
inv.ads:18:11: aspect "Invariant" only allowed for private type declared in visible part
---
     1	package Inv is
     2	   type Wrap is record
     3	      X : Integer;
     4	   end record
     5	     with Type_Invariant => X mod 2 = 1;
     6	   type Wrap2 is record
     7	      X : Integer;
     8	   end record
     9	     with Invariant => X mod 2 = 1;
    10	private
    11	   type Wrap3 is record
    12	      X : Integer;
    13	   end record
    14	     with Type_Invariant => X mod 2 = 1;
    15	   type Wrap4 is record
    16	      X : Integer;
    17	   end record
    18	     with Invariant => X mod 2 = 1;
    19	end Inv;

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

2011-09-06  Yannick Moy  <moy@adacore.com>

	* sem_ch13.adb (Analyze_Aspect_Specifications, case
	Aspect_Invariant): Do not issue error at this point on illegal
	pragma placement, as this is checked later on when analyzing
	the corresponding pragma.
	* sem_prag.adb (Error_Pragma_Arg_Alternate_Name): New procedure
	similar to Error_Pragma_Arg, except the source name of the
	aspect/pragma to use in warnings may be equal to parameter
	Alt_Name (Analyze_Pragma, case Pragma_Invariant): refine error
	message to distinguish source name of pragma/aspect, and whether
	the illegality resides in the type being public, or being private
	without a public declaration

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]