[Issue 5769] struct elaborate constructor should make rvalue

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Mar 23 05:50:21 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5769



--- Comment #1 from Kenji Hara <k.hara.pg at gmail.com> 2011-03-23 05:47:01 PDT ---
Fixing thi bug is difficult for me.

DMD internally behavior is...
1.Elaborate constructor returns this reference internally.
  -> see CtorDeclaration::semantic()
2.Elaborate constructor call T(args) is translated like (T __ctmp,
__ctmp.__ctor(args)) and __ctmp.__ctor returns ref T.
  -> see CallExp::semantic

Trivial fix patch is follwing, but this causes copying value.
----
 src/func.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/func.c b/src/func.c
index c3fd455..ea48670 100644
--- a/src/func.c
+++ b/src/func.c
@@ -2953,7 +2953,7 @@ void CtorDeclaration::semantic(Scope *sc)

 #if STRUCTTHISREF
     if (ad && ad->isStructDeclaration())
-    {   ((TypeFunction *)type)->isref = 1;
+    {   //((TypeFunction *)type)->isref = 1;
         if (!originalType)
             // Leave off the "ref"
             originalType = new TypeFunction(arguments, tret, varargs, LINKd,
storage_class | sc->stc);
----

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list