public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Missing semantic error on ineffective Others_Clause
@ 2021-05-06  7:58 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-05-06  7:58 UTC (permalink / raw)
  To: gcc-patches; +Cc: Ed Schonberg

[-- Attachment #1: Type: text/plain, Size: 744 bytes --]

Compiler fails to reject an Others_Clause in an aggregate for a
constrained array type when previous components of the aggregate cover
the full index range of the array subtype, and the expression in the
Others_Clause has a type incompatible with the component type of the
array. The Others_Clause does not generate any code but the construct is
illegal. The error was previously reported only in -gnatc mode.

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

gcc/ada/

	* exp_aggr.adb (Expand_Array_Aggregate): If the expression in an
	Others_Clause has not been analyzed because previous analysis of
	the enclosing aggregate showed the clause to be ineffective i.e.
	cover a null range, analyze it now to detect a possible type
	illegality.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1113 bytes --]

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -5958,6 +5958,21 @@ package body Exp_Aggr is
 
             if Nkind (First (Choice_List (Assoc))) = N_Others_Choice then
                Others_Present (Dim) := True;
+
+               --  An others_clause may be superfluous if previous components
+               --  cover the full given range of a constrained array. In such
+               --  a case an others_clause does not contribute any additional
+               --  components and has not been analyzed. We analyze it now to
+               --  detect type errors in the expression, even though no code
+               --  will be generated for it.
+
+               if Dim = Aggr_Dimension
+                 and then Nkind (Assoc) /= N_Iterated_Component_Association
+                 and then not Analyzed (Expression (Assoc))
+                 and then not Box_Present (Assoc)
+               then
+                  Preanalyze_And_Resolve (Expression (Assoc), Ctyp);
+               end if;
             end if;
          end if;
 



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-06  7:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-06  7:58 [Ada] Missing semantic error on ineffective Others_Clause Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).