This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] ada: Check that the type of Integer_Value attribute argument is known


Compiled and regtested on i686-pc-linux-gnu.


    gcc/ada/
	PR ada/32792
	* sem_attr.adb (Analyze_Attribute, Attribute_Integer_Value clause):
	Signal an error when attribute argument is a fixed-point value of
	an unknown type.

    gcc/testsuite/
	PR ada/32792
	* gnat.dg/specs/integer_value.ads: New test.
---
 gcc/ada/sem_attr.adb                          |    9 +++++++++
 gcc/testsuite/gnat.dg/specs/integer_value.ads |    5 +++++
 2 files changed, 14 insertions(+), 0 deletions(-)
 create mode 100644 gcc/testsuite/gnat.dg/specs/integer_value.ads

diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
index 0056024..6f1541f 100644
--- a/gcc/ada/sem_attr.adb
+++ b/gcc/ada/sem_attr.adb
@@ -3047,6 +3047,15 @@ package body Sem_Attr is
          Check_E1;
          Check_Integer_Type;
          Resolve (E1, Any_Fixed);
+
+         --  Signal an error if argument type is not a specific fixed-point
+         --  subtype. An error has been signalled already if the argument
+         --  was not of a fixed-point type.
+
+         if Etype (E1) = Any_Fixed and then not Error_Posted (E1) then
+            Error_Attr ("argument of % must be of a fixed-point type", E1);
+         end if;
+
          Set_Etype (N, P_Base_Type);
 
       -----------
diff --git a/gcc/testsuite/gnat.dg/specs/integer_value.ads b/gcc/testsuite/gnat.dg/specs/integer_value.ads
new file mode 100644
index 0000000..6e9c1b5
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/specs/integer_value.ads
@@ -0,0 +1,5 @@
+-- { dg-do compile }
+package Integer_Value is
+   X : constant Integer :=
+     Integer'Integer_Value (12.8); -- { dg-error "fixed-point type" "" }
+end Integer_Value;
-- 
1.5.3.5


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]