aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJustin Squirek <squirek@adacore.com>2018-01-11 08:54:34 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2018-01-11 08:54:34 +0000
commitcb4881181631189b0921b8aaec239016b7c16b46 (patch)
treee43e18317e531a410047d427b06ecebe8f62b001 /gcc
parented27b86ba18a1ffed8ae002412250f0765ab3e72 (diff)
downloadgcc-cb4881181631189b0921b8aaec239016b7c16b46.zip
gcc-cb4881181631189b0921b8aaec239016b7c16b46.tar.gz
gcc-cb4881181631189b0921b8aaec239016b7c16b46.tar.bz2
[Ada] No error on missing enclosing parentheses in Expression Function
This patch fixes an issue whereby an expression within an expression function declaration or completion without proper parenthesization is incorrectly accepted by the compiler. 2018-01-11 Justin Squirek <squirek@adacore.com> gcc/ada/ * par-ch6.adb (Scan_Body_Or_Expression_Function): Add additional check to make sure a given expression function is properly parenthesized. gcc/testsuite/ * gnat.dg/expr_func4.adb: New testcase. From-SVN: r256517
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/ChangeLog5
-rw-r--r--gcc/ada/par-ch6.adb22
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gnat.dg/expr_func4.adb8
4 files changed, 37 insertions, 2 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index fd0a8d3..f66092d 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,8 @@
+2018-01-11 Justin Squirek <squirek@adacore.com>
+
+ * par-ch6.adb (Scan_Body_Or_Expression_Function): Add additional check
+ to make sure a given expression function is properly parenthesized.
+
2018-01-11 Hristian Kirtchev <kirtchev@adacore.com>
* sem_ch6.adb (Analyze_Subprogram_Body_Helper): Check the
diff --git a/gcc/ada/par-ch6.adb b/gcc/ada/par-ch6.adb
index ddcedca..f9a54d2 100644
--- a/gcc/ada/par-ch6.adb
+++ b/gcc/ada/par-ch6.adb
@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
--- Copyright (C) 1992-2017, Free Software Foundation, Inc. --
+-- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -873,7 +873,25 @@ package body Ch6 is
New_Node
(N_Expression_Function, Sloc (Specification_Node));
Set_Specification (Body_Node, Specification_Node);
- Set_Expression (Body_Node, P_Expression);
+ declare
+ Expr : constant Node_Id := P_Expression;
+ begin
+ Set_Expression (Body_Node, Expr);
+
+ -- Check that the full expression is properly
+ -- parenthesized since we may have a left-operand that is
+ -- parenthesized but that is not one of the allowed cases
+ -- with syntactic parentheses.
+
+ if not (Paren_Count (Expr) /= 0
+ or else Nkind_In (Expr, N_Aggregate,
+ N_Extension_Aggregate,
+ N_Quantified_Expression))
+ then
+ Error_Msg ("expression function must be enclosed "
+ & "in parentheses", Sloc (Expr));
+ end if;
+ end;
-- Expression functions can carry pre/postconditions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index e5b1c35..e5d9dde 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2018-01-11 Justin Squirek <squirek@adacore.com>
+
+ * gnat.dg/expr_func4.adb: New testcase.
+
2018-01-11 Hristian Kirtchev <kirtchev@adacore.com>
* gnat.dg/pure_subp_body.adb, gnat.dg/pure_subp_body_pkg.ads: New
diff --git a/gcc/testsuite/gnat.dg/expr_func4.adb b/gcc/testsuite/gnat.dg/expr_func4.adb
new file mode 100644
index 0000000..79fc437
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/expr_func4.adb
@@ -0,0 +1,8 @@
+-- { dg-do compile }
+
+procedure Test_Exp is
+ function X return Boolean is
+ (Integer'Size = 32) or else (Float'Size = 32); -- { dg-error "expression function must be enclosed in parentheses" }
+begin
+ null;
+end;