+2018-07-17 Ed Schonberg <schonberg@adacore.com>
+
+ * sem_ch6.adb (Check_Untagged_Equality): Extend check to operations
+ declared in the same scope as the operand type, when that scope is a
+ procedure.
+
2018-07-17 Ed Schonberg <schonberg@adacore.com>
* exp_unst.adb (Unnest_Subprograms): Do nothing if the expander is not
if Is_Frozen (Typ) then
- -- If the type is not declared in a package, or if we are in the body
- -- of the package or in some other scope, the new operation is not
- -- primitive, and therefore legal, though suspicious. Should we
- -- generate a warning in this case ???
+ -- The check applies to a primitive operation, so check that type
+ -- and equality operation are in the same scope.
- if Ekind (Scope (Typ)) /= E_Package
- or else Scope (Typ) /= Current_Scope
- then
+ if Scope (Typ) /= Current_Scope then
return;
-- If the type is a generic actual (sub)type, the operation is not
("\move declaration to package spec (Ada 2012)?y?", Eq_Op);
end if;
- -- Otherwise try to find the freezing point
+ -- Otherwise try to find the freezing point for better message.
else
Obj_Decl := Next (Parent (Typ));
end if;
exit;
+
+ -- If we reach generated code for subprogram declaration
+ -- or body, it is the body that froze the type and the
+ -- declaration is legal.
+
+ elsif Sloc (Obj_Decl) = Sloc (Decl) then
+ return;
end if;
Next (Obj_Decl);
+2018-07-17 Ed Schonberg <schonberg@adacore.com>
+
+ * gnat.dg/equal3.adb: New testcase.
+
2018-07-17 Justin Squirek <squirek@adacore.com>
* gnat.dg/split_args.adb: New testcase.
--- /dev/null
+-- { dg-do compile }
+
+procedure Equal3 is
+ type R is record
+ A, B : Integer;
+ end record;
+
+ package Pack is
+ type RR is record
+ C : R;
+ end record;
+
+ X : RR := (C => (A => 1, B => 1));
+ Y : RR := (C => (A => 1, B => 2));
+ pragma Assert (X /= Y); --@ASSERT:PASS
+
+ end Pack;
+ use Pack;
+ function "=" (X, Y : R) return Boolean is (X.A = Y.A); -- { dg-error "equality operator must be declared before type \"R\" is frozen \\(RM 4.5.2 \\(9.8\\)\\) \\(Ada 2012\\)" }
+begin
+ pragma Assert (X /= Y); --@ASSERT:FAIL
+end Equal3;