mirror of
https://github.com/github/codeql.git
synced 2025-12-17 17:23:36 +01:00
59 lines
1.2 KiB
C#
59 lines
1.2 KiB
C#
public struct S1 { }
|
|
public ref struct S2 { }
|
|
|
|
// The `scoped` modifier can be applied to parameters
|
|
// or local variables. The type of the parameter or
|
|
// local variable must be either a `ref` value or `ref struct` value.
|
|
public class ScopedModifierTest
|
|
{
|
|
public ref int M1(scoped ref int x1, ref int y1)
|
|
{
|
|
// Not allowed.
|
|
// return ref x1;
|
|
return ref y1;
|
|
}
|
|
|
|
public ref int M2(scoped out int x2, ref int y2)
|
|
{
|
|
x2 = 0;
|
|
// Not allowed.
|
|
// return ref x;
|
|
return ref y2;
|
|
}
|
|
|
|
public int M3(scoped ref int x3)
|
|
{
|
|
// Allowed is it is not returned by reference.
|
|
return x3;
|
|
}
|
|
|
|
public S1 M4(scoped ref S1 x4)
|
|
{
|
|
// Allowed as it is not returned by reference.
|
|
return x4;
|
|
}
|
|
|
|
public S2 M5(scoped S2 x5)
|
|
{
|
|
// Not allowed.
|
|
// return x5;
|
|
return new S2();
|
|
}
|
|
|
|
public S2 M6(scoped ref S2 x6)
|
|
{
|
|
// Not allowed.
|
|
// return x6;
|
|
return new S2();
|
|
}
|
|
|
|
public S2 Locals()
|
|
{
|
|
scoped S2 x7 = new S2();
|
|
// Not allowed.
|
|
// return x7;
|
|
S2 y7 = new S2();
|
|
return y7;
|
|
}
|
|
|
|
} |