From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Javier Miranda <miranda@adacore.com>
Subject: [COMMITTED] ada: Spurious error analyzing 'old or 'result in class-wide conditions
Date: Tue, 16 May 2023 10:41:10 +0200 [thread overview]
Message-ID: <20230516084110.1502069-1-poulhies@adacore.com> (raw)
From: Javier Miranda <miranda@adacore.com>
gcc/ada/
* sem_attr.adb
(Analyze_Attribute_Old_Result): When preanalyzing a class-wide
condition, search in the scopes stack for the subprogram that has
the condition. This is required because returning the current
scope causes reporting spurious errors when the occurrence of the
attribute is found, for example, in a quantified expression.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/sem_attr.adb | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
index 452aabdd436..a07e91b839d 100644
--- a/gcc/ada/sem_attr.adb
+++ b/gcc/ada/sem_attr.adb
@@ -1366,8 +1366,27 @@ package body Sem_Attr is
-- yet on its definite context.
if Inside_Class_Condition_Preanalysis then
- Legal := True;
- Spec_Id := Current_Scope;
+ Legal := True;
+
+ -- Search for the subprogram that has this class-wide condition;
+ -- required to avoid reporting spurious errors since the current
+ -- scope may not be appropriate because the attribute may be
+ -- referenced from the inner scope of, for example, quantified
+ -- expressions.
+
+ -- Although the expression is not installed on its definite
+ -- context, we know that the subprogram has been placed in the
+ -- scope stack by Preanalyze_Condition; we also know that it is
+ -- not a generic subprogram since class-wide pre/postconditions
+ -- can only be applied for primitive operations of tagged types.
+
+ if Is_Subprogram (Current_Scope) then
+ Spec_Id := Current_Scope;
+ else
+ Spec_Id := Enclosing_Subprogram (Current_Scope);
+ end if;
+
+ pragma Assert (Is_Dispatching_Operation (Spec_Id));
return;
end if;
--
2.40.0
reply other threads:[~2023-05-16 8:41 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=20230516084110.1502069-1-poulhies@adacore.com \
--to=poulhies@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=miranda@adacore.com \
/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).