Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2020-11

Fpc does not allow Chr() in type definition. Bug?

8 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bart

Hi,

Type
  SubRange = Chr(1)..Chr(2);
begin
end.

This compiles in TP 6.0 and Delphi 7.0, but fpc doesn't.

Free Pascal Compiler version 3.3.1 [2020/09/26] for i386 Copyright (c) 1993-2020 by Florian Klaempfl and others Target OS: Win32 for i386
Compiling test.pas
test.pas(2,14) Error: Identifier not found "Chr"
test.pas(2,28) Error: Error in type definition
test.pas(5) Fatal: There were 2 errors compiling module, stopping Fatal: Compilation aborted

Is this a bug?

(Of course SubRange = #1..#2; compiles just fine)

Bart

Reply by email

Anton Shepelev
to Bart

Bart:

Show quoted text 6 lines
Type SubRange = Chr(1)..Chr(2); begin end. This compiles in TP 6.0 and Delphi 7.0, but fpc doesn't.

It also compiles in BP 7.0, but why? I think it can work only if the compiler treats Chr(1) as a macro, not as a function. Does any dialect Pascal allow function invocations in type definitions?

Reply by email

Anton Shepelev
to Anton Shepelev

I wrote to Bart:

Show quoted text 11 lines
> Type > SubRange = Chr(1)..Chr(2); > begin > end. > > This compiles in TP 6.0 and Delphi 7.0, but fpc doesn't. It also compiles in BP 7.0, but why? I think it can work only if the compilers treats Chr(1) as a macro, not as a function. Does any dialect Pascal allow function invocations in type definitions?

The Borland Pascal manual explains it:

   A constant expression is an expression that can be
   evaluated by the compiler without actually executing a
   program.
   [...]
   these constructs are not allowed in constant expres-
   sions:
   [...]
   function calls (except the following)
   Abs     Chr
   Hi      Length
   Lo      Odd
   Ord     Pred
   Ptr     Round
   SizeOf  Succ
   Swap    Trunc

Did you try compiling it with FreePascal in Borland mode?

Reply by email

Florian Klämpfl
to Bart: Type SubRange = Chr(1)..Chr(2); begin end. This compiles in TP 6.0 and Delphi 7.0, but…
Bart wrote 19 lines
Hi, Type SubRange = Chr(1)..Chr(2); begin end. This compiles in TP 6.0 and Delphi 7.0, but fpc doesn't. Free Pascal Compiler version 3.3.1 [2020/09/26] for i386 Copyright (c) 1993-2020 by Florian Klaempfl and others Target OS: Win32 for i386 Compiling test.pas test.pas(2,14) Error: Identifier not found "Chr" test.pas(2,28) Error: Error in type definition test.pas(5) Fatal: There were 2 errors compiling module, stopping Fatal: Compilation aborted Is this a bug?

Yes, it should work. It got broken somewhere during some generic work (at least I think so). Sven, can you please have a look?

Reply by email

Sven Barth
to Florian Klämpfl

Florian Klämpfl via fpc-devel schrieb am
So., 8. Nov. 2020, 22:18:

Show quoted text 25 lines
Am 07.11.2020 um 23:00 schrieb Bart via fpc-devel: > Hi, > > Type > SubRange = Chr(1)..Chr(2); > begin > end. > > This compiles in TP 6.0 and Delphi 7.0, but fpc doesn't. > > Free Pascal Compiler version 3.3.1 [2020/09/26] for i386 > Copyright (c) 1993-2020 by Florian Klaempfl and others > Target OS: Win32 for i386 > Compiling test.pas > test.pas(2,14) Error: Identifier not found "Chr" > test.pas(2,28) Error: Error in type definition > test.pas(5) Fatal: There were 2 errors compiling module, stopping > Fatal: Compilation aborted > > Is this a bug? Yes, it should work. It got broken somewhere during some generic work (at least I think so). Sven, can you please have a look?

I don't know if it's related to generics that this does not work, but at least with my changes in r47353 it now behaves consistent with e.g. Ord().

Regards,
Sven

Reply by email

Benjamin Rosseaux
to Bart

With the latest systemh.inc regarding this, the building of FPC SVN Trunk for the x86_64-win64 target with FPC 3.2.x as bootstrap compiler is failing:

E:/FPC/bootstrap/ppcx64.exe -XX -Cr- -CR- -Ct- -Co- -CO- -C3- -g -Ur -Xs
-O2 -n -Fi../inc -Fi../x86_64 -FE. -FUE:/FPC/svn/rtl/units/x86_64-win64
-dtls_threadvars -O2 -dSPILLING_NEW -g -dx86_64 -dRELEASE  -Us -Sg
system.pp -Fi../win
generic.inc(902,11) Error: Identifier not found "chr"
generic.inc(914,19) Error: Identifier not found "chr"
generic.inc(950,13) Error: Identifier not found "chr"
generic.inc(1010,14) Error: Identifier not found "Chr"
generic.inc(1029,10) Error: Identifier not found "chr"
generic.inc(1090,9) Error: Identifier not found "chr"
generic.inc(1272,11) Error: Identifier not found "chr"
sstrings.inc(24,9) Error: Identifier not found "chr"
sstrings.inc(44,25) Error: Identifier not found "chr"
sstrings.inc(60,12) Error: Identifier not found "Chr"
sstrings.inc(97,9) Error: Identifier not found "chr"
sstrings.inc(121,9) Error: Identifier not found "chr"
sstrings.inc(397,14) Error: Identifier not found "chr"
sstrings.inc(411,15) Error: Identifier not found "chr"
sstrings.inc(714,16) Error: Identifier not found "Chr"
sstrings.inc(773,26) Error: Identifier not found "chr"
sstrings.inc(790,13) Error: Identifier not found "chr"
sstrings.inc(827,13) Error: Identifier not found "Chr"
sstrings.inc(829,13) Error: Identifier not found "Chr"
text.inc(1747,9) Error: Identifier not found "chr"
system.pp(651) Fatal: There were 20 errors compiling module, stopping
Fatal: Compilation aborted

So I did undo the change locally for to be able building it again.

On Mon, Nov 9, 2020 at 8:26 PM Bart via fpc-devel <

Show quoted text 15 lines
wrote: On Mon, Nov 9, 2020 at 3:56 PM Anton Shepelev via fpc-devel wrote: > Did you try compiling it with FreePascal in Borland mode? Yes, I did, as the related (and now closed) bugreport shows. Anyhow, it should be fixed now. -- Bart _______________________________________________ fpc-devel maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Sven Barth
to Benjamin Rosseaux

Benjamin Rosseaux via fpc-devel schrieb am
Fr., 20. Nov. 2020, 12:40:

Show quoted text 33 lines
With the latest systemh.inc regarding this, the building of FPC SVN Trunk for the x86_64-win64 target with FPC 3.2.x as bootstrap compiler is failing: E:/FPC/bootstrap/ppcx64.exe -XX -Cr- -CR- -Ct- -Co- -CO- -C3- -g -Ur -Xs -O2 -n -Fi../inc -Fi../x86_64 -FE. -FUE:/FPC/svn/rtl/units/x86_64-win64 -dtls_threadvars -O2 -dSPILLING_NEW -g -dx86_64 -dRELEASE -Us -Sg system.pp -Fi../win generic.inc(902,11) Error: Identifier not found "chr" generic.inc(914,19) Error: Identifier not found "chr" generic.inc(950,13) Error: Identifier not found "chr" generic.inc(1010,14) Error: Identifier not found "Chr" generic.inc(1029,10) Error: Identifier not found "chr" generic.inc(1090,9) Error: Identifier not found "chr" generic.inc(1272,11) Error: Identifier not found "chr" sstrings.inc(24,9) Error: Identifier not found "chr" sstrings.inc(44,25) Error: Identifier not found "chr" sstrings.inc(60,12) Error: Identifier not found "Chr" sstrings.inc(97,9) Error: Identifier not found "chr" sstrings.inc(121,9) Error: Identifier not found "chr" sstrings.inc(397,14) Error: Identifier not found "chr" sstrings.inc(411,15) Error: Identifier not found "chr" sstrings.inc(714,16) Error: Identifier not found "Chr" sstrings.inc(773,26) Error: Identifier not found "chr" sstrings.inc(790,13) Error: Identifier not found "chr" sstrings.inc(827,13) Error: Identifier not found "Chr" sstrings.inc(829,13) Error: Identifier not found "Chr" text.inc(1747,9) Error: Identifier not found "chr" system.pp(651) Fatal: There were 20 errors compiling module, stopping Fatal: Compilation aborted So I did undo the change locally for to be able building it again.

Did you really use the latest? Cause yes, there was a problem directly after changing this, but nowadays it works with both 3.0.4 and 3.2.0.

Regards,
Sven

Reply by email