diff --git a/changelog/dmd.enable-rvaluerefparam.dd b/changelog/dmd.enable-rvaluerefparam.dd new file mode 100644 index 000000000000..e1c5d13dca1e --- /dev/null +++ b/changelog/dmd.enable-rvaluerefparam.dd @@ -0,0 +1,3 @@ +Enabled -preview=rvaluerefparam after a long testing period. + +You can now supply an rvalue to a ref argument. A temporary will automatically be created for the call. diff --git a/compiler/src/dmd/cli.d b/compiler/src/dmd/cli.d index baf50d107c14..884b60c60c6c 100644 --- a/compiler/src/dmd/cli.d +++ b/compiler/src/dmd/cli.d @@ -946,6 +946,9 @@ dmd -cov -unittest myprog.d Feature("dtorfields", "dtorFields", "don't destruct fields of partially constructed objects"), Feature("fieldwise", "fieldwise", "don't use fieldwise comparisons for struct equality", "https://dlang.org/changelog/2.085.0.html#no-cmpsb"), + Feature("rvaluerefparam", "rvalueRefParam", + "revert rvalue arguments to ref parameters", + "https://gist.github.com/andralex/e5405a5d773f07f73196c05f8339435a"), ]; /// Returns all available previews @@ -976,9 +979,6 @@ dmd -cov -unittest myprog.d Feature("dtorfields", "dtorFields", "destruct fields of partially constructed objects", "https://dlang.org/changelog/2.098.0.html#dtorfileds", false, false), - Feature("rvaluerefparam", "rvalueRefParam", - "enable rvalue arguments to ref parameters", - "https://gist.github.com/andralex/e5405a5d773f07f73196c05f8339435a"), Feature("safer", "safer", "more safety checks by default", "https://github.com/WalterBright/documents/blob/38f0a846726b571f8108f6e63e5e217b91421c86/safer.md", true, false), diff --git a/compiler/src/dmd/dscope.d b/compiler/src/dmd/dscope.d index 8648231b4a83..38c48a063992 100644 --- a/compiler/src/dmd/dscope.d +++ b/compiler/src/dmd/dscope.d @@ -113,7 +113,7 @@ private struct Previews this.in_ = params.previewIn; this.inclusiveInContracts = params.inclusiveInContracts; this.noSharedAccess = params.noSharedAccess == FeatureState.enabled; - this.rvalueRefParam = params.rvalueRefParam == FeatureState.enabled; + this.rvalueRefParam = params.rvalueRefParam != FeatureState.disabled; this.safer = params.safer == FeatureState.enabled; this.systemVariables = params.systemVariables; } diff --git a/compiler/src/dmd/frontend.h b/compiler/src/dmd/frontend.h index 26f1ba5fec62..cbf1c850e22c 100644 --- a/compiler/src/dmd/frontend.h +++ b/compiler/src/dmd/frontend.h @@ -8450,6 +8450,7 @@ struct Param final ehnogc(), useDIP1021(), fixAliasThis(), + rvalueRefParam((FeatureState)2u), previewIn(), inclusiveInContracts(), shortenedMethods(true), @@ -8500,7 +8501,7 @@ struct Param final timeTraceFile() { } - Param(bool obj, bool multiobj = false, bool trace = false, bool tracegc = false, bool vcg_ast = false, DiagnosticReporting useDeprecated = (DiagnosticReporting)1u, bool useUnitTests = false, bool useInline = false, bool release = false, bool preservePaths = false, DiagnosticReporting useWarnings = (DiagnosticReporting)2u, bool cov = false, uint8_t covPercent = 0u, bool ctfe_cov = false, bool ignoreUnsupportedPragmas = true, bool useModuleInfo = true, bool useTypeInfo = true, bool useExceptions = true, bool useGC = true, bool betterC = false, bool addMain = false, bool allInst = false, bool bitfields = false, CppStdRevision cplusplus = (CppStdRevision)201103u, Help help = Help(), Verbose v = Verbose(), FeatureState useDIP25 = (FeatureState)2u, FeatureState useDIP1000 = (FeatureState)0u, bool ehnogc = false, bool useDIP1021 = false, FeatureState fieldwise = (FeatureState)0u, bool fixAliasThis = false, FeatureState rvalueRefParam = (FeatureState)0u, FeatureState safer = (FeatureState)0u, FeatureState noSharedAccess = (FeatureState)0u, bool previewIn = false, bool inclusiveInContracts = false, bool shortenedMethods = true, bool fixImmutableConv = false, bool fix16997 = true, FeatureState dtorFields = (FeatureState)0u, FeatureState systemVariables = (FeatureState)0u, CHECKENABLE useInvariants = (CHECKENABLE)0u, CHECKENABLE useIn = (CHECKENABLE)0u, CHECKENABLE useOut = (CHECKENABLE)0u, CHECKENABLE useArrayBounds = (CHECKENABLE)0u, CHECKENABLE useAssert = (CHECKENABLE)0u, CHECKENABLE useSwitchError = (CHECKENABLE)0u, CHECKENABLE boundscheck = (CHECKENABLE)0u, CHECKACTION checkAction = (CHECKACTION)0u, CLIIdentifierTable dIdentifierTable = (CLIIdentifierTable)0u, CLIIdentifierTable cIdentifierTable = (CLIIdentifierTable)0u, _d_dynamicArray< const char > argv0 = {}, Array modFileAliasStrings = Array(), Array imppath = Array(), Array fileImppath = Array(), _d_dynamicArray< const char > objdir = {}, _d_dynamicArray< const char > objname = {}, _d_dynamicArray< const char > libname = {}, Output ddoc = Output(), Output dihdr = Output(), Output cxxhdr = Output(), Output json = Output(), JsonFieldFlags jsonFieldFlags = (JsonFieldFlags)0u, Output makeDeps = Output(), Output mixinOut = Output(), Output moduleDeps = Output(), uint32_t debuglevel = 0u, uint32_t versionlevel = 0u, bool run = false, Array runargs = Array(), Array cppswitches = Array(), const char* cpp = nullptr, Array objfiles = Array(), Array linkswitches = Array(), Array linkswitchIsForCC = Array(), Array libfiles = Array(), Array dllfiles = Array(), _d_dynamicArray< const char > deffile = {}, _d_dynamicArray< const char > resfile = {}, _d_dynamicArray< const char > exefile = {}, _d_dynamicArray< const char > mapfile = {}, bool fullyQualifiedObjectFiles = false, bool timeTrace = false, uint32_t timeTraceGranularityUs = 500u, const char* timeTraceFile = nullptr) : + Param(bool obj, bool multiobj = false, bool trace = false, bool tracegc = false, bool vcg_ast = false, DiagnosticReporting useDeprecated = (DiagnosticReporting)1u, bool useUnitTests = false, bool useInline = false, bool release = false, bool preservePaths = false, DiagnosticReporting useWarnings = (DiagnosticReporting)2u, bool cov = false, uint8_t covPercent = 0u, bool ctfe_cov = false, bool ignoreUnsupportedPragmas = true, bool useModuleInfo = true, bool useTypeInfo = true, bool useExceptions = true, bool useGC = true, bool betterC = false, bool addMain = false, bool allInst = false, bool bitfields = false, CppStdRevision cplusplus = (CppStdRevision)201103u, Help help = Help(), Verbose v = Verbose(), FeatureState useDIP25 = (FeatureState)2u, FeatureState useDIP1000 = (FeatureState)0u, bool ehnogc = false, bool useDIP1021 = false, FeatureState fieldwise = (FeatureState)0u, bool fixAliasThis = false, FeatureState rvalueRefParam = (FeatureState)2u, FeatureState safer = (FeatureState)0u, FeatureState noSharedAccess = (FeatureState)0u, bool previewIn = false, bool inclusiveInContracts = false, bool shortenedMethods = true, bool fixImmutableConv = false, bool fix16997 = true, FeatureState dtorFields = (FeatureState)0u, FeatureState systemVariables = (FeatureState)0u, CHECKENABLE useInvariants = (CHECKENABLE)0u, CHECKENABLE useIn = (CHECKENABLE)0u, CHECKENABLE useOut = (CHECKENABLE)0u, CHECKENABLE useArrayBounds = (CHECKENABLE)0u, CHECKENABLE useAssert = (CHECKENABLE)0u, CHECKENABLE useSwitchError = (CHECKENABLE)0u, CHECKENABLE boundscheck = (CHECKENABLE)0u, CHECKACTION checkAction = (CHECKACTION)0u, CLIIdentifierTable dIdentifierTable = (CLIIdentifierTable)0u, CLIIdentifierTable cIdentifierTable = (CLIIdentifierTable)0u, _d_dynamicArray< const char > argv0 = {}, Array modFileAliasStrings = Array(), Array imppath = Array(), Array fileImppath = Array(), _d_dynamicArray< const char > objdir = {}, _d_dynamicArray< const char > objname = {}, _d_dynamicArray< const char > libname = {}, Output ddoc = Output(), Output dihdr = Output(), Output cxxhdr = Output(), Output json = Output(), JsonFieldFlags jsonFieldFlags = (JsonFieldFlags)0u, Output makeDeps = Output(), Output mixinOut = Output(), Output moduleDeps = Output(), uint32_t debuglevel = 0u, uint32_t versionlevel = 0u, bool run = false, Array runargs = Array(), Array cppswitches = Array(), const char* cpp = nullptr, Array objfiles = Array(), Array linkswitches = Array(), Array linkswitchIsForCC = Array(), Array libfiles = Array(), Array dllfiles = Array(), _d_dynamicArray< const char > deffile = {}, _d_dynamicArray< const char > resfile = {}, _d_dynamicArray< const char > exefile = {}, _d_dynamicArray< const char > mapfile = {}, bool fullyQualifiedObjectFiles = false, bool timeTrace = false, uint32_t timeTraceGranularityUs = 500u, const char* timeTraceFile = nullptr) : obj(obj), multiobj(multiobj), trace(trace), diff --git a/compiler/src/dmd/globals.d b/compiler/src/dmd/globals.d index 77bb4986e724..1d1d1bb82b95 100644 --- a/compiler/src/dmd/globals.d +++ b/compiler/src/dmd/globals.d @@ -190,7 +190,7 @@ extern (C++) struct Param bool useDIP1021; // implement https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1021.md FeatureState fieldwise; // do struct equality testing field-wise rather than by memcmp() bool fixAliasThis; // if the current scope has an alias this, check it before searching upper scopes - FeatureState rvalueRefParam; // allow rvalues to be arguments to ref parameters + FeatureState rvalueRefParam = FeatureState.enabled; // allow rvalues to be arguments to ref parameters // https://dconf.org/2019/talks/alexandrescu.html // https://gist.github.com/andralex/e5405a5d773f07f73196c05f8339435a // https://digitalmars.com/d/archives/digitalmars/D/Binding_rvalues_to_ref_parameters_redux_325087.html diff --git a/compiler/src/dmd/typesem.d b/compiler/src/dmd/typesem.d index c631e640815e..41e76e6a7e88 100644 --- a/compiler/src/dmd/typesem.d +++ b/compiler/src/dmd/typesem.d @@ -2335,8 +2335,9 @@ Type typeSemantic(Type type, const ref Loc loc, Scope* sc) // default arg must be an lvalue if (isRefOrOut && !isAuto && - !(fparam.storageClass & STC.constscoperef) && !sc.previews.rvalueRefParam) - e = e.toLvalue(sc, "create default argument for `ref` / `out` parameter from"); + !(fparam.storageClass & STC.constscoperef) && + (!sc.previews.rvalueRefParam || (fparam.storageClass & STC.out_))) + e = e.toLvalue(sc, (global.params.rvalueRefParam != FeatureState.disabled) ? "create default argument for `out` parameter from" : "create default argument for `ref` / `out` parameter from"); fparam.defaultArg = e; return (e.op != EXP.error); diff --git a/compiler/test/compilable/fix21647.d b/compiler/test/compilable/fix21647.d index 58f144045d32..f26fd9523c6d 100644 --- a/compiler/test/compilable/fix21647.d +++ b/compiler/test/compilable/fix21647.d @@ -1,5 +1,5 @@ /* -REQUIRED_ARGS: -preview=rvaluerefparam +REQUIRED_ARGS: TEST_OUTPUT: --- cast(void)0 diff --git a/compiler/test/compilable/issue20704.d b/compiler/test/compilable/issue20704.d index ec95828007fc..529dcfc3641b 100644 --- a/compiler/test/compilable/issue20704.d +++ b/compiler/test/compilable/issue20704.d @@ -1,6 +1,6 @@ /* https://issues.dlang.org/show_bug.cgi?id=20704 -REQUIRED_ARGS: -preview=rvaluerefparam +REQUIRED_ARGS: */ void f1(T)(const auto ref T arg = T.init) {} diff --git a/compiler/test/compilable/issue20705.d b/compiler/test/compilable/issue20705.d index 76a364e129b9..c8fef59fa08d 100644 --- a/compiler/test/compilable/issue20705.d +++ b/compiler/test/compilable/issue20705.d @@ -1,4 +1,4 @@ -// REQUIRED_ARGS: -preview=rvaluerefparam +// REQUIRED_ARGS: struct Foo { int[] a; diff --git a/compiler/test/compilable/previewhelp.d b/compiler/test/compilable/previewhelp.d index b407c277d0e9..89f9d99b98e0 100644 --- a/compiler/test/compilable/previewhelp.d +++ b/compiler/test/compilable/previewhelp.d @@ -11,7 +11,6 @@ Upcoming language changes listed by -preview=name: =dip1021 implement Mutable Function Arguments DIP (https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1021.md) =bitfields add C-like bitfields (https://github.com/dlang/dlang.org/pull/3190) =fixAliasThis when a symbol is resolved, check alias this scope before going to upper scopes (https://github.com/dlang/dmd/pull/8885) - =rvaluerefparam enable rvalue arguments to ref parameters (https://gist.github.com/andralex/e5405a5d773f07f73196c05f8339435a) =safer more safety checks by default (https://github.com/WalterBright/documents/blob/38f0a846726b571f8108f6e63e5e217b91421c86/safer.md) =nosharedaccess disable access to shared memory objects (https://dlang.org/spec/const3.html#shared) =in `in` on parameters means `scope const [ref]` and accepts rvalues (https://dlang.org/spec/function.html#in-params) diff --git a/compiler/test/compilable/reverthelp.d b/compiler/test/compilable/reverthelp.d index 478c6bfbbcd4..adf1b96ebf37 100644 --- a/compiler/test/compilable/reverthelp.d +++ b/compiler/test/compilable/reverthelp.d @@ -10,5 +10,6 @@ Revertable language changes listed by -revert=name: =intpromote revert integral promotions for unary + - ~ operators =dtorfields don't destruct fields of partially constructed objects =fieldwise don't use fieldwise comparisons for struct equality (https://dlang.org/changelog/2.085.0.html#no-cmpsb) + =rvaluerefparam revert rvalue arguments to ref parameters (https://gist.github.com/andralex/e5405a5d773f07f73196c05f8339435a) ---- */ diff --git a/compiler/test/compilable/rvalue2.d b/compiler/test/compilable/rvalue2.d index e1dc44e3bbf4..a4e7822ae3e1 100644 --- a/compiler/test/compilable/rvalue2.d +++ b/compiler/test/compilable/rvalue2.d @@ -1,4 +1,4 @@ -/* PERMUTE_ARGS: -preview=rvaluerefparam +/* PERMUTE_ARGS: -revert=rvaluerefparam */ struct S diff --git a/compiler/test/compilable/rvalueref.d b/compiler/test/compilable/rvalueref.d index fbef10f059fa..8196f3c9a477 100644 --- a/compiler/test/compilable/rvalueref.d +++ b/compiler/test/compilable/rvalueref.d @@ -1,4 +1,4 @@ -/* REQUIRED_ARGS: -preview=rvaluerefparam +/* REQUIRED_ARGS: */ struct AS diff --git a/compiler/test/compilable/test18216.d b/compiler/test/compilable/test18216.d index 43f5629a3c7d..2935e0335652 100644 --- a/compiler/test/compilable/test18216.d +++ b/compiler/test/compilable/test18216.d @@ -1,3 +1,7 @@ +// TODO: hack, make this test work with rvaluerefparam. With ref parameters, opAssign generation triggers: +// compilable/test18216.d(17): Error: struct `test18216.Node` no size because of forward reference +// +// REQUIRED_ARGS: -revert=rvaluerefparam // https://issues.dlang.org/show_bug.cgi?id=18216 struct Node diff --git a/compiler/test/fail_compilation/b20011.d b/compiler/test/fail_compilation/b20011.d index 50ef6aff6097..340a7f9abedf 100644 --- a/compiler/test/fail_compilation/b20011.d +++ b/compiler/test/fail_compilation/b20011.d @@ -1,19 +1,13 @@ /* TEST_OUTPUT: --- -fail_compilation/b20011.d(28): Error: cannot modify expression `S1(cast(ubyte)0u).member` because it is not an lvalue -fail_compilation/b20011.d(31): Error: cannot modify expression `S2(null).member` because it is not an lvalue -fail_compilation/b20011.d(32): Error: cannot modify expression `S2(null).member` because it is not an lvalue -fail_compilation/b20011.d(35): Error: cannot modify expression `U1(cast(ubyte)0u, ).m2` because it is not an lvalue -fail_compilation/b20011.d(40): Error: function `assignableByRef` is not callable using argument types `(ubyte)` -fail_compilation/b20011.d(40): cannot pass rvalue argument `S1(cast(ubyte)0u).member` of type `ubyte` to parameter `ref ubyte p` -fail_compilation/b20011.d(37): `b20011.main.assignableByRef(ref ubyte p)` declared here -fail_compilation/b20011.d(41): Error: function `assignableByOut` is not callable using argument types `(ubyte)` -fail_compilation/b20011.d(41): cannot pass rvalue argument `S1(cast(ubyte)0u).member` of type `ubyte` to parameter `out ubyte p` -fail_compilation/b20011.d(38): `b20011.main.assignableByOut(out ubyte p)` declared here -fail_compilation/b20011.d(42): Error: function `assignableByConstRef` is not callable using argument types `(ubyte)` -fail_compilation/b20011.d(42): cannot pass rvalue argument `S1(cast(ubyte)0u).member` of type `ubyte` to parameter `ref const(ubyte) p` -fail_compilation/b20011.d(39): `b20011.main.assignableByConstRef(ref const(ubyte) p)` declared here +fail_compilation/b20011.d(22): Error: cannot modify expression `S1(cast(ubyte)0u).member` because it is not an lvalue +fail_compilation/b20011.d(25): Error: cannot modify expression `S2(null).member` because it is not an lvalue +fail_compilation/b20011.d(26): Error: cannot modify expression `S2(null).member` because it is not an lvalue +fail_compilation/b20011.d(29): Error: cannot modify expression `U1(cast(ubyte)0u, ).m2` because it is not an lvalue +fail_compilation/b20011.d(35): Error: function `assignableByOut` is not callable using argument types `(ubyte)` +fail_compilation/b20011.d(35): cannot pass rvalue argument `S1(cast(ubyte)0u).member` of type `ubyte` to parameter `out ubyte p` +fail_compilation/b20011.d(32): `b20011.main.assignableByOut(out ubyte p)` declared here --- */ module b20011; diff --git a/compiler/test/fail_compilation/fail20183.d b/compiler/test/fail_compilation/fail20183.d index 9d99212adac7..6770bdd44997 100644 --- a/compiler/test/fail_compilation/fail20183.d +++ b/compiler/test/fail_compilation/fail20183.d @@ -1,9 +1,7 @@ /* REQUIRED_ARGS: -preview=dip1000 TEST_OUTPUT: --- -fail_compilation/fail20183.d(1016): Error: function `addr` is not callable using argument types `(int)` -fail_compilation/fail20183.d(1016): cannot pass rvalue argument `S(0).i` of type `int` to parameter `return ref int b` -fail_compilation/fail20183.d(1004): `fail20183.addr(return ref int b)` declared here +fail_compilation/fail20183.d(1016): Error: address of variable `__rvalue2` assigned to `p` with longer lifetime fail_compilation/fail20183.d(1017): Error: address of expression temporary returned by `s()` assigned to `q` with longer lifetime fail_compilation/fail20183.d(1018): Error: address of struct literal `S(0)` assigned to `r` with longer lifetime --- diff --git a/compiler/test/fail_compilation/fail7603a.d b/compiler/test/fail_compilation/fail7603a.d deleted file mode 100644 index a106a566a5c4..000000000000 --- a/compiler/test/fail_compilation/fail7603a.d +++ /dev/null @@ -1,7 +0,0 @@ -/* -TEST_OUTPUT: ---- -fail_compilation/fail7603a.d(7): Error: cannot create default argument for `ref` / `out` parameter from constant `true` ---- -*/ -void test(ref bool val = true) { } diff --git a/compiler/test/fail_compilation/fail7603b.d b/compiler/test/fail_compilation/fail7603b.d index a6524221afd8..e3d1a7f398f3 100644 --- a/compiler/test/fail_compilation/fail7603b.d +++ b/compiler/test/fail_compilation/fail7603b.d @@ -1,7 +1,7 @@ /* TEST_OUTPUT: --- -fail_compilation/fail7603b.d(7): Error: cannot create default argument for `ref` / `out` parameter from constant `true` +fail_compilation/fail7603b.d(7): Error: cannot create default argument for `out` parameter from constant `true` --- */ void test(out bool val = true) { } diff --git a/compiler/test/fail_compilation/fail7603c.d b/compiler/test/fail_compilation/fail7603c.d deleted file mode 100644 index 3d030fc9668c..000000000000 --- a/compiler/test/fail_compilation/fail7603c.d +++ /dev/null @@ -1,8 +0,0 @@ -/* -TEST_OUTPUT: ---- -fail_compilation/fail7603c.d(8): Error: cannot create default argument for `ref` / `out` parameter from constant `3` ---- -*/ -enum x = 3; -void test(ref int val = x) { } diff --git a/compiler/test/fail_compilation/fail9773.d b/compiler/test/fail_compilation/fail9773.d deleted file mode 100644 index 26447a73914e..000000000000 --- a/compiler/test/fail_compilation/fail9773.d +++ /dev/null @@ -1,10 +0,0 @@ -/* -TEST_OUTPUT: ---- -fail_compilation/fail9773.d(7): Error: cannot create default argument for `ref` / `out` parameter from expression `""` because it is not an lvalue ---- -*/ -void f(ref string a = "") -{ - a = "crash and burn"; -} diff --git a/compiler/test/fail_compilation/fail9891.d b/compiler/test/fail_compilation/fail9891.d index 0c2384fccfa4..b3a1e1625646 100644 --- a/compiler/test/fail_compilation/fail9891.d +++ b/compiler/test/fail_compilation/fail9891.d @@ -1,9 +1,8 @@ /* TEST_OUTPUT: --- -fail_compilation/fail9891.d(13): Error: expression `i` of type `immutable(int)` is not implicitly convertible to type `ref int` of parameter `n` -fail_compilation/fail9891.d(18): Error: expression `i` of type `immutable(int)` is not implicitly convertible to type `out int` of parameter `n` -fail_compilation/fail9891.d(23): Error: cannot create default argument for `ref` / `out` parameter from expression `prop()` because it is not an lvalue +fail_compilation/fail9891.d(12): Error: expression `i` of type `immutable(int)` is not implicitly convertible to type `ref int` of parameter `n` +fail_compilation/fail9891.d(17): Error: expression `i` of type `immutable(int)` is not implicitly convertible to type `out int` of parameter `n` --- */ @@ -19,8 +18,3 @@ void f2(out int n = i) { ++n; } - -void f3(ref int n = prop) -{ - ++n; -} diff --git a/compiler/test/fail_compilation/issue20704.d b/compiler/test/fail_compilation/issue20704.d deleted file mode 100644 index ba91b0635724..000000000000 --- a/compiler/test/fail_compilation/issue20704.d +++ /dev/null @@ -1,39 +0,0 @@ -/* TEST_OUTPUT: ---- -fail_compilation/issue20704.d(17): Error: cannot create default argument for `ref` / `out` parameter from constant `0` -fail_compilation/issue20704.d(28): Error: template instance `issue20704.f2!int` error instantiating -fail_compilation/issue20704.d(19): Error: cannot create default argument for `ref` / `out` parameter from constant `0` -fail_compilation/issue20704.d(30): Error: template instance `issue20704.f4!int` error instantiating -fail_compilation/issue20704.d(17): Error: cannot create default argument for `ref` / `out` parameter from expression `S(0)` because it is not an lvalue -fail_compilation/issue20704.d(36): Error: template instance `issue20704.f2!(S)` error instantiating -fail_compilation/issue20704.d(17): Error: cannot create default argument for `ref` / `out` parameter from expression `null` because it is not an lvalue -fail_compilation/issue20704.d(38): Error: template instance `issue20704.f2!(C)` error instantiating ---- -*/ - -// https://issues.dlang.org/show_bug.cgi?id=20704 - -void f1(T)(const auto ref T arg = T.init) {} -void f2(T)(const ref T arg = T.init) {} -void f3(T)(const auto ref T arg = 0) {} -void f4(T)(const ref T arg = 0) {} - -struct S { int _; } -class C { int _; } - -void main () -{ - int i; - f1!int(i); - f2!int(i); - f3!int(i); - f4!int(i); - f1!int(); - f2!int(); - f3!int(); - f4!int(); - f1!S(); - f2!S(); - f1!C(); - f2!C(); -} diff --git a/compiler/test/fail_compilation/test21807.d b/compiler/test/fail_compilation/test21807.d index aaa56f970987..4c05cefa95eb 100644 --- a/compiler/test/fail_compilation/test21807.d +++ b/compiler/test/fail_compilation/test21807.d @@ -23,33 +23,3 @@ class Foo ca = getSArray(); } } - -/* -TEST_OUTPUT: ---- -fail_compilation/test21807.d(117): Error: function `addr` is not callable using argument types `(int)` -fail_compilation/test21807.d(117): cannot pass rvalue argument `S(0).i` of type `int` to parameter `return ref int b` -fail_compilation/test21807.d(106): `test21807.addr(return ref int b)` declared here ---- -*/ -#line 100 - -struct S -{ - int i; -} - -int* addr(return ref int b) -{ - return &b; -} - -class Foo2 -{ - int* ptr; - - this() - { - ptr = addr(S().i); // struct temporary - } -} diff --git a/compiler/test/fail_compilation/tolvalue.d b/compiler/test/fail_compilation/tolvalue.d index e911dff77296..ed75aa7be24c 100644 --- a/compiler/test/fail_compilation/tolvalue.d +++ b/compiler/test/fail_compilation/tolvalue.d @@ -1,18 +1,15 @@ /** TEST_OUTPUT: --- -fail_compilation/tolvalue.d(28): Error: cannot take address of template `templateFunc(T)()`, perhaps instantiate it first -fail_compilation/tolvalue.d(29): Error: cannot take address of type `int` -fail_compilation/tolvalue.d(30): Error: cannot take address of constant `3` -fail_compilation/tolvalue.d(31): Error: cannot take address of operator `$` -fail_compilation/tolvalue.d(32): Error: cannot take address of compiler-generated variable `__ctfe` -fail_compilation/tolvalue.d(33): Error: cannot take address of manifest constant `f` -fail_compilation/tolvalue.d(38): Error: cannot create default argument for `ref` / `out` parameter from constant `3` -fail_compilation/tolvalue.d(39): Error: cannot create default argument for `ref` / `out` parameter from compiler-generated variable `__ctfe` -fail_compilation/tolvalue.d(40): Error: cannot create default argument for `ref` / `out` parameter from manifest constant `f` -fail_compilation/tolvalue.d(45): Error: cannot modify constant `3` -fail_compilation/tolvalue.d(46): Error: cannot modify compiler-generated variable `__ctfe` -fail_compilation/tolvalue.d(47): Error: cannot modify manifest constant `f` +fail_compilation/tolvalue.d(25): Error: cannot take address of template `templateFunc(T)()`, perhaps instantiate it first +fail_compilation/tolvalue.d(26): Error: cannot take address of type `int` +fail_compilation/tolvalue.d(27): Error: cannot take address of constant `3` +fail_compilation/tolvalue.d(28): Error: cannot take address of operator `$` +fail_compilation/tolvalue.d(29): Error: cannot take address of compiler-generated variable `__ctfe` +fail_compilation/tolvalue.d(30): Error: cannot take address of manifest constant `f` +fail_compilation/tolvalue.d(35): Error: cannot modify constant `3` +fail_compilation/tolvalue.d(36): Error: cannot modify compiler-generated variable `__ctfe` +fail_compilation/tolvalue.d(37): Error: cannot modify manifest constant `f` --- */ @@ -33,13 +30,6 @@ void addr() auto x6 = &E.f; } -void refArg() -{ - void f0(ref int = 3) {} - void f1(ref bool = __ctfe) {} - void f3(ref E = E.f) {} -} - void inc(int lz) { 3++; diff --git a/compiler/test/runnable/overload.d b/compiler/test/runnable/overload.d index c413ade029a6..4886aa918934 100644 --- a/compiler/test/runnable/overload.d +++ b/compiler/test/runnable/overload.d @@ -1,5 +1,5 @@ /* -REQUIRED_ARGS: -preview=rvaluerefparam +REQUIRED_ARGS: EXTRA_SOURCES: imports/ovs1528a.d imports/ovs1528b.d EXTRA_SOURCES: imports/template_ovs1.d imports/template_ovs2.d imports/template_ovs3.d EXTRA_FILES: imports/m8668a.d imports/m8668b.d imports/m8668c.d diff --git a/compiler/test/runnable/rvalue1.d b/compiler/test/runnable/rvalue1.d index f8134f718a9f..4aa80101434d 100644 --- a/compiler/test/runnable/rvalue1.d +++ b/compiler/test/runnable/rvalue1.d @@ -1,4 +1,4 @@ -/* PERMUTE_ARGS: -preview=rvaluerefparam +/* PERMUTE_ARGS: -revert=rvaluerefparam /* testing __rvalue */ import core.stdc.stdio; diff --git a/compiler/test/runnable/structlit.d b/compiler/test/runnable/structlit.d index d4a6bd6061b1..8970254f6ce6 100644 --- a/compiler/test/runnable/structlit.d +++ b/compiler/test/runnable/structlit.d @@ -1,5 +1,5 @@ /* -REQUIRED_ARGS: -preview=rvaluerefparam +REQUIRED_ARGS: RUN_OUTPUT: --- Success diff --git a/compiler/test/runnable/template9.d b/compiler/test/runnable/template9.d index 7a55b2dbfee0..eded936076e1 100644 --- a/compiler/test/runnable/template9.d +++ b/compiler/test/runnable/template9.d @@ -1,5 +1,5 @@ /* -REQUIRED_ARGS: -preview=rvaluerefparam +REQUIRED_ARGS: PERMUTE_ARGS: EXTRA_FILES: imports/testmangle.d TEST_OUTPUT: diff --git a/compiler/test/runnable/testassign.d b/compiler/test/runnable/testassign.d index c2b8a513ee14..e7583bbaf3b9 100644 --- a/compiler/test/runnable/testassign.d +++ b/compiler/test/runnable/testassign.d @@ -1,5 +1,5 @@ /* -REQUIRED_ARGS: -preview=rvaluerefparam +REQUIRED_ARGS: TEST_OUTPUT: --- \ S1 S2a S2b S3a S3b S4a S4b diff --git a/compiler/test/runnable/xtest46.d b/compiler/test/runnable/xtest46.d index cbcbd1a97f1a..71dec3b62f84 100644 --- a/compiler/test/runnable/xtest46.d +++ b/compiler/test/runnable/xtest46.d @@ -1,4 +1,4 @@ -// REQUIRED_ARGS: -preview=rvaluerefparam +// REQUIRED_ARGS: // /* TEST_OUTPUT: --- diff --git a/compiler/test/runnable/xtest46_gc.d b/compiler/test/runnable/xtest46_gc.d index 38c136d531cd..b1a907e6c095 100644 --- a/compiler/test/runnable/xtest46_gc.d +++ b/compiler/test/runnable/xtest46_gc.d @@ -1,5 +1,5 @@ /* -REQUIRED_ARGS: -lowmem -Jrunnable -preview=rvaluerefparam +REQUIRED_ARGS: -lowmem -Jrunnable EXTRA_FILES: xtest46.d TEST_OUTPUT: --- diff --git a/druntime/src/core/internal/moving.d b/druntime/src/core/internal/moving.d index 9c97d2966f7b..7be9206ec64c 100644 --- a/druntime/src/core/internal/moving.d +++ b/druntime/src/core/internal/moving.d @@ -40,9 +40,10 @@ void __move_post_blt(S)(ref S newLocation, ref S oldLocation) nothrow static if (__traits(hasMember, S, "opPostMove")) { - import core.internal.traits : lvalueOf, rvalueOf; - static assert( is(typeof(S.init.opPostMove(lvalueOf!S))) && - !is(typeof(S.init.opPostMove(rvalueOf!S))), + import core.internal.traits : Parameters; + static assert(Parameters!(S.init.opPostMove).length == 1 && + is(Parameters!(S.init.opPostMove)[0] : const S) && + __traits(getParameterStorageClasses, S.init.opPostMove, 0)[0] == "ref", "`" ~ S.stringof ~ ".opPostMove` must take exactly one argument of type `" ~ S.stringof ~ "` by reference"); newLocation.opPostMove(oldLocation); diff --git a/druntime/src/core/internal/traits.d b/druntime/src/core/internal/traits.d index b1b29130eff3..0b2d25c98ae4 100644 --- a/druntime/src/core/internal/traits.d +++ b/druntime/src/core/internal/traits.d @@ -248,8 +248,10 @@ template hasElaborateMove(S) } else static if (is(S == struct)) { - enum hasElaborateMove = (is(typeof(S.init.opPostMove(lvalueOf!S))) && - !is(typeof(S.init.opPostMove(rvalueOf!S)))) || + enum hasElaborateMove = (is(typeof(S.init.opPostMove)) && + Parameters!(S.init.opPostMove).length == 1 && + is(Parameters!(S.init.opPostMove)[0] : const S) && + __traits(getParameterStorageClasses, S.init.opPostMove, 0)[0] == "ref") || anySatisfy!(.hasElaborateMove, Fields!S); } else diff --git a/druntime/test/stdcpp/src/string_test.d b/druntime/test/stdcpp/src/string_test.d index dbbccc7cd6f6..4c14b555404a 100644 --- a/druntime/test/stdcpp/src/string_test.d +++ b/druntime/test/stdcpp/src/string_test.d @@ -19,11 +19,7 @@ unittest str = "Hello again with a long long string woo"; assert(sumOfElements_val(str) == 10935); assert(sumOfElements_ref(str) == 3645); - //assert(str == std_string("Hello again with a long long string woo")); // Needs -preview=rvaluerefparam. - { - auto tmp = std_string("Hello again with a long long string woo"); // Workaround. - assert(str == tmp); - } + assert(str == std_string("Hello again with a long long string woo")); std_string str2 = std_string(Default); assert(str2.size == 0);