This patch suppresses spurious warnings on an iterator of the form: "for E of C" when C is a parameterless function call, and code expansion is disabled.
Tested on x86_64-pc-linux-gnu, committed on trunk 2011-12-21 Ed Schonberg <schonb...@adacore.com> * sem_ch5.adb (Analyze_Iterator_Specification): If the name of an element iterator is not an entity name we introduce a local renaming declaration for it. To prevent spurious warnings on parameterless function calls that return a container, when expansion is disabled (either explicitly or because of a previous errors) the name must be marked as not coming from source.
Index: sem_ch5.adb =================================================================== --- sem_ch5.adb (revision 182572) +++ sem_ch5.adb (working copy) @@ -2257,11 +2257,17 @@ begin Typ := Etype (Iter_Name); + -- The name in the renaming declaration may be a function call. + -- Indicate that it does not come from source, to suppress + -- spurious warnings on renamings of parameterless functions, + -- a common enough idiom in user-defined iterators. + Decl := Make_Object_Renaming_Declaration (Loc, Defining_Identifier => Id, Subtype_Mark => New_Occurrence_Of (Typ, Loc), - Name => Relocate_Node (Iter_Name)); + Name => + New_Copy_Tree (Iter_Name, New_Sloc => Loc)); Insert_Actions (Parent (Parent (N)), New_List (Decl)); Rewrite (Name (N), New_Occurrence_Of (Id, Loc));