Weird Numbers (Rosetta Code task) weird error

Hi;

I must be doing something very stupid.

Rosetta Code task “Weird Numbers”.

I’m on a Mac (M1 chip) using the GNAT compiler provded by Simon.

which gnatmake
/opt/gcc-14.2.0-3-aarch64/bin/gnatmake

the following is fom version #1 of the RC example:

gnatmake ./weird_numbers.adb
gcc -c -I./ -I- ./weird_numbers.adb
weird_numbers.adb:47:47: warning: value not in range of type "Ada.Containers.Vectors.Element_Type" from instance at line 11 [enabled by default]
weird_numbers.adb:47:47: warning: Constraint_Error will be raised at run time [enabled by default]
weird_numbers.adb:84:37: warning: value not in range of type "Ada.Containers.Vectors.Element_Type" from instance at line 11 [enabled by default]
weird_numbers.adb:84:37: warning: Constraint_Error will be raised at run time [enabled by default]
gnatbind -x weird_numbers.ali
gnatlink weird_numbers.ali

The following is from version #2:

gnatmake ./weird_numbers.adb
gcc -c -I./ -I- ./weird_numbers.adb
weird_numbers.adb:56:47: warning: value not in range of type "Ada.Containers.Vectors.Element_Type" from instance at line 10 [enabled by default]
weird_numbers.adb:56:47: warning: Constraint_Error will be raised at run time [enabled by default]
gnatbind -x weird_numbers.ali
gnatlink weird_numbers.ali

Since “pragma Ada_2022;” is at the top of both versions, I didn’t think I needed to provide and additional flags to the compile command; am I incorrect here?

RBE

The second version trips over a problem we’ve come across before: Proper_Divisors returns an IntVec (ugh, ugh, ugh) which is a vector of Positive, but we’re trying ’Reduce ("+", 0) and 0 isn’t in Positive.

In the first version (as published, which works for me) IntVec is a vector of Natural. Did you change it?

You’ll be pleased (?) to hear that GCC 15.0.0 (20241201) doesn’t have this problem.

See GCC PR 115349.

I wrote that example. Can I ask what you don’t like about IntVec? Is it that the code returns a vector, or the CamelCasing?

…Sorry, I think gnat went through some iterations where that worked on version 12 (? maybe 13?) then broke on version 14.

Hi Simon;

Indeed, the first version is not the same as the one on the web site currently. Therefore I must have made a change. I replaced my current code of the first version with what is currently on the web site and it now works fine.

Thanks,
RBE

It’s the CamelCasing. Just ignore me

2 Likes