Sign in Join

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

Mailing lists / fpc-pascal / 2013-03

Weird absence of compilation error

5 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

OBones

Hello all,

I'm using FPC 2.6.0 and have the following test program :

program test;
function Element: Double;
begin
   Result := 4;
end;
function Tmp: Double;
begin
   Result := 10; + Element;
end;
begin
   WriteLn(Tmp);
end.

And quite surprisingly to me, both ppc386 and pccrossx64 compile it successfully in Delphi mode!
What's even weirder is that if I replace the Plus operator by a Minus operator, then the compilation fails.
What I was expecting is that the compilation fails in all cases. Is there some flag that I failed to specify?

Regards
OBones

Gerhard Scholz
to OBones

This must be read as follows:

function Tmp: Double; begin Result := 10; // there is a semicolon (mispelling?) [statement 1]

+ Element; [statement 2]

end;

So, Result becomes 10.
The next line is a function call without storing the result. The leading '+' (plus) is seen as sign; since '+' is neutral, it seems to be ignored by the compiler. A '-' (minus) would force some action, so it is absolutely wrong at this place.

Earlier message 39 lines
----- Original Message ----- From: "OBones" To: "FPC-Pascal users discussions" Sent: Thursday, March 21, 2013 10:53 AM Subject: [fpc-pascal] Weird absence of compilation error > Hello all, > > I'm using FPC 2.6.0 and have the following test program : > > program test; > > function Element: Double; > begin > Result := 4; > end; > > function Tmp: Double; > begin > Result := 10; + Element; > end; > > begin > WriteLn(Tmp); > end. > > And quite surprisingly to me, both ppc386 and pccrossx64 compile it > successfully in Delphi mode! > What's even weirder is that if I replace the Plus operator by a Minus > operator, then the compilation fails. > What I was expecting is that the compilation fails in all cases. > Is there some flag that I failed to specify? > > Regards > OBones > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Tomas Hajny
to OBones: I'm using FPC 2.6.0 and have the following test program : program test; function Element:…

On Thu, March 21, 2013 10:53, OBones wrote:

Hello,

Show quoted text 20 lines
I'm using FPC 2.6.0 and have the following test program : program test; function Element: Double; begin Result := 4; end; function Tmp: Double; begin Result := 10; + Element; end; begin WriteLn(Tmp); end. And quite surprisingly to me, both ppc386 and pccrossx64 compile it successfully in Delphi mode!

I don't have Delphi but TP/BP fails on this indeed (even when replacing the Result references with the names of the respective functions as required with TP/BP).

What's even weirder is that if I replace the Plus operator by a Minus operator, then the compilation fails.

No idea why '+' should be different to '-' here, but I may have missed something.

What I was expecting is that the compilation fails in all cases. Is there some flag that I failed to specify?

You can add {$X-} to the top (i.e. disable the so-called extended syntax allowing to treat functions like procedures) and then it fails. However, I think that it should fail on the plus sign in any case and I would suggest filing a bug report.

Tomas

OBones
to Gerhard Scholz: This must be read as follows: + Element; …
Gerhard Scholz wrote 9 lines
This must be read as follows: > function Tmp: Double; > begin > Result := 10; // there is a semicolon (mispelling?) [statement 1] + Element; [statement 2] > end; So, Result becomes 10.

Yes, that's what happens and, yes it's a misspelling by one of our end users. Basically we use FPC as one of the engines for the scripting part of one of our applications.

The next line is a function call without storing the result. The leading '+' (plus) is seen as sign; since '+' is neutral, it seems to be ignored by the compiler. A '-' (minus) would force some action, so it is absolutely wrong at this place.

Thanks for the explanation on the behavior.

Show quoted text 43 lines
----- Original Message ----- From: "OBones" To: "FPC-Pascal users discussions" Sent: Thursday, March 21, 2013 10:53 AM Subject: [fpc-pascal] Weird absence of compilation error > Hello all, > > I'm using FPC 2.6.0 and have the following test program : > > program test; > > function Element: Double; > begin > Result := 4; > end; > > function Tmp: Double; > begin > Result := 10; + Element; > end; > > begin > WriteLn(Tmp); > end. > > And quite surprisingly to me, both ppc386 and pccrossx64 compile it > successfully in Delphi mode! > What's even weirder is that if I replace the Plus operator by a Minus > operator, then the compilation fails. > What I was expecting is that the compilation fails in all cases. > Is there some flag that I failed to specify? > > Regards > OBones > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
OBones
to Tomas Hajny: I don't have Delphi but TP/BP fails on this indeed (even when replacing the Result…
Tomas Hajny wrote 6 lines
> What I was expecting is that the compilation fails in all cases. > Is there some flag that I failed to specify? You can add {$X-} to the top (i.e. disable the so-called extended syntax allowing to treat functions like procedures) and then it fails. However, I think that it should fail on the plus sign in any case and I would suggest filing a bug report.

Ah, I see what $X- does, and yes indeed I get the compiler error. But alas, I can't use it directly because dropping the function result is something that is done in a lot of other places. Ah well, I'll have to warn my users to be more careful. Anyway, I have created a ticket for this, thanks for the response: http://bugs.freepascal.org/view.php?id=24104

Regards
OBones