[Ada] Wrong column in sloc of "expect name" error for loop variant

Message ID 20180111090336.GA102843@adacore.com
State New
Headers show
Series
  • [Ada] Wrong column in sloc of "expect name" error for loop variant
Related show

Commit Message

Pierre-Marie de Rodat Jan. 11, 2018, 9:03 a.m.
This patch corrects error messages printed when using the pragma Loop_Variant
without a named argument from having an incorrect column number in some cases.

Tested on x86_64-pc-linux-gnu, committed on trunk

2018-01-11  Justin Squirek  <squirek@adacore.com>

gcc/ada/

	* sem_prag.adb (Analyze_Pragma:Pragma_Loop_Variant): Modify error
	message to be printed on the pragma argument identifier.

gcc/testsuite/

	* gnat.dg/loopvar.adb: New testcase.

Patch

--- gcc/ada/sem_prag.adb
+++ gcc/ada/sem_prag.adb
@@ -18297,7 +18297,7 @@  package body Sem_Prag is
             Variant := First (Pragma_Argument_Associations (N));
             while Present (Variant) loop
                if Chars (Variant) = No_Name then
-                  Error_Pragma_Arg ("expect name `Increases`", Variant);
+                  Error_Pragma_Arg_Ident ("expect name `Increases`", Variant);
 
                elsif not Nam_In (Chars (Variant), Name_Decreases,
                                                   Name_Increases)--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/loopvar.adb
@@ -0,0 +1,15 @@ 
+--  { dg-do compile }
+
+procedure Loopvar (S : String) is
+   J : Integer := S'First;
+begin
+   while J < S'Last loop
+      pragma Loop_Variant (J);               -- { dg-error "expect name \"Increases\"" }
+      pragma Loop_Variant (Increasing => J); -- { dg-error "expect name \"Increases\"" }
+      pragma Loop_Variant (J + 1);           -- { dg-error "expect name \"Increases\"" }
+      pragma Loop_Variant (incr => -J + 1);  -- { dg-error "expect name \"Increases\"" }
+      pragma Loop_Variant (decr => -J + 1);  -- { dg-error "expect name \"Decreases\"" }
+      pragma Loop_Variant (foof => -J + 1);  -- { dg-error "expect name \"Increases\" or \"Decreases\"" }
+      J := J + 2;
+   end loop;
+end Loopvar;