]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Tune warning about assignment just before a raise statement
authorPiotr Trojanek <trojanek@adacore.com>
Thu, 2 Mar 2023 14:11:40 +0000 (15:11 +0100)
committerMarc Poulhiès <poulhies@adacore.com>
Thu, 25 May 2023 07:44:15 +0000 (09:44 +0200)
Tune warning about a possibly ineffective assignment to a formal
parameter that happens just before a raise statement.

The warning is now emitted for parameters of all by-copy types and not
just of scalar types (this gives more warnings), but is suppressed for
aliased parameters (this removes some spurious warnings).

gcc/ada/

* sem_ch11.adb (Analyze_Raise_Expression): Tune warning condition.
* libgnat/g-dirope.ads (Open): Remove a potentially inaccurate comment.
* libgnat/g-dirope.adb (Open): Remove a potentially useless assignment;
the Dir output parameter should be assigned a null value anyway by the
preceding call to Free.

gcc/ada/libgnat/g-dirope.adb
gcc/ada/libgnat/g-dirope.ads
gcc/ada/sem_ch11.adb

index 127f6ba8e80e2b62ceeb7c60deeef2d7799e1fc9..3cebc9fe4a767602aa5fdb0a9362b4790586ca73 100644 (file)
@@ -636,7 +636,6 @@ package body GNAT.Directory_Operations is
 
       if not Is_Open (Dir) then
          Free (Dir);
-         Dir := Null_Dir;
          raise Directory_Error;
       end if;
    end Open;
index a3a8e4635f007d1de7ae003a23caed88dca24dc7..cdb99ff3267fd3560c927f4abd7586512270d1a6 100644 (file)
@@ -210,8 +210,7 @@ package GNAT.Directory_Operations is
    procedure Open (Dir : out Dir_Type; Dir_Name : Dir_Name_Str);
    --  Opens the directory named by Dir_Name and returns a Dir_Type value
    --  that refers to this directory, and is positioned at the first entry.
-   --  Raises Directory_Error if Dir_Name cannot be accessed. In that case
-   --  Dir will be set to Null_Dir.
+   --  Raises Directory_Error if Dir_Name cannot be accessed.
 
    procedure Close (Dir : in out Dir_Type);
    --  Closes the directory stream referred to by Dir. After calling Close
index 5471111d6824bdd62b198999a40c459c50ab2a7c..73eca7a603e1901eee0f2915c90eac0807c0e0ff 100644 (file)
@@ -543,11 +543,12 @@ package body Sem_Ch11 is
             if Present (P) and then Nkind (P) = N_Assignment_Statement then
                L := Name (P);
 
-               --  Give warning for assignment to scalar formal
+               --  Give warning for assignment to by-copy formal
 
-               if Is_Scalar_Type (Etype (L))
-                 and then Is_Entity_Name (L)
+               if Is_Entity_Name (L)
                  and then Is_Formal (Entity (L))
+                 and then Is_By_Copy_Type (Etype (L))
+                 and then not Is_Aliased (Entity (L))
 
                  --  Do this only for parameters to the current subprogram.
                  --  This avoids some false positives for the nested case.