[Ada] Avoid inappropriate error messages regarding aggregates and variant parts

Pierre-Marie de Rodat derodat@adacore.com
Tue Jun 15 10:20:51 GMT 2021

An aggregate of a type that has a variant part has to satisfy certain
rules about the discriminant value governing that variant part. If these
rules are violated, then the front end typically emits a message
associated with the discriminant value. However, this is not useful in
the case where the discriminant value does not come from the aggregate.
This can occur if we have a discriminated tagged type with a variant
part, a type extension that declares a new discriminant (and supplies a
value for the old discriminant), and (later) an aggregate of the
extension type. This case was not being handled correctly in an
Ada_2020-only case.

One might reasonably wonder whether this decision to not generate an
error message could lead to problems with incorrectly accepting some
unit that ought to be rejected; the answer is quite the opposite - this
error message suppression is needed for correctness in order to avoid
rejecting units that ought to be accepted.

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


	* sem_util.adb (Gather_Components): Factor the test that was
	already being used to govern emitting a pre-Ada_2020 error
	message into an expression function,
	OK_Scope_For_Discrim_Value_Error_Messages. Call that new
	function in two places: the point where the same test was being
	performed previously, and in governing emission of a newer
	Ada_2020 error message. In both cases, the out-mode parameter
	Gather_Components.Report_Errors is set to True even if no error
	messages are generated within Gather_Components.
	* sem_util.ads: Correct a comment.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.diff
Type: text/x-diff
Size: 2944 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20210615/0a63d25f/attachment-0001.bin>

More information about the Gcc-patches mailing list