[Issue 3863] Various errors and ICE(todt.c) for struct constructors with ellipses

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Apr 11 14:51:34 PDT 2010


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


Don <clugdbug at yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|rejects-valid               |patch, wrong-code


--- Comment #5 from Don <clugdbug at yahoo.com.au> 2010-04-11 14:51:25 PDT ---
Actually this is a rare case where the ICE bug is the same as the others.
I don't think it has anything to do with constructor varargs, actually.
It involves using a struct constructor to perform type inference of a member of
that struct.

Here's an example of a situation where the current behaviour leads to wrong
code:

struct Vec {
   int w;
   this(int x) { w = 2; }

   enum KK = Vec(100);
   enum Vec KK2 = Vec(100);
}

static assert(Vec.KK == Vec.KK2);
// Error: static assert  ((Vec(100)) == (Vec(2))) is false
=========


PATCH. Issue an error message in these potentially recursive situations.
Although in this specific case, it could be made to compile by running semantic
on the constructors first, that won't work in general (the constructor may make
use of the enum, for example).
I've tested this on the DMD test suite, and it passes.


expression.c CallExp::semantic(), line 6790.
==========

#if !STRUCTTHISREF
                /* Constructors return a pointer to the instance
                 */
                e = new PtrExp(loc, e);
#endif
                e = e->semantic(sc);
                return e;
            }
+            // Check for a forward reference to a struct constructor.
+            else if (arguments && arguments->dim && !ad->ctor && ad->sizeok !=
1)
+            {
+                // The semantic pass of the struct isn't yet complete.
+                // Check for attempt to use a constructor.
+                Dsymbol *ctor = ad->search(0, Id::ctor, 0);
+                if (ctor)
+                {
+                    error("Forward reference to struct constructor");
+                    return new ErrorExp();
+                }
+            }

-- 
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