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] Excluded checked on unchecked unions


Checks that would read the value of a discriminant are suppressed on types
that are unchecked unions. If such a record has components whose types have
invariants, applying those checks would require determining the variant in
which they reside, and this cannot be done on an unchecked union. THis patch
recognizes such cases and warns that there are no invariant checks on the
components of the record.

Compiling unc_rec.ads must yield:

   cannot generate code for file unc_rec.ads (package spec)
   unc_rec.ads:12:24: warning:
     invariants cannot be checked on components of unchecked_union type "Rec"

---
package Unc_Rec is
   type Comp is private
     with Invariant => Comp_OK (Comp);
   type Rec (<>) is private;
   function Comp_OK (It : Comp) return Boolean;
private
   type Comp is new Float;

   type Rec (Flag : Boolean) is record
      case Flag is
         when True => Val : Integer;
         when False => Weight : Comp;
      end case;
   end record;

   pragma Unchecked_Union (Rec);
end;
     
Tested on x86_64-pc-linux-gnu, committed on trunk

2014-07-31  Ed Schonberg  <schonberg@adacore.com>

	* exp_ch3.adb (Build_Invariant_Checks): If the enclosing record
	is an unchecked_union, warn that invariants will not be checked
	on components that have them.

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]