-
Notifications
You must be signed in to change notification settings - Fork 93
Closed
Milestone
Description
Describe the bug
In the C# 7.x draft, 12.6.6.1 (Function member invocation / General) describes how a copy of a value-type instance "not classified as a variable" is made and used instead of the original. This defensive copying should also apply to an input parameter unless its type is a readonly struct.
Example
using System;
struct S {
public int I;
public void M() { I++; }
}
readonly struct R {
public void M() {}
}
class C {
static void Main() {
N(new S(), new S(), new R());
}
static void N(S s1, in S s2, in R r) {
s1.M(); // no copying
Console.WriteLine(s1.I); // 1
s2.M(); // copy required
Console.WriteLine(s2.I); // 0
r.M(); // no copying
}
}Expected behavior
In 12.6.6.1, declare:
If
Eis not classified as a variable, or ifEis an input parameter (15.6.2.3) andVis not a readonly struct type (16.2.2), then a temporary local variable of E’s type is created and the value of E is assigned to that variable.
Additional context
None.
BillWagner
Metadata
Metadata
Assignees
Labels
No labels