public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-1885] [Ada] Overriding errors on renamings and instances overriding predefined operators
@ 2021-06-29 14:25 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-06-29 14:25 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:4c07e6d67921bb0793890550094d464153e479eb
commit r12-1885-g4c07e6d67921bb0793890550094d464153e479eb
Author: Gary Dismukes <dismukes@adacore.com>
Date: Mon Apr 12 17:20:33 2021 -0400
[Ada] Overriding errors on renamings and instances overriding predefined operators
gcc/ada/
* sem_ch6.ads (Can_Override_Operator): Function declaration
moved from package body to package spec.
* sem_ch6.adb (Check_Overriding_Indicator): Now use test of
whether the subprogram's Chars is an operator name, to handle
cases of function instances whose entity is
N_Defining_Identifier rather than N_Defining_Operator_Symbol.
(Can_Override_Operator): Function declaration moved to package
spec. Now use test of whether the subprogram's Chars is an
operator name, to handle cases of function instances whose
entity is N_Defining_Identifier rather than
N_Defining_Operator_Symbol.
* sem_ch8.adb (Analyze_Renamed_Subprogram): Check for
possibility of an overridden predefined operator, and suppress
the "not overriding" message in that case.
Diff:
---
gcc/ada/sem_ch6.adb | 12 +++++++-----
gcc/ada/sem_ch6.ads | 3 +++
gcc/ada/sem_ch8.adb | 4 +++-
3 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
index 7b4b288e050..c361acc4937 100644
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -132,9 +132,6 @@ package body Sem_Ch6 is
-- Does all the real work of Analyze_Subprogram_Body. This is split out so
-- that we can use RETURN but not skip the debug output at the end.
- function Can_Override_Operator (Subp : Entity_Id) return Boolean;
- -- Returns true if Subp can override a predefined operator.
-
procedure Check_Conformance
(New_Id : Entity_Id;
Old_Id : Entity_Id;
@@ -7321,7 +7318,7 @@ package body Sem_Ch6 is
-- predefined signature, because we know already that there is no
-- explicit overridden operation.
- elsif Nkind (Subp) = N_Defining_Operator_Symbol then
+ elsif Chars (Subp) in Any_Operator_Name then
if Must_Not_Override (Spec) then
-- If this is not a primitive or a protected subprogram, then
@@ -8313,7 +8310,12 @@ package body Sem_Ch6 is
Typ : Entity_Id;
begin
- if Nkind (Subp) /= N_Defining_Operator_Symbol then
+ -- Return False if not an operator. We test the name rather than testing
+ -- that the Nkind is N_Defining_Operator_Symbol, because there are cases
+ -- where an operator entity can be an N_Defining_Identifier (such as for
+ -- function instantiations).
+
+ if Chars (Subp) not in Any_Operator_Name then
return False;
else
diff --git a/gcc/ada/sem_ch6.ads b/gcc/ada/sem_ch6.ads
index 9579582763b..4afcf36c18d 100644
--- a/gcc/ada/sem_ch6.ads
+++ b/gcc/ada/sem_ch6.ads
@@ -51,6 +51,9 @@ package Sem_Ch6 is
-- and body declarations. Returns the defining entity for the
-- specification N.
+ function Can_Override_Operator (Subp : Entity_Id) return Boolean;
+ -- Returns true if Subp can override a predefined operator
+
procedure Check_Conventions (Typ : Entity_Id);
-- Ada 2005 (AI-430): Check that the conventions of all inherited and
-- overridden dispatching operations of type Typ are consistent with their
diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb
index 1c68eed693b..aa33c507575 100644
--- a/gcc/ada/sem_ch8.adb
+++ b/gcc/ada/sem_ch8.adb
@@ -3299,7 +3299,9 @@ package body Sem_Ch8 is
Style.Missing_Overriding (N, Rename_Spec);
end if;
- elsif Must_Override (Specification (N)) then
+ elsif Must_Override (Specification (N))
+ and then not Can_Override_Operator (Rename_Spec)
+ then
Error_Msg_NE ("subprogram& is not overriding", N, Rename_Spec);
end if;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-06-29 14:25 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-29 14:25 [gcc r12-1885] [Ada] Overriding errors on renamings and instances overriding predefined operators 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).