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] Validity checks in generated equality function


When validity checks and Initialize_Scalars are enabled, an equality test on 
scalar uninitialized components raises a constraint error. With this patch,
a constraint error is also raised when applying the primitive equality function
to records that contain uninitialized fields.

The following must raise Constraint_Error without any other output:

    gnatmake -f -q -gnatVa my_test.adb
    my_test
---
with Text_IO;

procedure My_Test is
  type Operation_T is (Flight_Data,
                       Flight_Profiles,
                       Flight_Addressing,
                       Flight_Log);

  type Function_T is(Command,
                     Query,
                     Counts,
                     Counts_On_Flows,
                     Optimise);

  type Origin_T is (None, Live, Simul);

  type T_Abs is abstract tagged record
    Operation    : Operation_T;
    The_Function : Function_T;
  end record;

  type T is new T_Abs with record
    Origin : Origin_T;
  end record;

  X : constant T := (Operation    => Flight_Data,
                     The_Function => Command,
                     Origin       => None);

  Y : T;
begin
  Y.Operation := Flight_Data;
  Y.Origin := None;

  if Y /= X then
    -- expect here a constraint error.
    Text_Io.Put_Line ("X and Y are different");
  end if;

  if Y.The_Function /= X.The_Function then
    -- Got here a constraint error.
    Text_Io.Put_Line ("X.The_Function and Y.The_Function are different");
  end if;
end My_Test;

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

2010-06-23  Ed Schonberg  <schonberg@adacore.com>

	* exp_ch13.adb (Expand_Freeze_Actions): If validity checks and
	Initialize_Scalars are enabled, compile the generated equality function
	for a composite type with full checks enabled, so that validity checks
	are performed on individual components.

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]