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] | |
Tested on i686-linux, committed on mainline.
Because of view exchanges in multiple instantiations, conformance checking
might try to match the a partial view of a type with no discriminants,
with a full view that has defaulted discriminants. In such a case, use the
discriminant constraint of the full view, which must exist because we know
already that the two subtypes have the same base type.
The following example must compile without errors: gcc -c o-p.ads
--
generic
type P_Type (<>) is limited private;
package L is end;
package body M is
procedure E (P : AL.P_Type) is begin null; end;
end;
with L;
generic
with package AL is new L (<>);
package M is
procedure E (P : AL.P_Type);
end;
with M;
package body N is
package AM is new M (BL);
procedure F (Q : Q_Type) renames AM.E;
end N;
with L;
generic
type Q_Type (<>) is private;
package N is
procedure F (Q : Q_Type);
private
package BL is new L (Q_Type);
end N;
package O is
type O_Type is private;
private
type O_Type (B : Boolean := True) is null record;
end O;
with N;
package O.P is new N (O_Type);
--
Also implement an optimization afforded by the introduction into Ada2005 of the
non-null qualifier on access types. Even though expressions involving
access types are never static, it is worthwhile recognizing cases where
checks on access types have a compile-time result. This is already done
to remove redundant constraint checks. This patch emits a warning when
a source check is found to be redundant.
test case:
gcc -c -gnat05 -gnatwa ada2005_check.adb
ada2005_check.adb:6:14: warning: condition is always True
ada2005_check.adb:9:14: warning: condition is always True
ada2005_check.adb:12:16: warning: condition is always False
--
package Ada2005_Check is
type Not_Null_Access_Float is not null access Float;
type Day is
(Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday);
subtype Weekday is Day range Monday .. Friday;
procedure F (Ref : in Not_Null_Access_Float;
Var : in Positive;
D_Day : in out Weekday);
end Ada2005_Check;
package body Ada2005_Check is
procedure F (Ref : in Not_Null_Access_Float;
Var : in Positive;
D_Day : in out Weekday) is
begin
if Ref /= null then
Ref.all := 0.0;
end if;
if Var > 0 then
Ref.all := Float (Var);
end if;
if D_Day = Sunday then
D_Day := Tuesday;
end if;
end F;
end Ada2005_Check;
2005-06-14 Ed Schonberg <schonberg@adacore.com>
* sem_eval.adb (Subtypes_Statically_Match): Use discriminant
constraint of full view if present, when other type is discriminated.
(Eval_Relational_Op): Recognize tests of pointer values against Null,
when the pointer is known to be non-null, and emit appropriate warning.
Attachment:
difs.48
Description: Text document
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |