View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0037098 | FPC | Compiler | public | 2020-05-17 20:43 | 2020-05-17 21:18 |
Reporter | Kirinn | Assigned To | Jonas Maebe | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | closed | Resolution | no change required | ||
Platform | x86 | OS | Windows | ||
Product Version | 3.3.1 | ||||
Summary | 0037098: Address @ of a function result string element causes Variable identifier expected error | ||||
Description | The below code compiles and runs on FPC 3.0.4, but produces a compilation error on 3.2.0 RC1: "Error: Variable identifier expected". It seems like we can get the address of a function's result value directly, but we can't get the address of an index of the same without first saving it into a variable. If this change is intentional, a note should be added for User Changes on 3.2.0. | ||||
Steps To Reproduce | program test3; function GetString : string; // <-- or UTF8string begin GetString := 'hello'; end; var p : pointer; s : string; begin s := GetString(); p := @s[1]; // <-- compiles ok p := @GetString[1]; // <-- fails to compile in 3.2.0 end. | ||||
Tags | No tags attached. | ||||
Fixed in Revision | |||||
FPCOldBugId | |||||
FPCTarget | - | ||||
Attached Files |
|
|
It's not mentioned on the user changes page because that code was invalid. It did not work in 3.0.4 either (or at least not reliably in most cases), because you are getting the address of a temporary memory location. As soon as the statement in which you take the address has finished executing, that address is no longer (guaranteed to be) valid. The user changes page only mentioned code that used to work correctly, but is no longer supported or needs changes to keep working correctly. |
|
I'm mildly surprised then that it has been working fine for me so far, but I can see why it shouldn't. Thanks for checking. |
Date Modified | Username | Field | Change |
---|---|---|---|
2020-05-17 20:43 | Kirinn | New Issue | |
2020-05-17 21:12 | Jonas Maebe | Assigned To | => Jonas Maebe |
2020-05-17 21:12 | Jonas Maebe | Status | new => resolved |
2020-05-17 21:12 | Jonas Maebe | Resolution | open => no change required |
2020-05-17 21:12 | Jonas Maebe | FPCTarget | => - |
2020-05-17 21:12 | Jonas Maebe | Note Added: 0122887 | |
2020-05-17 21:18 | Kirinn | Note Added: 0122888 | |
2020-05-17 21:18 | Kirinn | Status | resolved => closed |