[Ada] No error on misplaced pragma Pure_Function
authorJustin Squirek <squirek@adacore.com>
Tue, 22 May 2018 13:17:58 +0000 (13:17 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Tue, 22 May 2018 13:17:58 +0000 (13:17 +0000)
commiteaf51442d2d20864713492eb0355a9ec4abe0573
tree2f2350fe698fb7516c8089b7a5192930c6c3d6f6
parent80f0c69c2c698023f76d0e5db7e2b42e1fd7b637
[Ada] No error on misplaced pragma Pure_Function

This patch fixes an issue whereby placement of the pragma/aspect Pure_Function
was not verified to have been in the same declarative part as the function
declaration incorrectly allowing it to appear after a function body or in a
different region like a private section.

2018-05-22  Justin Squirek  <squirek@adacore.com>

gcc/ada/

* sem_ch12.adb (In_Same_Declarative_Part): Moved to sem_util.
(Freeze_Subprogram_Body, Install_Body): Modify calls to
In_Same_Declarative_Part.
* sem_prag.adb (Analyze_Pragma-Pragma_Pure_Function): Add check to
verify pragma declaration is within the same declarative list with
corresponding error message.
* sem_util.adb, sem_util.ads (In_Same_Declarative_Part): Moved from
sem_ch12.adb and generalized to be useful outside the scope of
freezing.

gcc/testsuite/

* gnat.dg/pure_function1.adb, gnat.dg/pure_function1.ads,
gnat.dg/pure_function2.adb, gnat.dg/pure_function2.ads: New testcases.

From-SVN: r260507
gcc/ada/ChangeLog
gcc/ada/sem_ch12.adb
gcc/ada/sem_prag.adb
gcc/ada/sem_util.adb
gcc/ada/sem_util.ads
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/pure_function1.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/pure_function1.ads [new file with mode: 0644]
gcc/testsuite/gnat.dg/pure_function2.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/pure_function2.ads [new file with mode: 0644]