Skip to content

Commit e3bf0aa

Browse files
committed
Fix Issue 18212 - Usage of cfloat,cdouble,cfloat,ifloat,idouble,ireal shouldn't trigger an error in deprecated code
1 parent c22cba2 commit e3bf0aa

8 files changed

Lines changed: 52 additions & 20 deletions

File tree

src/dmd/dscope.d

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,4 +807,28 @@ struct Scope
807807
else
808808
return STRUCTALIGN_DEFAULT;
809809
}
810+
811+
/**********************************
812+
* Checks whether the current scope (or any of its parents) is deprecated.
813+
*
814+
* Returns: `true` if any parent scope is deprecated, `false` otherwise`
815+
*/
816+
extern(D) bool isDeprecated()
817+
{
818+
for (Dsymbol sp = this.parent; sp; sp = sp.parent)
819+
{
820+
if (sp.isDeprecated())
821+
return true;
822+
}
823+
for (Scope* sc2 = &this; sc2; sc2 = sc2.enclosing)
824+
{
825+
if (sc2.scopesym && sc2.scopesym.isDeprecated())
826+
return true;
827+
828+
// If inside a StorageClassDeclaration that is deprecated
829+
if (sc2.stc & STC.deprecated_)
830+
return true;
831+
}
832+
return false;
833+
}
810834
}

src/dmd/dsymbol.d

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -310,20 +310,9 @@ extern (C++) class Dsymbol : RootObject
310310
if (global.params.useDeprecated != 1 && isDeprecated())
311311
{
312312
// Don't complain if we're inside a deprecated symbol's scope
313-
for (Dsymbol sp = sc.parent; sp; sp = sp.parent)
314-
{
315-
if (sp.isDeprecated())
316-
return false;
317-
}
318-
for (Scope* sc2 = sc; sc2; sc2 = sc2.enclosing)
319-
{
320-
if (sc2.scopesym && sc2.scopesym.isDeprecated())
321-
return false;
313+
if (sc.isDeprecated())
314+
return false;
322315

323-
// If inside a StorageClassDeclaration that is deprecated
324-
if (sc2.stc & STC.deprecated_)
325-
return false;
326-
}
327316
const(char)* message = null;
328317
for (Dsymbol p = this; p; p = p.parent)
329318
{

src/dmd/dsymbolsem.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
383383
//printf("storage_class = x%x\n", storage_class);
384384

385385
if (global.params.vcomplex)
386-
dsym.type.checkComplexTransition(dsym.loc);
386+
dsym.type.checkComplexTransition(dsym.loc, sc);
387387

388388
// Calculate type size + safety checks
389389
if (sc.func && !sc.intypeof)

src/dmd/expressionsem.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,7 +1856,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
18561856
assert(0);
18571857

18581858
if (global.params.vcomplex)
1859-
exp.type.checkComplexTransition(exp.loc);
1859+
exp.type.checkComplexTransition(exp.loc, sc);
18601860

18611861
result = e;
18621862
}
@@ -3774,7 +3774,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
37743774
}
37753775

37763776
if (global.params.vcomplex)
3777-
ta.checkComplexTransition(exp.loc);
3777+
ta.checkComplexTransition(exp.loc, sc);
37783778

37793779
Expression e;
37803780
if (ea && ta.toBasetype().ty == Tclass)

src/dmd/mtype.d

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3010,15 +3010,18 @@ extern (C++) abstract class Type : RootObject
30103010
* Params:
30113011
* loc = The source location.
30123012
*/
3013-
final void checkComplexTransition(Loc loc)
3013+
final bool checkComplexTransition(Loc loc, Scope* sc)
30143014
{
3015+
if (sc.isDeprecated())
3016+
return false;
3017+
30153018
Type t = baseElemOf();
30163019
while (t.ty == Tpointer || t.ty == Tarray)
30173020
t = t.nextOf().baseElemOf();
30183021

30193022
// Basetype is an opaque enum, nothing to check.
30203023
if (t.ty == Tenum && !(cast(TypeEnum)t).sym.memtype)
3021-
return;
3024+
return false;
30223025

30233026
if (t.isimaginary() || t.iscomplex())
30243027
{
@@ -3047,13 +3050,16 @@ extern (C++) abstract class Type : RootObject
30473050
{
30483051
deprecation(loc, "use of complex type `%s` is deprecated, use `std.complex.Complex!(%s)` instead",
30493052
toChars(), rt.toChars());
3053+
return true;
30503054
}
30513055
else
30523056
{
30533057
deprecation(loc, "use of imaginary type `%s` is deprecated, use `%s` instead",
30543058
toChars(), rt.toChars());
3059+
return true;
30553060
}
30563061
}
3062+
return false;
30573063
}
30583064

30593065
static void error(Loc loc, const(char)* format, ...)

src/dmd/mtype.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ class Type : public RootObject
336336
uinteger_t sizemask();
337337
virtual bool needsDestruction();
338338
virtual bool needsNested();
339-
void checkComplexTransition(Loc loc);
339+
void checkComplexTransition(Loc loc, Scope *sc);
340340

341341
static void error(Loc loc, const char *format, ...);
342342
static void warning(Loc loc, const char *format, ...);

src/dmd/semantic3.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ private extern(C++) final class Semantic3Visitor : Visitor
581581
funcdecl.fbody = new ErrorStatement();
582582
}
583583
if (global.params.vcomplex && f.next !is null)
584-
f.next.checkComplexTransition(funcdecl.loc);
584+
f.next.checkComplexTransition(funcdecl.loc, sc);
585585

586586
if (funcdecl.returns && !funcdecl.fbody.isErrorStatement())
587587
{

test/compilable/sw_transition_complex.d

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,16 @@ struct S;
141141
void test14488c(E *e, S *s)
142142
{
143143
}
144+
145+
// Issue 18212 - Usage of cfloat,cdouble,cfloat,ifloat,idouble,ireal shouldn't trigger an error in deprecated code
146+
deprecated void test18212(creal c){}
147+
deprecated unittest
148+
{
149+
ireal = 2i;
150+
creal = 2 + 3i;
151+
}
152+
deprecated struct Foo
153+
{
154+
ifloat a = 2i;
155+
cfloat b = 2f + 2i;
156+
}

0 commit comments

Comments
 (0)