That is indeed the case for both Delphi and Freepascal.
I once suggested a patch for the case where enum members have a value assignment but it was refused as won't fix some (~8-10?) years ago. You can do it manually, though: if there are "gaps" in the enum, they have no name filled in. I will look up what I did to fix that, but I need to connect an old drive first.
EDIT
Seems there is no typeinfo for enums with assigned values at all. Same as in Delphi
Investigating....
EDIT2 helped by claude for exact formulation (AFTER I wrote the code!!)
EnumCount<T> — counts declared literals of a (possibly non-sequential)
enumerated type T.
Requires FPC >= trunk r49064 / 3.3.1 (fix for Mantis #38642: generics +
non-sequential enums). Fails to compile on stable 3.2.2 with
"No type info available for this type".
T is not restricted to ordinal types at compile time, since FPC has no
"T: Ordinal" generic constraint yet.
Non-ordinal T is instead rejected at run time via GetTypeKind(T), which
returns 0.
For sparse enums, Write()/IOResult (RTL error 107, documented in the
User's Guide, Appendix D) distinguishes declared literals from gaps in
the ordinal range; this does not depend on published RTTI, which sparse
enums lack.
VERY dirty solution:
{$if fpc_fullversion < 30301}{$error 'needs a trunk after #38642 (fixed, revision 49064)'}{$endif}
{$mode delphi}
type
TWeekdays = (monday = 4,tuesday=100, wednesday,thursday,friday);
function EnumCount<T>:integer;
var
test:T;
s:string;// dummy
begin
{$push}{$I-}
result := 0; // if T is not an enum, simply return 0.
if GetTypeKind(T) = tkEnumeration then
for test :=Low(T) to High(T) do
begin
writestr(s,test);// misuse error recovery....This IS needed.
if IOResult = 0 then inc(result); // count only valid values, not the gaps.
end;
{$pop}
end;
begin
writeln(EnumCount<TWeekdays>);
end.
I still have to find my MR/FR.
The above code
works for any enum.
My original proposal was probably a feature request.