Bug 9203 – Clarify that template functions with auto ref params do not share static locals

Status
NEW
Severity
normal
Priority
P3
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-12-24T17:10:49Z
Last change time
2024-12-15T15:22:00Z
Keywords
spec
Assigned to
No Owner
Creator
Peter Alexander
Moved to GitHub: dlang.org#4020 →

Comments

Comment #0 by peter.alexander.au — 2012-12-24T17:10:49Z
void foo()(auto ref int x) { import std.stdio; static int calls = 0; writeln(calls++); } void main() { int x = 0; foo(x); foo(x + x); } The output is: 0 0 I would have expected: 0 1 The spec says about auto ref parameters: "An auto ref function template parameter becomes a ref parameter if its corresponding argument is an lvalue, otherwise it becomes a value parameter" I understand that auto ref is implemented as creating two different functions for each arg l/rvalue type, but it isn't clear in the spec whether those are actually different functions (with different adresses/sets of static vars) or just conceptually different (like with inout params). If they are intended to be completely different functions then I think this needs to be made very clear in the spec.
Comment #1 by dlang-bugzilla — 2014-03-20T09:22:29Z
Yes, I'm quite sure this works as intended.
Comment #2 by robert.schadek — 2024-12-15T15:22:00Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dlang.org/issues/4020 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB