[Ada] Static predicate check on characters of a string literal
Pierre-Marie de Rodat
derodat@adacore.com
Thu May 31 10:49:00 GMT 2018
This patch implements the rule given in RM 4.2 (11): if the component type of
a string literal is a character type with a static predicate, that predicate
must be applied to each character in the string.
Compiling the example below must yield:
gcc -c -gnata main.adb
main.adb:4:23: warning: static expression fails static predicate check on "C"
main.adb:4:23: warning: expression is no longer considered static
main.adb:4:24: warning: static expression fails static predicate check on "C"
main.adb:4:24: warning: expression is no longer considered static
main.adb:4:25: warning: static expression fails static predicate check on "C"
main.adb:4:25: warning: expression is no longer considered static
Execution must yield:
raised SYSTEM.ASSERTIONS.ASSERT_FAILURE :
Static_Predicate failed at main.adb:4
----
procedure Main is
subtype C is Character with Static_Predicate => C in 'A' | 'B' | 'C';
type S is array (Positive range <>) of C;
X : constant S := "abc";
begin
null;
end;
Tested on x86_64-pc-linux-gnu, committed on trunk
2018-05-31 Ed Schonberg <schonberg@adacore.com>
gcc/ada/
* sem_res.adb (Resolve_String_Literal): If the type is a string type
whose component subtype has a static predicate, ensure that the
predicate is applied to each character by expanding the string into the
equivalent aggregate. This is also done if the component subtype is
constrained.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.diff
Type: text/x-diff
Size: 931 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20180531/d2b74ab1/attachment.bin>
More information about the Gcc-patches
mailing list