This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] improve warning for unused var


Tested on i686-linux, committed on trunk

This patch addresses the issue of not giving
the warning that "X is not modified, could be declared as constant"
for the case of e.g. unbounded strings, as shown by the example below
which did give the second warning when compiled with -gnatwa.

     1. with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
     2. procedure Cst is
     3.    C : Integer := 12;
           |
        >>> warning: "C" is not modified, could be declared constant
        >>> warning: variable "C" is not referenced

     4.    V : Unbounded_String := To_Unbounded_String ("toto");
           |
        >>> warning: "V" is not modified, could be declared constant

     5.    W : Unbounded_String;
           |
        >>> warning: variable "W" is assigned but never read

     6. begin
     7.    W := V;
     8. end Cst;

--
Descendants of a limited interface are not necessarily limited: they must either
have a limited non-interface ancestor, or be declared explicitly as limited.
However, if the ancestor, or a progenitor, is a synchronized interface, the
type is limited, which among other things implies that default stream operations
are not defined for them.

gnat.dg/specs/limited1.ads must compile quietly.

--
This patch also improves tracking of null values, and allows more cases
for detecting null dereferences at compile time. There are two aspects
to this. First the Known_Null routine is enhanced to recognize the case
of null constants. Second initial expressions in object declarations
are processed like assignments with respect to recording null/not-null
indications.

The following program shows the additional warnings at work:

procedure k is
   type r is access integer;
   q1 : r := null;
   q2 : constant r := null;
   q3 : r;
   g : integer;
   procedure internal is begin null; end;
begin
   g := q1.all;
   g := q2.all;
   g := q3.all;
   internal;
   g := q1.all;
   g := q2.all;
   g := q3.all;
   q1 := null;
   q3 := null;
   g := q1.all;
   g := q2.all;
   g := q3.all;
   return;
end k;

This program generates the following warnings:

k.adb:9:09: warning: null value not allowed here
k.adb:9:09: warning: "Constraint_Error" will be raised at run time
k.adb:10:09: warning: null value not allowed here
k.adb:10:09: warning: "Constraint_Error" will be raised at run time
k.adb:11:09: warning: null value not allowed here
k.adb:11:09: warning: "Constraint_Error" will be raised at run time
k.adb:14:09: warning: null value not allowed here
k.adb:14:09: warning: "Constraint_Error" will be raised at run time
k.adb:15:09: warning: "q3" may be null
k.adb:18:09: warning: null value not allowed here
k.adb:18:09: warning: "Constraint_Error" will be raised at run time
k.adb:19:09: warning: null value not allowed here
k.adb:19:09: warning: "Constraint_Error" will be raised at run time
k.adb:20:09: warning: null value not allowed here
k.adb:20:09: warning: "Constraint_Error" will be raised at run time

--
In Ada2005, anonymous access to subprograms can be used as access discriminants
for all discriminated types. This includes tasks and protected types.

gnat.dg/discr_test.adb must must compile quietly.

2007-08-14  Robert Dewar  <dewar@adacore.com>
	    Ed Schonberg  <schonberg@adacore.com>

	* sem_ch11.adb: Improved warnings for unused variables

	* sem_ch3.ads, sem_ch3.adb (Build_Derived_Record_Type): If the ancestor
	is a synchronized interface, the derived type is limited.
	(Analyze_Object_Declaration): Mark the potential coextensions in the
	definition and expression of an object declaration node.
	(Build_Derived_Type): For the completion of a private type declaration
	with a derived type declaration, chain the parent type's representation
	items to the last representation item of the derived type (not the
	first one) if they are not present already.
	(Analyze_Object_Declaration, Constant_Redeclaration): Allow incomplete
	object declaration of forward references to tags.
	(Access_Subprogram_Declaration): In Ada2005, anonymous access to
	subprogram types can appear as access discriminants of synchronized
	types.
	(OK_For_Limited_Init_In_05): The initialization is legal is it is a call
	given in prefixed form as a selected component.
	(Process_Discriminants): If not all discriminants have defaults, place
	error message on a default that is present.
	(Analyze_Private_Extension_Declaration): Diagnose properly an attempt to
	extend a synchronized tagged type.
	Improved warnings for unused variables
	(Is_Visible_Component): Fix a visibility hole on a component inherited
	by a private extension when parent is itself declared as a private
	extension, and the derivation is in a child unit.
	(Find_Hidden_Interface): Move spec from the package body.

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]