public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <pmderodat@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-1452] [Ada] Avoid inappropriate error messages regarding aggregates and variant parts
Date: Tue, 15 Jun 2021 10:20:51 +0000 (GMT)	[thread overview]
Message-ID: <20210615102051.19E8A398B172@sourceware.org> (raw)

https://gcc.gnu.org/g:4dbdeeb889dfd4dcce214e1525b56a7464128a3c

commit r12-1452-g4dbdeeb889dfd4dcce214e1525b56a7464128a3c
Author: Steve Baird <baird@adacore.com>
Date:   Wed Feb 17 17:54:53 2021 -0800

    [Ada] Avoid inappropriate error messages regarding aggregates and variant parts
    
    gcc/ada/
    
            * 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.

Diff:
---
 gcc/ada/sem_util.adb | 26 +++++++++++++++++++-------
 gcc/ada/sem_util.ads |  3 ++-
 2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 01690f3a35e..73a6f79f36f 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -9990,6 +9990,18 @@ package body Sem_Util is
       Discrim_Value         : Node_Id;
       Discrim_Value_Subtype : Node_Id;
       Discrim_Value_Status  : Discriminant_Value_Status := Bad;
+
+      function OK_Scope_For_Discrim_Value_Error_Messages return Boolean is
+        (Scope (Original_Record_Component
+                        (Entity (First (Choices (Assoc))))) = Typ);
+      --  Used to avoid generating error messages having a source position
+      --  which refers to somewhere (e.g., a discriminant value in a derived
+      --  tagged type declaration) unrelated to the offending construct. This
+      --  is required for correctness - clients of Gather_Components such as
+      --  Sem_Ch3.Create_Constrained_Components depend on this function
+      --  returning True while processing semantically correct examples;
+      --  generating an error message in this case would be wrong.
+
    begin
       Report_Errors := False;
 
@@ -10178,9 +10190,7 @@ package body Sem_Util is
             --  every value of that subtype (and there must be at least one)
             --  selects the same variant.
 
-            if Scope (Original_Record_Component
-                        ((Entity (First (Choices (Assoc)))))) = Typ
-            then
+            if OK_Scope_For_Discrim_Value_Error_Messages then
                if Ada_Version >= Ada_2020 then
                   Error_Msg_FE
                     ("value for discriminant & must be static or " &
@@ -10299,10 +10309,12 @@ package body Sem_Util is
                         (Subset => Discrim_Value_Subtype_Intervals,
                          Of_Set => Variant_Intervals)
                then
-                  Error_Msg_NE
-                    ("no single variant is associated with all values of " &
-                     "the subtype of discriminant value &",
-                     Discrim_Value, Discrim);
+                  if OK_Scope_For_Discrim_Value_Error_Messages then
+                     Error_Msg_NE
+                       ("no single variant is associated with all values of " &
+                        "the subtype of discriminant value &",
+                        Discrim_Value, Discrim);
+                  end if;
                   Report_Errors := True;
                   return;
                end if;
diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads
index 83791fc271e..2e26c283d71 100644
--- a/gcc/ada/sem_util.ads
+++ b/gcc/ada/sem_util.ads
@@ -1079,7 +1079,8 @@ package Sem_Util is
    --     to its tail.
    --
    --    Report_Errors is set to True if the values of the discriminants are
-   --     non-static.
+   --     insufficiently static (see body for details of what that means).
+
    --
    --    Allow_Compile_Time if set to True, allows compile time known values in
    --     Governed_By expressions in addition to static expressions.


                 reply	other threads:[~2021-06-15 10:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210615102051.19E8A398B172@sourceware.org \
    --to=pmderodat@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).