View Issue Details

IDProjectCategoryView StatusLast Update
0038073FPCDocumentationpublic2020-11-14 18:21
ReporterKai Burghardt Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Platformx86_64OSGNU/Linux 
Product Version3.2.0 
Fixed in Version3.3.1 
Summary0038073: Reference Guide: Operator overloading Delphi Compatibility names table
DescriptionExamining compiler/tokens.pas I notice

- the table suggests using `assign` for `:=`, but in fact `implicit` is correct
- `positive` and `negative` are not mentioned
- `bitwisenot`, `power` and `symmetricaldifference` are documented, but do not appear in tokens.pas.
TagsNo tags attached.
Fixed in Revision1779
FPCOldBugId
FPCTarget3.2.2
Attached Files

Activities

Kai Burghardt

2020-11-13 03:02

reporter  

ref.tex.patch (599 bytes)   
--- ref.tex~	2020-11-13 02:02:10.303469497 +0000
+++ ref.tex	2020-11-13 02:02:10.303469497 +0000
@@ -11816,8 +11816,8 @@
 name:
 \begin{FPCltable}{cl}{Operator names}{operatornames}
 Symbol & Name \\ \hline
-\var{+} & add \\
-\var{-} & subtract \\
+\var{+} & positive, add \\
+\var{-} & negative, subtract \\
 \var{*} & multiply \\
 \var{/} & divide \\
 \var{**} & power \\
@@ -11828,7 +11828,7 @@
 \var{>} & greaterthan \\
 \var{>=} & greaterthanorequal \\
 \var{<>} & notequal \\
-\var{:=} & assign \\
+\var{:=} & implicit \\
 \var{in} & in \\
 \var{shr} & rightshift \\
 \var{shl} & leftshift \\
ref.tex.patch (599 bytes)   

Michael Van Canneyt

2020-11-13 16:51

administrator   ~0126883

Fixed, thanks for pointing it out.
Note that the table moved to the section on extended records, record operator overloads.

Kai Burghardt

2020-11-13 18:25

reporter   ~0126886

Uhm, I think the table on typed out operator names should stay in the chapter on operator overloading, since it is perfectly legal to use them in non-Delphi modes. Why would you intentionally scatter documentation on _one_ topic? I do understand the Delphi mode restrictions, yet we are not documenting Delphi, but FPC, right?

Kai Burghardt

2020-11-13 18:25

reporter   ~0126887

ref.tex-2.patch (483 bytes)   
--- ref.tex~	2020-11-13 17:24:00.213932207 +0000
+++ ref.tex	2020-11-13 17:24:00.213932207 +0000
@@ -7399,7 +7399,7 @@
 This is of course because the syntax must be compatible with Delphi.
 
 Below is a table that links the symbolic operator names to the plain-text
-name. Note that some FPC operators do not have an equivalent usin a Delphi
+name. Note that some FPC operators do not have an equivalent use in a Delphi
 name.
 
 \begin{FPCltable}{cl}{Operator names}{operatornames}
ref.tex-2.patch (483 bytes)   

Kai Burghardt

2020-11-13 18:28

reporter   ~0126888

And `bitwisenot` is still documented. I guess, that’s also an operator that has “(no equivalent)”? Or, maybe, tokens.pas is incomplete, I don’t know.

Michael Van Canneyt

2020-11-13 21:35

administrator   ~0126892

The table is moved because the named operators can only be used within the context of record class operators.

Sven confirmed this, and the compiler refuses to compile textual names:
home:~> cat top.pp
type
  complex = record
    re: double;
    im: double;
  end;
 
  operator implicit (r: double) : complex;
  begin
    Result.re := r;
    Result.im := 0.0;
  end;
 
var
  R: double;
  C: complex;
 
begin
  C := R;
end.
home:~> fpc -S2 cat top.pp
top.pp(7,21) Error: It is not possible to overload this operator. Related overloadable operators (if any) are:
top.pp(7,42) Error: Impossible operator overload
top.pp(18,8) Error: Incompatible types: got "Double" expected "complex"
top.pp(19,5) Fatal: There were 3 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/local/bin/ppcx64 returned an error exitcode
home:~> fpc -Sd top.pp
top.pp(7,12) Fatal: Syntax error, "=" expected but "identifier IMPLICIT" found
Fatal: Compilation aborted
Error: /usr/local/bin/ppcx64 returned an error exitcode

Same with array type:

type
  TA = Array[1..12] of string;
  
operator add (A,B : TA) : Ta;

begin
end;

var
  a,b,c : TA;
  

begin
  a:=b+c;
end.

home:~> fpc -S2 toa.pp
toa.pp(4,14) Error: It is not possible to overload this operator. Related overloadable operators (if any) are:
toa.pp(4,29) Error: Impossible operator overload
toa.pp(14,7) Error: Operator is not overloaded: "TA" + "TA"
toa.pp(16) Fatal: There were 3 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/local/bin/ppcx64 returned an error exitcode

Or even an enumerated type:
type
  TA = (t1,t2,t3);
  
operator add (A,B : TA) : Ta;

begin
end;

var
  a,b,c : TA;
  

begin
  a:=b+c;
end.

home:~> fpc -S2 toa.pp
toa.pp(4,14) Error: It is not possible to overload this operator. Related overloadable operators (if any) are:
toa.pp(4,29) Error: Impossible operator overload
toa.pp(14,7) Error: Operation "+" not supported for types "TA" and "TA"
toa.pp(16) Fatal: There were 3 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/local/bin/ppcx64 returned an error exitcode

Kai Burghardt

2020-11-13 22:32

reporter   ~0126898

I stand corrected. I believed, the typed out names were always legal, even in global operator overloads. But you gotta admit, it’s quite a mess, huh? I still prefer to have everything in _one_ chapter.

NB: + and - can never be overloaded in conjunction with enumeration data types. I’ve learned it the hard way in https://forum.lazarus.freepascal.org/index.php/topic,41144.msg285289.html

Michael Van Canneyt

2020-11-13 22:40

administrator   ~0126899

Indeed. I added a note about this in rev. 1776.
Also noted that for dynamic arrays, + cannot be overloaded, as it is handled internally by the compiler for Delphi compatibility.

Kai Burghardt

2020-11-14 03:44

reporter   ~0126906

Now, `logicalnot` does appear in `tokens.pas`. It’s just `bitwisenot` that isn’t recognized.

Also, it’s since the advent of {$modeSwitch arrayOperators+} + can’t be overloaded on arrays, cf. https://wiki.freepascal.org/User_Changes_3.2.0#Operator_overload_.2B_no_longer_allowed_for_dynamic_arrays

Kai Burghardt

2020-11-14 03:45

reporter   ~0126907

ref.tex-3.patch (911 bytes)   
--- ref.tex~	2020-11-14 02:30:00.386670997 +0000
+++ ref.tex	2020-11-14 02:30:00.386670997 +0000
@@ -7425,7 +7425,7 @@
 \var{and} & bitwiseand or logicaland \\
 \var{or} & bitwiseor or logicalor \\
 \var{xor} & bitwisexor \\
-%\var{not} & bitwisenot or logicalnot \\
+\var{not} & logicalnot \\
 \end{FPCltable}
 
 For example, the power operator (**) can be used in \var{Delphi} mode using its
@@ -11893,8 +11893,10 @@
 
 User-defined simple types can be used for operators, as well as records and arrays.
 It is not possible to define operators on classes. The + and - operators
-cannot be defined on enumerated types, and the + operator cannot be
-overloaded on dynamic arrays, because it is handled internally.
+cannot be defined on enumerated types.
+The + operator cannot be overloaded on dynamic arrays
+whose type has been defined while the ArrayOperators
+modewitch has been active.
 
 
 \begin{remark}
ref.tex-3.patch (911 bytes)   

Michael Van Canneyt

2020-11-14 11:45

administrator   ~0126914

Expanded the explanations in rev. 1779

Sven Barth

2020-11-14 15:53

manager   ~0126924

Note: the + operator for dynamic arrays is special. It is only defined internally by the compiler if the modeswitch ArrayOperators is enabled (default in mode Delphi, but can be disabled there with {$modeswitch ArrayOperators-} after {$mode Delphi}). In this case FPC does not allow the declaration nor the use of + operator overloads for dynamic arrays. If the modeswitch is not enabled however they can both be declared as well as used.
It was done this way, cause the addition of the internal operator resulted in quite some backlash regarding backwards compatibilty.

Michael Van Canneyt

2020-11-14 17:34

administrator   ~0126936

Sven, I explained it like that.

Sven Barth

2020-11-14 18:21

manager   ~0126940

Ah, sorry, I had only looked at 1776 instead of 1779 as well.

Issue History

Date Modified Username Field Change
2020-11-13 03:02 Kai Burghardt New Issue
2020-11-13 03:02 Kai Burghardt Status new => assigned
2020-11-13 03:02 Kai Burghardt Assigned To => Michael Van Canneyt
2020-11-13 03:02 Kai Burghardt File Added: ref.tex.patch
2020-11-13 16:51 Michael Van Canneyt Status assigned => resolved
2020-11-13 16:51 Michael Van Canneyt Resolution open => fixed
2020-11-13 16:51 Michael Van Canneyt Fixed in Version => 3.3.1
2020-11-13 16:51 Michael Van Canneyt Fixed in Revision => 1774
2020-11-13 16:51 Michael Van Canneyt FPCTarget => 3.2.2
2020-11-13 16:51 Michael Van Canneyt Note Added: 0126883
2020-11-13 18:25 Kai Burghardt Status resolved => feedback
2020-11-13 18:25 Kai Burghardt Resolution fixed => open
2020-11-13 18:25 Kai Burghardt Note Added: 0126886
2020-11-13 18:25 Kai Burghardt Note Added: 0126887
2020-11-13 18:25 Kai Burghardt File Added: ref.tex-2.patch
2020-11-13 18:25 Kai Burghardt Status feedback => assigned
2020-11-13 18:28 Kai Burghardt Note Added: 0126888
2020-11-13 21:35 Michael Van Canneyt Status assigned => resolved
2020-11-13 21:35 Michael Van Canneyt Resolution open => fixed
2020-11-13 21:35 Michael Van Canneyt Fixed in Revision 1774 => 1775
2020-11-13 21:35 Michael Van Canneyt Note Added: 0126892
2020-11-13 22:32 Kai Burghardt Note Added: 0126898
2020-11-13 22:40 Michael Van Canneyt Note Added: 0126899
2020-11-14 03:44 Kai Burghardt Status resolved => feedback
2020-11-14 03:44 Kai Burghardt Resolution fixed => open
2020-11-14 03:44 Kai Burghardt Note Added: 0126906
2020-11-14 03:45 Kai Burghardt Note Added: 0126907
2020-11-14 03:45 Kai Burghardt File Added: ref.tex-3.patch
2020-11-14 03:45 Kai Burghardt Status feedback => assigned
2020-11-14 11:45 Michael Van Canneyt Status assigned => resolved
2020-11-14 11:45 Michael Van Canneyt Resolution open => fixed
2020-11-14 11:45 Michael Van Canneyt Fixed in Revision 1775 => 1779
2020-11-14 11:45 Michael Van Canneyt Note Added: 0126914
2020-11-14 15:53 Sven Barth Note Added: 0126924
2020-11-14 17:34 Michael Van Canneyt Note Added: 0126936
2020-11-14 18:21 Sven Barth Note Added: 0126940