Skip to content
This repository was archived by the owner on Jun 20, 2019. It is now read-only.

Commit 3992982

Browse files
committed
Fix inference of 'scope' for parameters for inferable functions
1 parent 1e25719 commit 3992982

File tree

3 files changed

+31
-28
lines changed

3 files changed

+31
-28
lines changed

gcc/d/dfrontend/dtemplate.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,9 +2313,9 @@ void functionResolve(Match *m, Dsymbol *dstart, Loc loc, Scope *sc,
23132313
Expressions *fargs;
23142314
// result
23152315
Match *m;
2316-
int property; // 0: unintialized
2317-
// 1: seen @property
2318-
// 2: not @property
2316+
int property; // 0: unintialized
2317+
// 1: seen @property
2318+
// 2: not @property
23192319
size_t ov_index;
23202320
TemplateDeclaration *td_best;
23212321
TemplateInstance *ti_best;
@@ -2324,13 +2324,12 @@ void functionResolve(Match *m, Dsymbol *dstart, Loc loc, Scope *sc,
23242324

23252325
static int fp(void *param, Dsymbol *s)
23262326
{
2327-
if (!s->errors)
2328-
{
2329-
if (FuncDeclaration *fd = s->isFuncDeclaration())
2330-
return ((ParamDeduce *)param)->applyFunction(fd);
2331-
if (TemplateDeclaration *td = s->isTemplateDeclaration())
2332-
return ((ParamDeduce *)param)->applyTemplate(td);
2333-
}
2327+
if (s->errors)
2328+
return 0;
2329+
if (FuncDeclaration *fd = s->isFuncDeclaration())
2330+
return ((ParamDeduce *)param)->applyFunction(fd);
2331+
if (TemplateDeclaration *td = s->isTemplateDeclaration())
2332+
return ((ParamDeduce *)param)->applyTemplate(td);
23342333
return 0;
23352334
}
23362335

@@ -2750,7 +2749,8 @@ void functionResolve(Match *m, Dsymbol *dstart, Loc loc, Scope *sc,
27502749
* Now instantiate the template.
27512750
*/
27522751
assert(p.td_best->_scope);
2753-
if (!sc) sc = p.td_best->_scope; // workaround for Type::aliasthisOf
2752+
if (!sc)
2753+
sc = p.td_best->_scope; // workaround for Type::aliasthisOf
27542754

27552755
TemplateInstance *ti = new TemplateInstance(loc, p.td_best, p.ti_best->tiargs);
27562756
ti->semantic(sc, fargs);

gcc/d/dfrontend/func.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,10 @@ static void initInferAttributes(FuncDeclaration *fd)
433433

434434
if (!fd->isVirtual() || fd->introducing)
435435
fd->flags |= FUNCFLAGreturnInprocess;
436+
437+
// Initialize for inferring STCscope
438+
if (global.params.vsafe)
439+
fd->flags |= FUNCFLAGinferScope;
436440
}
437441

438442
// Do the semantic analysis on the external interface to the function.
@@ -1576,7 +1580,7 @@ void FuncDeclaration::semantic3(Scope *sc)
15761580
stc |= STCparameter;
15771581
if (f->varargs == 2 && i + 1 == nparams)
15781582
stc |= STCvariadic;
1579-
if (flags & FUNCFLAGinferScope)
1583+
if (flags & FUNCFLAGinferScope && !(fparam->storageClass & STCscope))
15801584
stc |= STCmaybescope;
15811585
stc |= fparam->storageClass & (STCin | STCout | STCref | STCreturn | STCscope | STClazy | STCfinal | STC_TYPECTOR | STCnodtor);
15821586
v->storage_class = stc;
@@ -2485,7 +2489,7 @@ VarDeclaration *FuncDeclaration::declareThis(Scope *sc, AggregateDeclaration *ad
24852489
if (tf->isscope)
24862490
v->storage_class |= STCscope;
24872491
}
2488-
if (flags & FUNCFLAGinferScope)
2492+
if (flags & FUNCFLAGinferScope && !(v->storage_class & STCscope))
24892493
v->storage_class |= STCmaybescope;
24902494

24912495
v->semantic(sc);
@@ -2511,7 +2515,7 @@ VarDeclaration *FuncDeclaration::declareThis(Scope *sc, AggregateDeclaration *ad
25112515
if (tf->isscope)
25122516
v->storage_class |= STCscope;
25132517
}
2514-
if (flags & FUNCFLAGinferScope)
2518+
if (flags & FUNCFLAGinferScope && !(v->storage_class & STCscope))
25152519
v->storage_class |= STCmaybescope;
25162520

25172521
v->semantic(sc);

gcc/d/dfrontend/mtype.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6048,8 +6048,7 @@ MATCH TypeFunction::callMatch(Type *tthis, Expressions *args, int flag)
60486048
{
60496049
if (MODimplicitConv(t->mod, mod))
60506050
match = MATCHconst;
6051-
else if ((mod & MODwild)
6052-
&& MODimplicitConv(t->mod, (mod & ~MODwild) | MODconst))
6051+
else if ((mod & MODwild) && MODimplicitConv(t->mod, (mod & ~MODwild) | MODconst))
60536052
{
60546053
match = MATCHconst;
60556054
}
@@ -6223,12 +6222,12 @@ MATCH TypeFunction::callMatch(Type *tthis, Expressions *args, int flag)
62236222

62246223
switch (tb->ty)
62256224
{
6226-
case Tsarray:
6227-
tsa = (TypeSArray *)tb;
6228-
sz = tsa->dim->toInteger();
6229-
if (sz != nargs - u)
6230-
goto Nomatch;
6231-
case Tarray:
6225+
case Tsarray:
6226+
tsa = (TypeSArray *)tb;
6227+
sz = tsa->dim->toInteger();
6228+
if (sz != nargs - u)
6229+
goto Nomatch;
6230+
case Tarray:
62326231
{
62336232
TypeArray *ta = (TypeArray *)tb;
62346233
for (; u < nargs; u++)
@@ -6263,13 +6262,13 @@ MATCH TypeFunction::callMatch(Type *tthis, Expressions *args, int flag)
62636262
}
62646263
goto Ldone;
62656264
}
6266-
case Tclass:
6267-
// Should see if there's a constructor match?
6268-
// Or just leave it ambiguous?
6269-
goto Ldone;
6265+
case Tclass:
6266+
// Should see if there's a constructor match?
6267+
// Or just leave it ambiguous?
6268+
goto Ldone;
62706269

6271-
default:
6272-
goto Nomatch;
6270+
default:
6271+
goto Nomatch;
62736272
}
62746273
}
62756274
goto Nomatch;

0 commit comments

Comments
 (0)