View Issue Details

IDProjectCategoryView StatusLast Update
0033050pas2jstranspilerpublic2020-09-28 11:58
ReporterMichal Gawrycki Assigned ToMattias Gaertner  
PrioritynormalSeverityminorReproducibilityN/A
Status resolvedResolutionfixed 
Summary0033050: [feature request] 'Strict' ordinal types (overflow check)
DescriptionCould ordinal types be more strict? For example adding var i: byte = 200; ... i:=i+100; will result in i=44 instead of i=300.
I know it will affect performance, but it could be controlled by compiler directive.
In addition, this feature could include range checking {$R+}
TagsNo tags attached.
Fixed in Revision
Attached Files

Activities

Mattias Gaertner

2018-01-18 17:47

manager   ~0105905

Range checking raises an ERangeCheck. How should this work together?

Michal Gawrycki

2018-01-18 18:14

reporter   ~0105908

I think these are related. If we adjust value to type, we can also check range. Of course when range checking is enabled.

Mattias Gaertner

2018-01-18 18:20

manager   ~0105909

If I understand the proposal correctly, a directive should be added to emulate the modulo overflows of normal processors, which could help porting some code.

Martin Vahi

2018-01-18 18:26

reporter   ~0105911

I'm not a FreePascal developer, I'm just a spectator, but
from the perspective of a spectator, who has worked
years using C++, it seems to me that the overflow of
the value of the byte is

MORE PRECISE than TYPE CONVERSION.

C++ has a lot of type conversion and it really
takes skill to read C++ code, because one always
has to keep in mind the different type conversions
and if operators are overloaded, then the function
that is chosen for executing the overloaded operator,
for example, an overloaded "+" depends on the types
of the parameters, giving a situation, where

c = a + b;

can have a whole variety of types for the "c".
I actually like the operator overloading and
I haven't had much problems with the automatic
type conversion, but since You used the word
 
    PRECISE

then refraining from automatic type conversion is
more RIGID and LESS ERROR PRONE AT CORNER CASES than
what You suggested with the byte+something=300 example.

What I'm saying is that it's a matter of policy, how
You people like to develop the Free Pascal semantics, but
the automatic type conversion is certainly NOT SOMETHING
that You would like to have in safety critical code or
otherwise code that associates with formal verification
and the word "PRECISE".

Thank You for reading my comment.

Michal Gawrycki

2018-01-18 19:58

reporter   ~0105915

> If I understand the proposal correctly, a directive should be added to emulate the modulo overflows of normal processors, which could help porting some code.

Yes, but not only. I mean that ordinal types work exactly like in fpc. Including signed <> unsigned typing:

B: Byte;
S: ShortInt;

B:=$FF;
S:=B; -> S = -1

But now I wonder if it makes sense in case of pas2js.

Mattias Gaertner

2018-05-02 08:45

manager   ~0108097

Typecasting integers now works in trunk:

aByte:=$FF;
write(shortint(aByte));

now writes -1

Mattias Gaertner

2020-09-28 11:58

manager   ~0125921

There are integer overflow checks.

An emulation to mimic the add/sub modulo of integers is not planned.

Issue History

Date Modified Username Field Change
2018-01-18 17:25 Michal Gawrycki New Issue
2018-01-18 17:47 Mattias Gaertner Note Added: 0105905
2018-01-18 17:48 Mattias Gaertner Assigned To => Mattias Gaertner
2018-01-18 17:48 Mattias Gaertner Status new => assigned
2018-01-18 18:14 Michal Gawrycki Note Added: 0105908
2018-01-18 18:20 Mattias Gaertner Note Added: 0105909
2018-01-18 18:26 Martin Vahi Note Added: 0105911
2018-01-18 19:58 Michal Gawrycki Note Added: 0105915
2018-05-02 08:45 Mattias Gaertner Note Added: 0108097
2018-05-25 10:33 Mattias Gaertner Summary [feature request] 'Strict' ordinal types => [feature request] 'Strict' ordinal types (overflow check)
2020-09-28 11:58 Mattias Gaertner Status assigned => resolved
2020-09-28 11:58 Mattias Gaertner Resolution open => fixed
2020-09-28 11:58 Mattias Gaertner Note Added: 0125921