diff options
author | Ed Schonberg <schonberg@adacore.com> | 2019-07-23 08:13:15 +0000 |
---|---|---|
committer | Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> | 2019-07-23 08:13:15 +0000 |
commit | c910db716273c381b4e2f36f3d04c6e480876b63 (patch) | |
tree | 3803b6f751ba27d3ba2f891617dad7aa5a6fcd4d /gcc/testsuite | |
parent | 15e79d66f00317d3acbfa1c93c9460a65174454b (diff) | |
download | gcc-c910db716273c381b4e2f36f3d04c6e480876b63.zip gcc-c910db716273c381b4e2f36f3d04c6e480876b63.tar.gz gcc-c910db716273c381b4e2f36f3d04c6e480876b63.tar.bz2 |
[Ada] Iterators are view-specific
Operational aspects, such as Default_Iterator, are view-specific, and if
such an aspect appears on the full view of a private type, an object of
the type cannot be iterated upon if it is not in the scope of the full
view, This patch diagnoses properly an attempt to iterate over such an
object.
2019-07-23 Ed Schonberg <schonberg@adacore.com>
gcc/ada/
* aspects.ads: New table Operational_Aspect, used to distinguish
between aspects that are view-specific, such as those related to
iterators, and representation aspects that apply to all views of
a type.
* aspects.adb (Find_Aspect): If the aspect being sought is
operational, do not ecamine the full view of a private type to
retrieve it.
* sem_ch5.adb (Analyze_Iterator_Specification): Improve error
message when the intended domain of iteration does not implement
the required iterator aspects.
gcc/testsuite/
* gnat.dg/iter5.adb: Add an expected error.
* gnat.dg/iter6.adb: New testcase.
From-SVN: r273722
Diffstat (limited to 'gcc/testsuite')
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gnat.dg/iter5.adb | 2 | ||||
-rw-r--r-- | gcc/testsuite/gnat.dg/iter6.adb | 40 |
3 files changed, 46 insertions, 1 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0ef05dd..03cf4bb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-07-23 Ed Schonberg <schonberg@adacore.com> + + * gnat.dg/iter5.adb: Add an expected error. + * gnat.dg/iter6.adb: New testcase. + 2019-07-23 Yannick Moy <moy@adacore.com> * gnat.dg/ghost6.adb, gnat.dg/ghost6_pkg.ads: New testcase. diff --git a/gcc/testsuite/gnat.dg/iter5.adb b/gcc/testsuite/gnat.dg/iter5.adb index b17b435..fa21715 100644 --- a/gcc/testsuite/gnat.dg/iter5.adb +++ b/gcc/testsuite/gnat.dg/iter5.adb @@ -4,7 +4,7 @@ with Iter5_Pkg; procedure Iter5 is begin - for The_Filename of Iter5_Pkg.Iterator_For ("C:\Program_Files") loop + for The_Filename of Iter5_Pkg.Iterator_For ("C:\Program_Files") loop -- { dg-error "cannot iterate over \"Item\"" } null; end loop; end Iter5; diff --git a/gcc/testsuite/gnat.dg/iter6.adb b/gcc/testsuite/gnat.dg/iter6.adb new file mode 100644 index 0000000..371352b --- /dev/null +++ b/gcc/testsuite/gnat.dg/iter6.adb @@ -0,0 +1,40 @@ +-- { dg-do compile } + +with Ada.Iterator_Interfaces; + +procedure Iter6 is + package Pkg is + type Item (<>) is limited private; + private + + type Cursor is null record; + + function Constant_Reference (The_Item : aliased Item; + Unused_Index : Cursor) return String + is (""); + + function Has_More (Data : Cursor) return Boolean is (False); + + package List_Iterator_Interfaces is new Ada.Iterator_Interfaces + (Cursor, Has_More); + + function Iterate (The_Item : Item) + return List_Iterator_Interfaces.Forward_Iterator'class + is (raise Program_Error); + + type Item (Name_Length : Natural) is tagged limited record + null; + end record + with + Constant_Indexing => Constant_Reference, + Default_Iterator => Iterate, + Iterator_Element => String; + end Pkg; use Pkg; + + type Item_Ref is access Item; + function F return Item_Ref is (null); +begin + for I of F.all loop -- { dg-error "cannot iterate over \"Item\"" } + null; + end loop; +end; |