with Sem_SCIL; use Sem_SCIL;
with Sem_Type; use Sem_Type;
with Sem_Util; use Sem_Util;
+with Sem_Warn; use Sem_Warn;
with Sinfo; use Sinfo;
with Sinfo.Nodes; use Sinfo.Nodes;
with Sinfo.Utils; use Sinfo.Utils;
with Tbuild; use Tbuild;
with Ttypes; use Ttypes;
with Validsw; use Validsw;
+with Warnsw; use Warnsw;
package body Exp_Ch3 is
if Is_Library_Level_Entity (Typ) then
Set_Is_Public (Op);
end if;
+
+ -- Otherwise, the result is defined in terms of the primitive equals
+ -- operator (RM 4.5.2 (24/3)). Report a warning if some component of
+ -- the untagged record has defined a user-defined "=", because it can
+ -- be surprising that the predefined "=" takes precedence over it.
+ -- This warning is not reported when Build_Eq is True because the
+ -- expansion of the built body will call Expand_Composite_Equality
+ -- that will report it if necessary.
+
+ elsif Warn_On_Ignored_Equality then
+ Comp := First_Component (Typ);
+
+ while Present (Comp) loop
+ if Present (User_Defined_Eq (Etype (Comp)))
+ and then not Is_Record_Type (Etype (Comp))
+ and then not Is_Intrinsic_Subprogram
+ (User_Defined_Eq (Etype (Comp)))
+ then
+ Warn_On_Ignored_Equality_Operator
+ (Typ => Typ,
+ Comp_Typ => Etype (Comp),
+ Loc => Sloc (User_Defined_Eq (Etype (Comp))));
+ end if;
+
+ Next_Component (Comp);
+ end loop;
end if;
end Build_Untagged_Record_Equality;
declare
Op : constant Entity_Id := Find_Primitive_Eq (Comp_Type);
+
begin
- if Warn_On_Ignored_Equality
- and then Present (Op)
+ if Present (Op)
and then not In_Predefined_Unit (Base_Type (Comp_Type))
and then not Is_Intrinsic_Subprogram (Op)
then
pragma Assert
(Is_First_Subtype (Outer_Type)
or else Is_Generic_Actual_Type (Outer_Type));
- Error_Msg_Node_2 := Comp_Type;
- Error_Msg_N
- ("?_q?""="" for type & uses predefined ""="" for }",
- Outer_Type);
- Error_Msg_Sloc := Sloc (Op);
- Error_Msg_N ("\?_q?""="" # is ignored here", Outer_Type);
+
+ Warn_On_Ignored_Equality_Operator
+ (Typ => Outer_Type,
+ Comp_Typ => Comp_Type,
+ Loc => Sloc (Op));
end if;
end;
end if;
end Warn_On_Constant_Valid_Condition;
+ ---------------------------------------
+ -- Warn_On_Ignored_Equality_Operator --
+ ---------------------------------------
+
+ procedure Warn_On_Ignored_Equality_Operator
+ (Typ : Entity_Id;
+ Comp_Typ : Entity_Id;
+ Loc : Source_Ptr) is
+ begin
+ if Warn_On_Ignored_Equality then
+ Error_Msg_Node_2 := Comp_Typ;
+ Error_Msg_N ("?_q?""="" for type & uses predefined ""="" for }", Typ);
+
+ Error_Msg_Sloc := Loc;
+ Error_Msg_N ("\?_q?""="" # is ignored here", Typ);
+ end if;
+ end Warn_On_Ignored_Equality_Operator;
+
-----------------------------
-- Warn_On_Known_Condition --
-----------------------------
-- Op assuming that its scalar operands are valid. Emit a warning when the
-- result of the evaluation is True or False.
+ procedure Warn_On_Ignored_Equality_Operator
+ (Typ : Entity_Id;
+ Comp_Typ : Entity_Id;
+ Loc : Source_Ptr);
+ -- Typ is a composite type and Comp_Typ is the type of one of its
+ -- components. Output a warning notifying that the predefined "="
+ -- for Comp_Typ takes precedence over the user-defined equality
+ -- defined at the given location.
+
procedure Warn_On_Known_Condition (C : Node_Id);
-- C is a node for a boolean expression resulting from a relational
-- or membership operation. If the expression has a compile time known