re PR d/90603 (ICE in functionParameters, at d/dmd/expression.c:1553)
authorIain Buclaw <ibuclaw@gcc.gnu.org>
Sun, 16 Jun 2019 22:50:16 +0000 (22:50 +0000)
committerIain Buclaw <ibuclaw@gcc.gnu.org>
Sun, 16 Jun 2019 22:50:16 +0000 (22:50 +0000)
PR d/90603
d/dmd: Merge upstream dmd 792f0fdf2

Fixes segmentation fault in functionParameters, and other related
semantic bugs in forward or recursively referenced declarations.

Reviewed-on: https://github.com/dlang/dmd/pull/10046

From-SVN: r272366

24 files changed:
gcc/d/dmd/MERGE
gcc/d/dmd/dclass.c
gcc/d/dmd/declaration.c
gcc/d/dmd/denum.c
gcc/d/dmd/dimport.c
gcc/d/dmd/dinterpret.c
gcc/d/dmd/dstruct.c
gcc/d/dmd/dtemplate.c
gcc/d/dmd/expression.c
gcc/d/dmd/expressionsem.c
gcc/d/dmd/func.c
gcc/d/dmd/mtype.c
gcc/d/dmd/optimize.c
gcc/d/dmd/statement.c
gcc/d/dmd/statementsem.c
gcc/d/dmd/traits.c
gcc/testsuite/gdc.test/compilable/imports/test16214b.d [new file with mode: 0644]
gcc/testsuite/gdc.test/compilable/test16214a.d [new file with mode: 0644]
gcc/testsuite/gdc.test/fail_compilation/b15875.d [new file with mode: 0644]
gcc/testsuite/gdc.test/fail_compilation/b17285.d [new file with mode: 0644]
gcc/testsuite/gdc.test/fail_compilation/b19691.d [new file with mode: 0644]
gcc/testsuite/gdc.test/fail_compilation/b19691e.d [new file with mode: 0644]
gcc/testsuite/gdc.test/fail_compilation/b19717.d [new file with mode: 0644]
gcc/testsuite/gdc.test/fail_compilation/b19717a.d [new file with mode: 0644]

index 0620a5ba5564442b8d149f0474739a6edf4ad10c..d208aea3717cee2dbab73402e7e0e126ca9a72f0 100644 (file)
@@ -1,4 +1,4 @@
-6e44734ccbeb78252a52e129a67fefb313679948
+792f0fdf249b21531dc91690024827f4f9ecbb97
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/dmd repository.
index 572b3e24387a62305e36f2522724ab0ab94bbbbc..bbe2f8a9d72e9fa822e933582e78143394cfea04 100644 (file)
@@ -481,7 +481,7 @@ void ClassDeclaration::semantic(Scope *sc)
             baseClass = tc->sym;
             b->sym = baseClass;
 
-            if (tc->sym->_scope && tc->sym->baseok < BASEOKdone)
+            if (tc->sym->baseok < BASEOKdone)
                 resolveBase(this, sc, scx, tc->sym); // Try to resolve forward reference
             if (tc->sym->baseok < BASEOKdone)
             {
@@ -533,7 +533,7 @@ void ClassDeclaration::semantic(Scope *sc)
 
             b->sym = tc->sym;
 
-            if (tc->sym->_scope && tc->sym->baseok < BASEOKdone)
+            if (tc->sym->baseok < BASEOKdone)
                 resolveBase(this, sc, scx, tc->sym); // Try to resolve forward reference
             if (tc->sym->baseok < BASEOKdone)
             {
@@ -918,10 +918,10 @@ bool ClassDeclaration::isBaseOf(ClassDeclaration *cd, int *poffset)
     {
         /* cd->baseClass might not be set if cd is forward referenced.
          */
-        if (!cd->baseClass && cd->_scope && !cd->isInterfaceDeclaration())
+        if (!cd->baseClass && cd->semanticRun < PASSsemanticdone && !cd->isInterfaceDeclaration())
         {
             cd->semantic(NULL);
-            if (!cd->baseClass && cd->_scope)
+            if (!cd->baseClass && cd->semanticRun < PASSsemanticdone)
                 cd->error("base class is forward referenced by %s", toChars());
         }
 
@@ -1574,7 +1574,7 @@ void InterfaceDeclaration::semantic(Scope *sc)
 
             b->sym = tc->sym;
 
-            if (tc->sym->_scope && tc->sym->baseok < BASEOKdone)
+            if (tc->sym->baseok < BASEOKdone)
                 resolveBase(this, sc, scx, tc->sym); // Try to resolve forward reference
             if (tc->sym->baseok < BASEOKdone)
             {
index 2a054306347e60b3a16d367cc8170b643a90ff85..0018d9501f057c5f7a3590a4384668ac57eb6447 100644 (file)
@@ -865,6 +865,11 @@ void VarDeclaration::semantic(Scope *sc)
         _scope = NULL;
     }
 
+    if (!sc)
+        return;
+
+    semanticRun = PASSsemantic;
+
     /* Pick up storage classes from context, but except synchronized,
      * override, abstract, and final.
      */
@@ -1038,6 +1043,7 @@ void VarDeclaration::semantic(Scope *sc)
                 else if (isAliasThisTuple(e))
                 {
                     VarDeclaration *v = copyToTemp(0, "__tup", e);
+                    v->semantic(sc);
                     VarExp *ve = new VarExp(loc, v);
                     ve->type = e->type;
 
@@ -1439,7 +1445,7 @@ Lnomatch:
                         if (!e)
                         {
                             error("is not a static and cannot have static initializer");
-                            return;
+                            e = new ErrorExp();
                         }
                     }
                     ei = new ExpInitializer(_init->loc, e);
index fbca54b7dae0e2e23b1b801e083f689369603c0c..ff261bc0ad087de8f81e4a7229221359072d01b3 100644 (file)
@@ -110,6 +110,9 @@ void EnumDeclaration::semantic(Scope *sc)
         _scope = NULL;
     }
 
+    if (!sc)
+        return;
+
     parent = sc->parent;
     type = type->semantic(loc, sc);
 
index 3d899f09b521c40169c13a8ca204031a5262fe25..5f7d7fdc09e3a1ac41397e465679a99c11f96452 100644 (file)
@@ -197,12 +197,18 @@ void Import::importAll(Scope *sc)
 void Import::semantic(Scope *sc)
 {
     //printf("Import::semantic('%s') %s\n", toPrettyChars(), id->toChars());
+    if (semanticRun > PASSinit)
+        return;
 
     if (_scope)
     {
         sc = _scope;
         _scope = NULL;
     }
+    if (!sc)
+        return;
+
+    semanticRun = PASSsemantic;
 
     // Load if not already done so
     if (!mod)
@@ -291,6 +297,8 @@ void Import::semantic(Scope *sc)
         sc = sc->pop();
     }
 
+    semanticRun = PASSsemanticdone;
+
     // object self-imports itself, so skip that (Bugzilla 7547)
     // don't list pseudo modules __entrypoint.d, __main.d (Bugzilla 11117, 11164)
     if (global.params.moduleDeps != NULL &&
index 0749c7f487dd0d222ed25f5718fc9504d4c614cd..a1658bbd051e75ec12b2223ff2d27b94c2e94507 100644 (file)
@@ -2085,9 +2085,9 @@ public:
             if (v->ident == Id::ctfe)
                 return new IntegerExp(loc, 1, Type::tbool);
 
-            if (!v->originalType && v->_scope)   // semantic() not yet run
+            if (!v->originalType && v->semanticRun < PASSsemanticdone) // semantic() not yet run
             {
-                v->semantic (v->_scope);
+                v->semantic(NULL);
                 if (v->type->ty == Terror)
                     return CTFEExp::cantexp;
             }
index 1338e1f69b04ed99d450d434c975e23da606a692..22da0a3be3d7914a2f2ffef4d130aacc4c4afd6a 100644 (file)
@@ -116,7 +116,7 @@ void semanticTypeInfo(Scope *sc, Type *t)
 
                 // Bugzilla 15149, if the typeid operand type comes from a
                 // result of auto function, it may be yet speculative.
-                unSpeculative(sc, sd);
+                // unSpeculative(sc, sd);
             }
 
             /* Step 2: If the TypeInfo generation requires sd.semantic3, run it later.
@@ -324,6 +324,7 @@ void AggregateDeclaration::semantic3(Scope *sc)
 
     if (sd)
         sd->semanticTypeInfoMembers();
+    semanticRun = PASSsemantic3done;
 }
 
 /***************************************
@@ -359,7 +360,7 @@ bool AggregateDeclaration::determineFields()
 
             AggregateDeclaration *ad = ((SV *)param)->agg;
 
-            if (v->_scope)
+            if (v->semanticRun < PASSsemanticdone)
                 v->semantic(NULL);
             // Note: Aggregate fields or size could have determined during v->semantic.
             if (ad->sizeok != SIZEOKnone)
index 0173ee401b685c9a2b52602554e8014042c8eb31..b5e3662a9e30b855fb181731009aa7b8d1ef78f1 100644 (file)
@@ -685,6 +685,7 @@ void TemplateDeclaration::semantic(Scope *sc)
     /* BUG: should check:
      *  o no virtual functions or non-static data members of classes
      */
+    semanticRun = PASSsemanticdone;
 }
 
 const char *TemplateDeclaration::kind() const
@@ -2169,12 +2170,14 @@ void functionResolve(Match *m, Dsymbol *dstart, Loc loc, Scope *sc,
             if (tiargs && tiargs->dim > 0)
                 return 0;
 
-            if (fd->semanticRun == PASSinit && fd->_scope)
+            // constructors need a valid scope in order to detect semantic errors
+            if (!fd->isCtorDeclaration() &&
+                fd->semanticRun < PASSsemanticdone)
             {
                 Ungag ungag = fd->ungagSpeculative();
-                fd->semantic(fd->_scope);
+                fd->semantic(NULL);
             }
-            if (fd->semanticRun == PASSinit)
+            if (fd->semanticRun < PASSsemanticdone)
             {
                 ::error(loc, "forward reference to template %s", fd->toChars());
                 return 1;
index af762eb3c66f36f9eb0c65a06ffa0d293476e4b6..c674392095e21c6b756b3adbdc42c66001819e2b 100644 (file)
@@ -516,9 +516,9 @@ static bool checkPropertyCall(Expression *e)
             tf = (TypeFunction *)ce->f->type;
             /* If a forward reference to ce->f, try to resolve it
              */
-            if (!tf->deco && ce->f->_scope)
+            if (!tf->deco && ce->f->semanticRun < PASSsemanticdone)
             {
-                ce->f->semantic(ce->f->_scope);
+                ce->f->semantic(NULL);
                 tf = (TypeFunction *)ce->f->type;
             }
         }
@@ -1125,6 +1125,8 @@ bool arrayExpressionToCommonType(Scope *sc, Expressions *exps, Type **pt)
     Type *t0 = NULL;
     Expression *e0 = NULL;      // dead-store to prevent spurious warning
     size_t j0 = ~0;             // dead-store to prevent spurious warning
+    bool foundType = false;
+
     for (size_t i = 0; i < exps->dim; i++)
     {
         Expression *e = (*exps)[i];
@@ -1140,6 +1142,7 @@ bool arrayExpressionToCommonType(Scope *sc, Expressions *exps, Type **pt)
         }
         if (e->op == TOKtype)
         {
+            foundType = true;   // do not break immediately, there might be more errors
             e->checkValue();    // report an error "type T has no value"
             t0 = Type::terror;
             continue;
@@ -1158,7 +1161,7 @@ bool arrayExpressionToCommonType(Scope *sc, Expressions *exps, Type **pt)
 
         e = doCopyOrMove(sc, e);
 
-        if (t0 && !t0->equals(e->type))
+        if (!foundType && t0 && !t0->equals(e->type))
         {
             /* This applies ?: to merge the types. It's backwards;
              * ?: should call this function to merge types.
index 88c59a9045b105cf96911749354ae99026a770a5..c23e332b180f626108b73ba3a9db3f94b93dca04 100644 (file)
@@ -397,6 +397,7 @@ public:
             // Create the magic __ctfe bool variable
             VarDeclaration *vd = new VarDeclaration(exp->loc, Type::tbool, Id::ctfe, NULL);
             vd->storage_class |= STCtemp;
+            vd->semanticRun = PASSsemanticdone;
             Expression *e = new VarExp(exp->loc, vd);
             e = semantic(e, sc);
             result = e;
@@ -1441,7 +1442,10 @@ public:
 
     void visit(VarExp *e)
     {
-        if (FuncDeclaration *fd = e->var->isFuncDeclaration())
+        VarDeclaration *vd = e->var->isVarDeclaration();
+        FuncDeclaration *fd = e->var->isFuncDeclaration();
+
+        if (fd)
         {
             //printf("L%d fd = %s\n", __LINE__, f->toChars());
             if (!fd->functionSemantic())
@@ -1452,7 +1456,14 @@ public:
             e->type = e->var->type;
 
         if (e->type && !e->type->deco)
+        {
+            Declaration *decl = e->var->isDeclaration();
+            if (decl)
+                decl->inuse++;
             e->type = e->type->semantic(e->loc, sc);
+            if (decl)
+                decl->inuse--;
+        }
 
         /* Fix for 1161 doesn't work because it causes protection
          * problems when instantiating imported templates passing private
@@ -1460,7 +1471,7 @@ public:
          */
         //checkAccess(e->loc, sc, NULL, e->var);
 
-        if (VarDeclaration *vd = e->var->isVarDeclaration())
+        if (vd)
         {
             if (vd->checkNestedReference(sc, e->loc))
                 return setError();
@@ -1468,7 +1479,7 @@ public:
             // the purity violation error is redundant.
             //checkPurity(sc, vd);
         }
-        else if (FuncDeclaration *fd = e->var->isFuncDeclaration())
+        else if (fd)
         {
             // TODO: If fd isn't yet resolved its overload, the checkNestedReference
             // call would cause incorrect validation.
@@ -1962,8 +1973,8 @@ public:
                         ClassDeclaration *cd = ((TypeClass *)e->targ)->sym;
                         Parameters *args = new Parameters;
                         args->reserve(cd->baseclasses->dim);
-                        if (cd->_scope && !cd->symtab)
-                            cd->semantic(cd->_scope);
+                        if (cd->semanticRun < PASSsemanticdone)
+                            cd->semantic(NULL);
                         for (size_t i = 0; i < cd->baseclasses->dim; i++)
                         {
                             BaseClass *b = (*cd->baseclasses)[i];
index 04c70cf3b7b3b99b514c88b3d1e00ac963a3280d..11e4b2f721ba495475b6c31a3d136f442d3d1157 100644 (file)
@@ -471,6 +471,9 @@ void FuncDeclaration::semantic(Scope *sc)
         _scope = NULL;
     }
 
+    if (!sc || errors)
+        return;
+
     parent = sc->parent;
     Dsymbol *parent = toParent();
 
@@ -932,6 +935,7 @@ void FuncDeclaration::semantic(Scope *sc)
 
             case -2:
                 // can't determine because of forward references
+                errors = true;
                 return;
 
             default:
@@ -1049,6 +1053,7 @@ void FuncDeclaration::semantic(Scope *sc)
 
                 case -2:
                     // can't determine because of forward references
+                    errors = true;
                     return;
 
                 default:
index 906fb11b634c7475bd883ab86846d21721273887..b76b5baad25536db35e323af3df7fe6bdedcf6c4 100644 (file)
@@ -4672,7 +4672,7 @@ Type *TypeAArray::semantic(Loc loc, Scope *sc)
         /* AA's need typeid(index).equals() and getHash(). Issue error if not correctly set up.
          */
         StructDeclaration *sd = ((TypeStruct *)tbase)->sym;
-        if (sd->_scope)
+        if (sd->semanticRun < PASSsemanticdone)
             sd->semantic(NULL);
 
         // duplicate a part of StructDeclaration::semanticTypeInfoMembers
@@ -4739,7 +4739,7 @@ Type *TypeAArray::semantic(Loc loc, Scope *sc)
     else if (tbase->ty == Tclass && !((TypeClass *)tbase)->sym->isInterfaceDeclaration())
     {
         ClassDeclaration *cd = ((TypeClass *)tbase)->sym;
-        if (cd->_scope)
+        if (cd->semanticRun < PASSsemanticdone)
             cd->semantic(NULL);
 
         if (!ClassDeclaration::object)
@@ -5336,7 +5336,7 @@ int Type::covariant(Type *t, StorageClass *pstc, bool fix17349)
 
         // If t1n is forward referenced:
         ClassDeclaration *cd = ((TypeClass *)t1n)->sym;
-        if (cd->_scope)
+        if (cd->semanticRun < PASSsemanticdone && !cd->isBaseInfoComplete())
             cd->semantic(NULL);
         if (!cd->isBaseInfoComplete())
         {
@@ -5448,6 +5448,13 @@ Type *TypeFunction::semantic(Loc loc, Scope *sc)
 
     bool errors = false;
 
+    if (inuse > 500)
+    {
+        inuse = 0;
+        ::error(loc, "recursive type");
+        return Type::terror;
+    }
+
     /* Copy in order to not mess up original.
      * This can produce redundant copies if inferring return type,
      * as semantic() will get called again on this.
@@ -5532,9 +5539,9 @@ Type *TypeFunction::semantic(Loc loc, Scope *sc)
         for (size_t i = 0; i < dim; i++)
         {
             Parameter *fparam = Parameter::getNth(tf->parameters, i);
-            tf->inuse++;
+            inuse++;
             fparam->type = fparam->type->semantic(loc, argsc);
-            if (tf->inuse == 1) tf->inuse--;
+            inuse--;
 
             if (fparam->type->ty == Terror)
             {
@@ -5776,13 +5783,6 @@ Type *TypeFunction::semantic(Loc loc, Scope *sc)
     }
     tf->iswild = wildparams;
 
-    if (tf->inuse)
-    {
-        error(loc, "recursive type");
-        tf->inuse = 0;
-        errors = true;
-    }
-
     if (tf->isproperty && (tf->varargs || Parameter::dim(tf->parameters) > 2))
     {
         error(loc, "properties can only have zero, one, or two parameter");
@@ -7444,8 +7444,8 @@ Expression *TypeEnum::dotExp(Scope *sc, Expression *e, Identifier *ident, int fl
     if (ident == Id::_mangleof)
         return getProperty(e->loc, ident, flag & 1);
 
-    if (sym->_scope)
-        sym->semantic(sym->_scope);
+    if (sym->semanticRun < PASSsemanticdone)
+        sym->semantic(NULL);
     if (!sym->members)
     {
         if (sym->isSpecial())
@@ -7914,8 +7914,8 @@ L1:
                 return e;
             }
         }
-        if (d->semanticRun == PASSinit && d->_scope)
-            d->semantic(d->_scope);
+        if (d->semanticRun == PASSinit)
+            d->semantic(NULL);
         checkAccess(e->loc, sc, e, d);
         VarExp *ve = new VarExp(e->loc, d);
         if (d->isVarDeclaration() && d->needThis())
@@ -8443,7 +8443,7 @@ L1:
 
         if (ident == Id::outer && sym->vthis)
         {
-            if (sym->vthis->_scope)
+            if (sym->vthis->semanticRun == PASSinit)
                 sym->vthis->semantic(NULL);
 
             if (ClassDeclaration *cdp = sym->toParent2()->isClassDeclaration())
@@ -8670,8 +8670,8 @@ L1:
             }
         }
         //printf("e = %s, d = %s\n", e->toChars(), d->toChars());
-        if (d->semanticRun == PASSinit && d->_scope)
-            d->semantic(d->_scope);
+        if (d->semanticRun == PASSinit)
+            d->semantic(NULL);
         checkAccess(e->loc, sc, e, d);
         VarExp *ve = new VarExp(e->loc, d);
         if (d->isVarDeclaration() && d->needThis())
@@ -8727,9 +8727,9 @@ MATCH TypeClass::implicitConvTo(Type *to)
     if (cdto)
     {
         //printf("TypeClass::implicitConvTo(to = '%s') %s, isbase = %d %d\n", to->toChars(), toChars(), cdto->isBaseInfoComplete(), sym->isBaseInfoComplete());
-        if (cdto->_scope && !cdto->isBaseInfoComplete())
+        if (cdto->semanticRun < PASSsemanticdone && !cdto->isBaseInfoComplete())
             cdto->semantic(NULL);
-        if (sym->_scope && !sym->isBaseInfoComplete())
+        if (sym->semanticRun < PASSsemanticdone && !sym->isBaseInfoComplete())
             sym->semantic(NULL);
         if (cdto->isBaseOf(sym, NULL) && MODimplicitConv(mod, to->mod))
         {
index b382d0adeb4efa2663ed51b5babea754d1dfa1c5..2e702ba9d86690eeedbc500dad21c0852215fb9b 100644 (file)
@@ -34,8 +34,8 @@ Expression *expandVar(int result, VarDeclaration *v)
     Expression *e = NULL;
     if (!v)
         return e;
-    if (!v->originalType && v->_scope)   // semantic() not yet run
-        v->semantic (v->_scope);
+    if (!v->originalType && v->semanticRun < PASSsemanticdone) // semantic() not yet run
+        v->semantic(NULL);
 
     if (v->isConst() || v->isImmutable() || v->storage_class & STCmanifest)
     {
index 2d3a11237cbbccfcd42da4bd89e67f9e1447f176..450b3f4f5948c0cbebdf94ead6c79c0332f058a2 100644 (file)
@@ -1312,7 +1312,7 @@ Statement *OnScopeStatement::syntaxCopy()
     return new OnScopeStatement(loc, tok, statement->syntaxCopy());
 }
 
-Statement *OnScopeStatement::scopeCode(Scope *, Statement **sentry, Statement **sexception, Statement **sfinally)
+Statement *OnScopeStatement::scopeCode(Scope *sc, Statement **sentry, Statement **sexception, Statement **sfinally)
 {
     //printf("OnScopeStatement::scopeCode()\n");
     //print();
@@ -1340,6 +1340,7 @@ Statement *OnScopeStatement::scopeCode(Scope *, Statement **sentry, Statement **
              *  sfinally: if (!x) statement;
              */
             VarDeclaration *v = copyToTemp(0, "__os", new IntegerExp(Loc(), 0, Type::tbool));
+            v->semantic(sc);
             *sentry = new ExpStatement(loc, v);
 
             Expression *e = new IntegerExp(Loc(), 1, Type::tbool);
index 143864dc666aee7a651c2c8a6cd405ca351005f4..cc2b63e24666a499d5634b9a150984860c54e27f 100644 (file)
@@ -1074,6 +1074,7 @@ public:
                     else
                     {
                         r = copyToTemp(0, "__r", fs->aggr);
+                        r->semantic(sc);
                         init = new ExpStatement(loc, r);
                         if (vinit)
                             init = new CompoundStatement(loc, new ExpStatement(loc, vinit), init);
@@ -1106,6 +1107,7 @@ public:
                     else
                     {
                         VarDeclaration *vd = copyToTemp(STCref, "__front", einit);
+                        vd->semantic(sc);
                         makeargs = new ExpStatement(loc, vd);
 
                         Type *tfront = NULL;
@@ -2986,6 +2988,7 @@ public:
              *  try { body } finally { _d_monitorexit(tmp); }
              */
             VarDeclaration *tmp = copyToTemp(0, "__sync", ss->exp);
+            tmp->semantic(sc);
 
             Statements *cs = new Statements();
             cs->push(new ExpStatement(ss->loc, tmp));
@@ -3133,6 +3136,7 @@ public:
                      * }
                      */
                     VarDeclaration *tmp = copyToTemp(0, "__withtmp", ws->exp);
+                    tmp->semantic(sc);
                     ExpStatement *es = new ExpStatement(ws->loc, tmp);
                     ws->exp = new VarExp(ws->loc, tmp);
                     Statement *ss = new ScopeStatement(ws->loc, new CompoundStatement(ws->loc, es, ws), ws->endloc);
index 1d5f3fc1064e63a1219e6c842202e635bba3dd35..2430383526849c3c5e5d2c7c41d47b3762e0681e 100644 (file)
@@ -671,8 +671,8 @@ Expression *semanticTraits(TraitsExp *e, Scope *sc)
                 e->error("argument %s has no protection", o->toChars());
             return new ErrorExp();
         }
-        if (s->_scope)
-            s->semantic(s->_scope);
+        if (s->semanticRun == PASSinit)
+            s->semantic(NULL);
 
         const char *protName = protectionToChars(s->prot().kind);   // TODO: How about package(names)
         assert(protName);
@@ -1240,7 +1240,7 @@ Expression *semanticTraits(TraitsExp *e, Scope *sc)
         ClassDeclaration *cd = sds->isClassDeclaration();
         if (cd && e->ident == Id::allMembers)
         {
-            if (cd->_scope)
+            if (cd->semanticRun < PASSsemanticdone)
                 cd->semantic(NULL);    // Bugzilla 13668: Try to resolve forward reference
 
             struct PushBaseMembers
diff --git a/gcc/testsuite/gdc.test/compilable/imports/test16214b.d b/gcc/testsuite/gdc.test/compilable/imports/test16214b.d
new file mode 100644 (file)
index 0000000..e2036fc
--- /dev/null
@@ -0,0 +1,10 @@
+module test16214b;
+import test16214a;
+
+struct Appender() { int[] arr; }
+struct Tuple() { alias A = Appender!(); }
+
+class EventLoop
+{
+    auto f() { auto x = [Tuple!().init]; }
+}
diff --git a/gcc/testsuite/gdc.test/compilable/test16214a.d b/gcc/testsuite/gdc.test/compilable/test16214a.d
new file mode 100644 (file)
index 0000000..2ea64d9
--- /dev/null
@@ -0,0 +1,7 @@
+// EXTRA_SOURCES: imports/test16214b.d
+// REQUIRED_ARGS: -Icompilable/imports
+
+module test16214a;
+import test16214b;
+
+class LibasyncEventLoop : EventLoop {}
diff --git a/gcc/testsuite/gdc.test/fail_compilation/b15875.d b/gcc/testsuite/gdc.test/fail_compilation/b15875.d
new file mode 100644 (file)
index 0000000..daa79b7
--- /dev/null
@@ -0,0 +1,10 @@
+/* TEST_OUTPUT:
+---
+fail_compilation/b15875.d(9): Error: circular reference to variable `a`
+fail_compilation/b15875.d(10): Error: circular reference to `b15875.f`
+---
+*/
+// https://issues.dlang.org/show_bug.cgi?id=15875
+// https://issues.dlang.org/show_bug.cgi?id=17290
+d o(int[a]a)(){}
+f.T f(){}
diff --git a/gcc/testsuite/gdc.test/fail_compilation/b17285.d b/gcc/testsuite/gdc.test/fail_compilation/b17285.d
new file mode 100644 (file)
index 0000000..7b79cf0
--- /dev/null
@@ -0,0 +1,15 @@
+/*
+TEST_OUTPUT:
+---
+fail_compilation/b17285.d(14): Error: type `ONE` has no value
+fail_compilation/b17285.d(14): Error: type `TWO` has no value
+fail_compilation/b17285.d(14): Error: cannot implicitly convert expression `ONE` of type `b17285.ONE` to `int`
+---
+*/
+
+class ONE {}
+enum TWO;
+
+void foo() {
+    foreach(key; [ONE, TWO, 1]) {}
+}
diff --git a/gcc/testsuite/gdc.test/fail_compilation/b19691.d b/gcc/testsuite/gdc.test/fail_compilation/b19691.d
new file mode 100644 (file)
index 0000000..8663512
--- /dev/null
@@ -0,0 +1,20 @@
+// REQUIRED_ARGS: -de
+/* TEST_OUTPUT:
+---
+fail_compilation/b19691.d(13): Error: forward reference to template `this`
+fail_compilation/b19691.d(19): Deprecation: constructor `b19691.S2.this` all parameters have default arguments, but structs cannot have default constructors.
+---
+*/
+// https://issues.dlang.org/show_bug.cgi?id=19691
+module b19691;
+
+struct S1 {
+    this(T...)(T) {
+        S2("");
+    }
+}
+
+struct S2 {
+    this(string) {}
+    this(S1 s = null) {}
+}
diff --git a/gcc/testsuite/gdc.test/fail_compilation/b19691e.d b/gcc/testsuite/gdc.test/fail_compilation/b19691e.d
new file mode 100644 (file)
index 0000000..21d0e90
--- /dev/null
@@ -0,0 +1,24 @@
+// REQUIRED_ARGS: -de
+/* TEST_OUTPUT:
+---
+fail_compilation/b19691e.d(17): Error: forward reference to template `this`
+fail_compilation/b19691e.d(17): Error: constructor `b19691e.S2.this(S1 s = "")` is not callable using argument types `(string)`
+fail_compilation/b19691e.d(17): Error: forward reference to template `this`
+fail_compilation/b19691e.d(23): Deprecation: constructor `b19691e.S2.this` all parameters have default arguments, but structs cannot have default constructors.
+---
+*/
+// https://issues.dlang.org/show_bug.cgi?id=19691
+module b19691e;
+
+struct S1
+{
+    this(T)(T)
+    {
+        S2("");
+    }
+}
+
+struct S2
+{
+    this(S1 s = ""){}
+}
diff --git a/gcc/testsuite/gdc.test/fail_compilation/b19717.d b/gcc/testsuite/gdc.test/fail_compilation/b19717.d
new file mode 100644 (file)
index 0000000..6a48b88
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+TEST_OUTPUT:
+---
+fail_compilation/b19717.d(16): Error: undefined identifier `Foo`, did you mean function `foo`?
+fail_compilation/b19717.d(13): Error: forward reference to template `foo`
+fail_compilation/b19717.d(13): Error: forward reference to inferred return type of function call `foo()`
+---
+*/
+
+enum bar = __traits(getMember, mixin(__MODULE__), "foo");
+
+auto foo() {
+       return foo();
+}
+
+void foo(Foo) {}
diff --git a/gcc/testsuite/gdc.test/fail_compilation/b19717a.d b/gcc/testsuite/gdc.test/fail_compilation/b19717a.d
new file mode 100644 (file)
index 0000000..79a9de0
--- /dev/null
@@ -0,0 +1,14 @@
+// REQUIRED_ARGS: -de
+/* TEST_OUTPUT:
+---
+fail_compilation/b19717a.d(14): Error: forward reference to template `a`
+fail_compilation/b19717a.d(14): Error: forward reference to template `a`
+fail_compilation/b19717a.d(14): Error: none of the overloads of `a` are callable using argument types `()`, candidates are:
+fail_compilation/b19717a.d(13):        `b19717a.a(int b)`
+fail_compilation/b19717a.d(14):        `b19717a.a(int b = a)`
+---
+*/
+module b19717a;
+
+auto a(int b) {}
+auto a(int b = a) {}