aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ada/ChangeLog14
-rw-r--r--gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst23
-rw-r--r--gcc/ada/exp_ch4.adb10
-rw-r--r--gcc/ada/gnat_ugn.texi31
-rw-r--r--gcc/ada/usage.adb2
-rw-r--r--gcc/ada/warnsw.adb12
-rw-r--r--gcc/ada/warnsw.ads7
7 files changed, 99 insertions, 0 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 1dd2a38..ee00d1f 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,17 @@
+2019-07-09 Justin Squirek <squirek@adacore.com>
+
+ * exp_ch4.adb (Expand_N_Allocator): Add conditional to detect
+ the presence of anoymous access type allocators and issue a
+ warning if the appropriate warning flag is enabled.
+ * warnsw.ads: Add new warning flag for anonymous allocators
+ * warnsw.adb (All_Warnings, Restore_Warnings, Save_Warnings,
+ Set_Underscore_Warning_Switch): Register new flags.
+ (WA_Warnings): Register new flag as an "all warnings" switch
+ * usage.adb,
+ doc/gnat_ugn/building_executable_programs_with_gnat.rst:
+ Document new warning switches -gnatw_a and -gnatw_A.
+ * gnat_ugn.texi: Regenerate.
+
2019-07-09 Ed Schonberg <schonberg@adacore.com>
* sem_ch4.adb (Diagnose_Call): Improve error recovery when a
diff --git a/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst b/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst
index 98c3e16..af8f8a4 100644
--- a/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst
+++ b/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst
@@ -2842,6 +2842,29 @@ of the pragma in the :title:`GNAT_Reference_manual`).
compile time that the assertion will fail.
+.. index:: -gnatw_a
+
+:switch:`-gnatw_a`
+ *Activate warnings on anonymous allocators.*
+
+ .. index:: Anonymous allocators
+
+ This switch activates warnings for allocators of anonymous access types,
+ which can involve run-time accessibility checks and lead to unexpected
+ accessibility violations. For more details on the rules involved, see
+ RM 3.10.2 (14).
+
+
+.. index:: -gnatw_A
+
+:switch:`-gnatw_A`
+ *Supress warnings on anonymous allocators.*
+
+ .. index:: Anonymous allocators
+
+ This switch suppresses warnings for anonymous access type allocators.
+
+
.. index:: -gnatwb (gcc)
:switch:`-gnatwb`
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index 99bde93..b4159a7 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -72,6 +72,7 @@ with Ttypes; use Ttypes;
with Uintp; use Uintp;
with Urealp; use Urealp;
with Validsw; use Validsw;
+with Warnsw; use Warnsw;
package body Exp_Ch4 is
@@ -4354,6 +4355,15 @@ package body Exp_Ch4 is
-- Start of processing for Expand_N_Allocator
begin
+ -- Warn on the presence of an allocator of an anonymous access type when
+ -- enabled.
+
+ if Warn_On_Anonymous_Allocators
+ and then Ekind (PtrT) = E_Anonymous_Access_Type
+ then
+ Error_Msg_N ("?use of an anonymous access type allocator", N);
+ end if;
+
-- RM E.2.3(22). We enforce that the expected type of an allocator
-- shall not be a remote access-to-class-wide-limited-private type
diff --git a/gcc/ada/gnat_ugn.texi b/gcc/ada/gnat_ugn.texi
index 124c289..db2adaf 100644
--- a/gcc/ada/gnat_ugn.texi
+++ b/gcc/ada/gnat_ugn.texi
@@ -11040,6 +11040,37 @@ This switch suppresses warnings for assertions where the compiler can tell at
compile time that the assertion will fail.
@end table
+@geindex -gnatw_a
+
+
+@table @asis
+
+@item @code{-gnatw_a}
+
+@emph{Activate warnings on anonymous allocators.}
+
+@geindex Anonymous allocators
+
+This switch activates warnings for allocators of anonymous access types,
+which can involve run-time accessibility checks and lead to unexpected
+accessibility violations. For more details on the rules involved, see
+RM 3.10.2 (14).
+@end table
+
+@geindex -gnatw_A
+
+
+@table @asis
+
+@item @code{-gnatw_A}
+
+@emph{Supress warnings on anonymous allocators.}
+
+@geindex Anonymous allocators
+
+This switch suppresses warnings for anonymous access type allocators.
+@end table
+
@geindex -gnatwb (gcc)
diff --git a/gcc/ada/usage.adb b/gcc/ada/usage.adb
index 1eace05..fb261e5 100644
--- a/gcc/ada/usage.adb
+++ b/gcc/ada/usage.adb
@@ -483,6 +483,8 @@ begin
Write_Line (" A turn off all optional info/warnings");
Write_Line (" .a*+ turn on warnings for failing assertion");
Write_Line (" .A turn off warnings for failing assertion");
+ Write_Line (" _a*+ turn on warnings for anonymous allocators");
+ Write_Line (" _A turn off warnings for anonymous allocators");
Write_Line (" b+ turn on warnings for bad fixed value " &
"(not multiple of small)");
Write_Line (" B* turn off warnings for bad fixed value " &
diff --git a/gcc/ada/warnsw.adb b/gcc/ada/warnsw.adb
index 472f1df..219d440 100644
--- a/gcc/ada/warnsw.adb
+++ b/gcc/ada/warnsw.adb
@@ -56,6 +56,7 @@ package body Warnsw is
Warn_On_Ada_2005_Compatibility := Setting;
Warn_On_Ada_2012_Compatibility := Setting;
Warn_On_All_Unread_Out_Parameters := Setting;
+ Warn_On_Anonymous_Allocators := Setting;
Warn_On_Assertion_Failure := Setting;
Warn_On_Assumed_Low_Bound := Setting;
Warn_On_Atomic_Synchronization := Setting;
@@ -129,6 +130,8 @@ package body Warnsw is
W.Warn_On_Ada_2012_Compatibility;
Warn_On_All_Unread_Out_Parameters :=
W.Warn_On_All_Unread_Out_Parameters;
+ Warn_On_Anonymous_Allocators :=
+ W.Warn_On_Anonymous_Allocators;
Warn_On_Assertion_Failure :=
W.Warn_On_Assertion_Failure;
Warn_On_Assumed_Low_Bound :=
@@ -235,6 +238,8 @@ package body Warnsw is
Warn_On_Ada_2012_Compatibility;
W.Warn_On_All_Unread_Out_Parameters :=
Warn_On_All_Unread_Out_Parameters;
+ W.Warn_On_Anonymous_Allocators :=
+ Warn_On_Anonymous_Allocators;
W.Warn_On_Assertion_Failure :=
Warn_On_Assertion_Failure;
W.Warn_On_Assumed_Low_Bound :=
@@ -478,6 +483,12 @@ package body Warnsw is
function Set_Underscore_Warning_Switch (C : Character) return Boolean is
begin
case C is
+ when 'a' =>
+ Warn_On_Anonymous_Allocators := True;
+
+ when 'A' =>
+ Warn_On_Anonymous_Allocators := False;
+
when others =>
if Ignore_Unrecognized_VWY_Switches then
Write_Line ("unrecognized switch -gnatw_" & C & " ignored");
@@ -705,6 +716,7 @@ package body Warnsw is
Ineffective_Inline_Warnings := True; -- -gnatwp
Warn_On_Ada_2005_Compatibility := True; -- -gnatwy
Warn_On_Ada_2012_Compatibility := True; -- -gnatwy
+ Warn_On_Anonymous_Allocators := True; -- -gnatw_a
Warn_On_Assertion_Failure := True; -- -gnatw.a
Warn_On_Assumed_Low_Bound := True; -- -gnatww
Warn_On_Bad_Fixed_Value := True; -- -gnatwb
diff --git a/gcc/ada/warnsw.ads b/gcc/ada/warnsw.ads
index 23970a9..5875ecd 100644
--- a/gcc/ada/warnsw.ads
+++ b/gcc/ada/warnsw.ads
@@ -38,6 +38,12 @@ package Warnsw is
-- here as time goes by. And in fact a really nice idea would be to put
-- them all in a Warn_Record so that they would be easy to save/restore.
+ Warn_On_Anonymous_Allocators : Boolean := False;
+ -- Warn when allocators for anonymous access types are present, which,
+ -- although not illegal in Ada, may be confusing to users due to how
+ -- accessibility checks get generated. Off by default, modified by use of
+ -- -gnatw_a/_A and set as part of -gnatwa.
+
Warn_On_Late_Primitives : Boolean := False;
-- Warn when tagged type public primitives are defined after its private
-- extensions.
@@ -90,6 +96,7 @@ package Warnsw is
Warn_On_Ada_2005_Compatibility : Boolean;
Warn_On_Ada_2012_Compatibility : Boolean;
Warn_On_All_Unread_Out_Parameters : Boolean;
+ Warn_On_Anonymous_Allocators : Boolean;
Warn_On_Assertion_Failure : Boolean;
Warn_On_Assumed_Low_Bound : Boolean;
Warn_On_Atomic_Synchronization : Boolean;