+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
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`
with Uintp; use Uintp;
with Urealp; use Urealp;
with Validsw; use Validsw;
+with Warnsw; use Warnsw;
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
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)
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 " &
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;
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 :=
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 :=
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");
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
-- 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.
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;