Skip to content
Browse files

fix Issue 8105 - in ref

  • Loading branch information...
1 parent 1c618b0 commit 687044996a06535210801577e5d68b72edfa3985 @WalterBright WalterBright committed
Showing with 11 additions and 1 deletion.
  1. +2 −1 src/parse.c
  2. +9 −0 test/runnable/xtest46.d
View
3 src/parse.c
@@ -1371,7 +1371,8 @@ Parameters *Parser::parseParameters(int *pvarargs, TemplateParameters **tpl)
default:
Ldefault:
{ stc = storageClass & (STCin | STCout | STCref | STClazy);
- if (stc & (stc - 1)) // if stc is not a power of 2
+ if (stc & (stc - 1) && // if stc is not a power of 2
+ !(stc == (STCin | STCref)))
error("incompatible parameter storage classes");
if ((storageClass & (STCconst | STCout)) == (STCconst | STCout))
error("out cannot be const");
View
9 test/runnable/xtest46.d
@@ -5094,6 +5094,14 @@ void test8064()
/***************************************************/
+void func8105(in ref int x) { }
+
+void test8105()
+{
+}
+
+/***************************************************/
+
int main()
{
test1();
@@ -5326,6 +5334,7 @@ int main()
test7907();
test8004();
test8064();
+ test8105();
printf("Success\n");
return 0;

4 comments on commit 6870449

@alexrp
D Programming Language member

Since in implies scope wouldn't it also make sense to support scope ref?

@WalterBright
D Programming Language member
@TurkeyMan

That was easy.. Cheers! :)

How often does scope come up without const? I suspect that is why the shorthand 'in' was invented?

@ntrel

How often does scope come up without const?

When you want to modify a parameter and also guarantee that no escaping references are made to it. It would be useful when passing stack allocated structs, slices or associative arrays.

Please sign in to comment.
Something went wrong with that request. Please try again.