aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Schonberg <schonberg@adacore.com>2018-05-24 13:05:49 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2018-05-24 13:05:49 +0000
commit861e589e8b957713fb02b5db0773c39bed2dcc61 (patch)
treec70a303f0872fe365859f4ad242d0978dd905b84
parent0347c01b136f864830d1ec9e8d9f1da0cb8029f7 (diff)
downloadgcc-861e589e8b957713fb02b5db0773c39bed2dcc61.zip
gcc-861e589e8b957713fb02b5db0773c39bed2dcc61.tar.gz
gcc-861e589e8b957713fb02b5db0773c39bed2dcc61.tar.bz2
[Ada] Add warning on redundant others_clause in array aggregate
This patch adds a warning on a redundant others_clause in an array aggregate when all index positions are already specified in previous positional or named associations. The warning is emitted when Warn_On_Redundant_Constructs is enabled. 2018-05-24 Ed Schonberg <schonberg@adacore.com> gcc/ada/ * exp_aggr.adb (Flatten): Add a warning on an others clause in an array aggregate with static bounds when named associations cover all index positions and the others clause is redundant. gcc/testsuite/ * gnat.dg/others1.adb: New testcase. From-SVN: r260657
-rw-r--r--gcc/ada/ChangeLog6
-rw-r--r--gcc/ada/exp_aggr.adb6
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gnat.dg/others1.adb13
4 files changed, 29 insertions, 0 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index b30baad..2e80976 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,9 @@
+2018-05-24 Ed Schonberg <schonberg@adacore.com>
+
+ * exp_aggr.adb (Flatten): Add a warning on an others clause in an array
+ aggregate with static bounds when named associations cover all index
+ positions and the others clause is redundant.
+
2018-05-24 Raphael Amiard <amiard@adacore.com>
* libgnat/a-cohama.ads: Add documentation.
diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 356686e..81d3553 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -4581,6 +4581,12 @@ package body Exp_Aggr is
end if;
end loop;
+ if Rep_Count = 0
+ and then Warn_On_Redundant_Constructs
+ then
+ Error_Msg_N ("there are no others?r?", Elmt);
+ end if;
+
exit Component_Loop;
-- Case of a subtype mark, identifier or expanded name
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index ad047a4..6ab7157 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2018-05-24 Ed Schonberg <schonberg@adacore.com>
+
+ * gnat.dg/others1.adb: New testcase.
+
2018-05-24 Justin Squirek <squirek@adacore.com>
* gnat.dg/raise_expr.adb: New testcase.
diff --git a/gcc/testsuite/gnat.dg/others1.adb b/gcc/testsuite/gnat.dg/others1.adb
new file mode 100644
index 0000000..59393fa
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/others1.adb
@@ -0,0 +1,13 @@
+-- { dg-do compile }
+-- { dg-options "-gnatwr" }
+
+procedure Others1 is
+ type Ar is Array (1..10) of Natural;
+ function five return integer is (5);
+ THing : Ar;
+begin
+ Thing := (1..5 => 22, 6 ..10 => 111, others => Five); -- { dg-warning "there are no others" }
+ if Thing (1) /= thing (5) then
+ raise Program_Error;
+ end if;
+end;