diff options
author | Bob Duff <duff@adacore.com> | 2018-01-11 08:53:48 +0000 |
---|---|---|
committer | Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> | 2018-01-11 08:53:48 +0000 |
commit | 4727f693ad0f5ea1f3496d76361204e16abd2615 (patch) | |
tree | c27152b758c5e0df86a26a394d7f3033aeccd6f7 | |
parent | 1ceee6a144f29ef39744316174a69e648c6c6582 (diff) | |
download | gcc-4727f693ad0f5ea1f3496d76361204e16abd2615.zip gcc-4727f693ad0f5ea1f3496d76361204e16abd2615.tar.gz gcc-4727f693ad0f5ea1f3496d76361204e16abd2615.tar.bz2 |
[Ada] Null procedures not allowed in protected definitions
The syntax rules do not allow null procedures in protected definitions. This
patch fixes a bug that accidentally allowed them.
2018-01-11 Bob Duff <duff@adacore.com>
gcc/ada/
* par-ch9.adb (P_Protected_Operation_Declaration_Opt): Give an error if
a null procedure occurs in a protected definition.
gcc/testsuite/
* gnat.dg/protected_null.adb: New testcase.
From-SVN: r256511
-rw-r--r-- | gcc/ada/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/ada/par-ch9.adb | 88 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gnat.dg/protected_null.adb | 15 |
4 files changed, 79 insertions, 33 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 77666f1..eaad418 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,5 +1,10 @@ 2018-01-11 Bob Duff <duff@adacore.com> + * par-ch9.adb (P_Protected_Operation_Declaration_Opt): Give an error if + a null procedure occurs in a protected definition. + +2018-01-11 Bob Duff <duff@adacore.com> + * binderr.ads, namet.ads: Minor reformatting. 2018-01-11 Bob Duff <duff@adacore.com> diff --git a/gcc/ada/par-ch9.adb b/gcc/ada/par-ch9.adb index b5d6d20..6d4c509 100644 --- a/gcc/ada/par-ch9.adb +++ b/gcc/ada/par-ch9.adb @@ -782,6 +782,8 @@ package body Ch9 is return Decl; end P_Entry_Or_Subprogram_With_Indicator; + Result : Node_Id := Empty; + -- Start of processing for P_Protected_Operation_Declaration_Opt begin @@ -789,50 +791,70 @@ package body Ch9 is -- is skipped. loop - if Token = Tok_Pragma then - return P_Pragma; + case Token is + when Tok_Pragma => + Result := P_Pragma; + exit; - elsif Token = Tok_Not or else Token = Tok_Overriding then - return P_Entry_Or_Subprogram_With_Indicator; + when Tok_Not | Tok_Overriding => + Result := P_Entry_Or_Subprogram_With_Indicator; + exit; - elsif Token = Tok_Entry then - return P_Entry_Declaration; + when Tok_Entry => + Result := P_Entry_Declaration; + exit; - elsif Token = Tok_Function or else Token = Tok_Procedure then - return P_Subprogram (Pf_Decl_Pexp); + when Tok_Function | Tok_Procedure => + Result := P_Subprogram (Pf_Decl_Pexp); + exit; - elsif Token = Tok_Identifier then - L := New_List; - P := Token_Ptr; - Skip_Declaration (L); + when Tok_Identifier => + L := New_List; + P := Token_Ptr; + Skip_Declaration (L); - if Nkind (First (L)) = N_Object_Declaration then - Error_Msg - ("component must be declared in private part of " & - "protected type", P); - else - Error_Msg - ("illegal declaration in protected definition", P); - end if; + if Nkind (First (L)) = N_Object_Declaration then + Error_Msg + ("component must be declared in private part of " & + "protected type", P); + else + Error_Msg + ("illegal declaration in protected definition", P); + end if; + -- Continue looping - elsif Token in Token_Class_Declk then - Error_Msg_SC ("illegal declaration in protected definition"); - Resync_Past_Semicolon; + when Tok_For => + Error_Msg_SC + ("representation clause not allowed in protected definition"); + Resync_Past_Semicolon; + -- Continue looping - -- Return now to avoid cascaded messages if next declaration - -- is a valid component declaration. + when others => + if Token in Token_Class_Declk then + Error_Msg_SC ("illegal declaration in protected definition"); + Resync_Past_Semicolon; - return Error; + -- Return now to avoid cascaded messages if next declaration + -- is a valid component declaration. - elsif Token = Tok_For then - Error_Msg_SC - ("representation clause not allowed in protected definition"); - Resync_Past_Semicolon; + Result := Error; + end if; - else - return Empty; - end if; + exit; + end case; end loop; + + if Nkind (Result) = N_Subprogram_Declaration + and then Nkind (Specification (Result)) = + N_Procedure_Specification + and then Null_Present (Specification (Result)) + then + Error_Msg_N + ("protected operation cannot be a null procedure", + Null_Statement (Specification (Result))); + end if; + + return Result; end P_Protected_Operation_Declaration_Opt; ----------------------------------- diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0ea0a93..3bbd01c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2018-01-11 Bob Duff <duff@adacore.com> + + * gnat.dg/protected_null.adb: New testcase. + 2018-01-11 Ed Schonberg <schonberg@adacore.com> * gnat.dg/expr_func3.adb, gnat.dg/expr_func3.ads: New testcase. diff --git a/gcc/testsuite/gnat.dg/protected_null.adb b/gcc/testsuite/gnat.dg/protected_null.adb new file mode 100644 index 0000000..c58fa2b --- /dev/null +++ b/gcc/testsuite/gnat.dg/protected_null.adb @@ -0,0 +1,15 @@ +-- { dg-do compile } + +procedure Proc is + protected Po is + procedure P is null; -- { dg-error " protected operation cannot be a null procedure" } + end Po; + protected body Po is + procedure P is + begin + null; + end P; + end Po; +begin + null; +end; |