diff mbox series

[Ada] Warn on unknown aspect

Message ID 20201015094001.GA67792@adacore.com
State New
Headers show
Series [Ada] Warn on unknown aspect | expand

Commit Message

Pierre-Marie de Rodat Oct. 15, 2020, 9:40 a.m. UTC
Rather than generating a hard error on unknown aspects, generate a
warning which is friendlier wrt compatibility across versions and is
similar to what is done for unknown pragmas.

We keep an error when -gnatd2 is used for now, for strict conformance
until the Ada RM is also changed to allow this behavior.

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

gcc/ada/

	* par-ch13.adb (Get_Aspect_Specifications): Generate a warning
	rather than an error on unknown aspects unless -gnatd2 is used.
	(Aspect_Specifications_Present): Improve detection of unknown
	aspects.
	* debug.adb (Debug_Flag_2): Update document.
diff mbox series

Patch

diff --git a/gcc/ada/debug.adb b/gcc/ada/debug.adb
--- a/gcc/ada/debug.adb
+++ b/gcc/ada/debug.adb
@@ -1032,6 +1032,9 @@  package body Debug is
    --       flag also suppresses the additional messages explaining why a
    --       non-static expression is non-static (see Sem_Eval.Why_Not_Static).
    --       This avoids having to worry about these messages in ACATS testing.
+   --       Finally, this flag is also used for strict legality check, in
+   --       particular it will generate an error instead a warning when
+   --       encountering an unknown pragma.
 
    --  d3   Causes Comperr to dump the contents of the node for which an abort
    --       was detected (normally only the Node_Id of the node is output).


diff --git a/gcc/ada/par-ch13.adb b/gcc/ada/par-ch13.adb
--- a/gcc/ada/par-ch13.adb
+++ b/gcc/ada/par-ch13.adb
@@ -153,9 +153,7 @@  package body Ch13 is
             Result := True;
          else
             Scan; -- past identifier
-            Result := Token = Tok_Arrow or else
-                      Token = Tok_Comma or else
-                      Token = Tok_Semicolon;
+            Result := Token in Tok_Arrow | Tok_Comma | Tok_Is | Tok_Semicolon;
          end if;
 
       --  If earlier than Ada 2012, check for valid aspect identifier (possibly
@@ -178,7 +176,7 @@  package body Ch13 is
             --  defaulted True value. Further checks when analyzing aspect
             --  specification, which may include further aspects.
 
-            elsif Token = Tok_Comma or else Token = Tok_Semicolon then
+            elsif Token in Tok_Comma | Tok_Semicolon then
                Result := True;
 
             elsif Token = Tok_Apostrophe then
@@ -265,7 +263,8 @@  package body Ch13 is
          --  The aspect mark is not recognized
 
          if A_Id = No_Aspect then
-            Error_Msg_N ("& is not a valid aspect identifier", Token_Node);
+            Error_Msg_Warn := not Debug_Flag_2;
+            Error_Msg_N ("<<& is not a valid aspect identifier", Token_Node);
             OK := False;
 
             --  Check bad spelling
@@ -274,7 +273,7 @@  package body Ch13 is
                if Is_Bad_Spelling_Of (Token_Name, Aspect_Names (J)) then
                   Error_Msg_Name_1 := Aspect_Names (J);
                   Error_Msg_N -- CODEFIX
-                    ("\possible misspelling of%", Token_Node);
+                    ("\<<possible misspelling of%", Token_Node);
                   exit;
                end if;
             end loop;