aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada
diff options
context:
space:
mode:
authorGary Dismukes <dismukes@adacore.com>2018-01-11 08:56:18 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2018-01-11 08:56:18 +0000
commitfab588529a9605df33ca25a97f5b0e7c56f6c3be (patch)
tree6203c8953870146f3f20b821fbd88c7447aab377 /gcc/ada
parenta2dbe7d5ae0627efc7079ff59f39487b78a2423d (diff)
downloadgcc-fab588529a9605df33ca25a97f5b0e7c56f6c3be.zip
gcc-fab588529a9605df33ca25a97f5b0e7c56f6c3be.tar.gz
gcc-fab588529a9605df33ca25a97f5b0e7c56f6c3be.tar.bz2
[Ada] Warning on out-of-range value for default-initialized scalar object
When an object of a type with a specified Default_Value aspect is declared without an explicit initial value and the default value is out of range of the objects subtype, the compiler now issues a warning that Constraint_Error will be raised due to an out-of-range value. The test below must output a compiler warning as follows: $ gcc -c -gnatj70 default_warning.adb default_warning.adb:7:08: warning: value not in range of type "Subint" defined at line 5, "Constraint_Error" will be raised at run time procedure Default_Warning is type Int_With_Default is new Integer with Default_Value => 0; subtype Subint is Int_With_Default range 1 .. 100; S : Subint; begin null; end Default_Warning; 2018-01-11 Gary Dismukes <dismukes@adacore.com> gcc/ada/ * exp_ch3.adb (Default_Initialize_Object): Call New_Copy_Tree on the result of Get_Simple_Init_Value and pass the source location of the object declaration's object_definition. From-SVN: r256524
Diffstat (limited to 'gcc/ada')
-rw-r--r--gcc/ada/ChangeLog6
-rw-r--r--gcc/ada/exp_ch3.adb5
2 files changed, 10 insertions, 1 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 63c2a95..aa69c92 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,9 @@
+2018-01-11 Gary Dismukes <dismukes@adacore.com>
+
+ * exp_ch3.adb (Default_Initialize_Object): Call New_Copy_Tree on the
+ result of Get_Simple_Init_Value and pass the source location of the
+ object declaration's object_definition.
+
2018-01-11 Ed Schonberg <schonberg@adacore.com>
* exp_ch6.adb (Make_Build_In_Place_Call_In_Object_Declaration): Handle
diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index 53f71af..89ff658 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -6052,7 +6052,10 @@ package body Exp_Ch3 is
and then not Has_Init_Expression (N)
then
Set_No_Initialization (N, False);
- Set_Expression (N, Get_Simple_Init_Val (Typ, N, Esize (Def_Id)));
+ Set_Expression
+ (N, New_Copy_Tree
+ (Get_Simple_Init_Val (Typ, N, Esize (Def_Id)),
+ New_Sloc => Sloc (Obj_Def)));
Analyze_And_Resolve (Expression (N), Typ);
end if;