View Issue Details

IDProjectCategoryView StatusLast Update
0037098FPCCompilerpublic2020-05-17 21:18
ReporterKirinn Assigned ToJonas Maebe  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionno change required 
Platformx86OSWindows 
Product Version3.3.1 
Summary0037098: Address @ of a function result string element causes Variable identifier expected error
DescriptionThe 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 Reproduceprogram 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.
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget-
Attached Files

Activities

Jonas Maebe

2020-05-17 21:12

manager   ~0122887

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.

Kirinn

2020-05-17 21:18

reporter   ~0122888

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.

Issue History

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