diff --git a/src/dmd/backend/cgcod.d b/src/dmd/backend/cgcod.d index 1d0bc86c89fe..f1f538c80dff 100644 --- a/src/dmd/backend/cgcod.d +++ b/src/dmd/backend/cgcod.d @@ -173,7 +173,7 @@ version (SCPP) allregs = ALLREGS; pass = PASSinitial; Alloca.init(); - anyiasm = 0; + anyiasm = false; if (config.ehmethod == EHmethod.EH_DWARF) { @@ -246,7 +246,7 @@ else version (SCPP) if (b.Belem) resetEcomsub(b.Belem); // reset all the Ecomsubs if (b.BC == BCasm) - anyiasm = 1; // we have inline assembler + anyiasm = true; // we have inline assembler if (b.BC == BCret || b.BC == BCretexp) nretblocks++; } diff --git a/src/dmd/backend/cgelem.d b/src/dmd/backend/cgelem.d index 63c289249faf..a739f03dbda0 100644 --- a/src/dmd/backend/cgelem.d +++ b/src/dmd/backend/cgelem.d @@ -859,7 +859,7 @@ L1: else if (e2.Eoper == OPneg) { e.EV.E2 = el_selecte1(e2); e.Eoper = OPmin; - again = 1; + again = true; return e; } /* Replace (-v + e) with (e + -v) */ @@ -902,7 +902,7 @@ L1: e.EV.E1.Ety = e1.Ety; } } - again = 1; + again = true; return e; } /* Replace (e + e) with (e * 2) */ @@ -911,7 +911,7 @@ L1: e.Eoper = OPmul; el_free(e2); e.EV.E2 = el_long(e1.Ety,2); - again = 1; + again = true; return e; } // Replace ((e11 + c) + e2) with ((e11 + e2) + c) @@ -999,7 +999,7 @@ private elem * elmul(elem *e, goal_t goal) e1.Eoper = OPmul; e.EV.E2 = el_bin(OPmul,tym,e1.EV.E2,e2); e1.EV.E2 = el_copytree(e2); - again = 1; + again = true; return e; } @@ -1008,7 +1008,7 @@ private elem * elmul(elem *e, goal_t goal) { e2.EV.Vullong *= cast(targ_ullong)1 << el_tolong(e1.EV.E2); e1.EV.E2.EV.Vullong = 0; - again = 1; + again = true; return e; } } @@ -1030,7 +1030,7 @@ private elem * elmul(elem *e, goal_t goal) e2.Ety = TYint; e.Eoper = (e.Eoper == OPmul) /* convert to shift left */ ? OPshl : OPshlass; - again = 1; + again = true; return e; } else if (el_allbits(e2,-1)) @@ -1048,7 +1048,7 @@ Lneg: ? OPneg : OPnegass; el_free(e.EV.E2); e.EV.E2 = null; - again = 1; + again = true; return e; } @@ -3023,7 +3023,7 @@ private elem * elind(elem *e, goal_t goal) e.Ety = tym; e.EV.E2 = el_una(OPind,tym,e.EV.E2); e.EV.E2.ET = t; - again = 1; + again = true; return e; default: @@ -3365,7 +3365,7 @@ elem * elstruct(elem *e, goal_t goal) if (e.Eoper == OPstreq) { e.Eoper = OPcomma; e = optelem(e,GOALvalue); - again = 1; + again = true; } else goto Ldefault; @@ -4534,7 +4534,7 @@ private elem * ellngsht(elem *e, goal_t goal) } e1.Ety = ty; e = el_selecte1(e); - again = 1; + again = true; return e; } break; diff --git a/src/dmd/backend/cod2.d b/src/dmd/backend/cod2.d index 08ca84fa09ff..5bfeb3e65dd5 100644 --- a/src/dmd/backend/cod2.d +++ b/src/dmd/backend/cod2.d @@ -557,7 +557,7 @@ else if (!rretregs) rretregs = mLSW; rretregs |= mCX; - codelem(cdb,e1,&rretregs,0); + codelem(cdb,e1,&rretregs,false); retregs &= ~rretregs; if (!(retregs & mLSW)) retregs |= mLSW & ~rretregs; @@ -566,7 +566,7 @@ else } else { // long + hptr - codelem(cdb,e1,&retregs,0); + codelem(cdb,e1,&retregs,false); rretregs = (mLSW | mCX) & ~retregs; if (!(rretregs & mLSW)) rretregs |= mLSW; diff --git a/src/dmd/backend/cod3.d b/src/dmd/backend/cod3.d index 45a6101bf902..e454f94dfb91 100644 --- a/src/dmd/backend/cod3.d +++ b/src/dmd/backend/cod3.d @@ -834,7 +834,7 @@ void outblkexitcode(ref CodeBuilder cdb, block *bl, ref int anyspill, const(char { // Swap bs1 and bs2 block *btmp; - jcond ^= 1; + jcond = !jcond; btmp = bs1; bs1 = bs2; bs2 = btmp; @@ -1376,7 +1376,7 @@ void doswitch(ref CodeBuilder cdb, block *b) if (n == 0) msw = ms; else if (msw != ms) - mswsame = 0; + mswsame = false; } else // REGSIZE == 4 { @@ -1384,7 +1384,7 @@ void doswitch(ref CodeBuilder cdb, block *b) if (n == 0) msw = ms; else if (msw != ms) - mswsame = 0; + mswsame = false; } } p -= ncases; diff --git a/src/dmd/dcast.d b/src/dmd/dcast.d index 3cfda5076d45..a2586356f340 100644 --- a/src/dmd/dcast.d +++ b/src/dmd/dcast.d @@ -335,6 +335,18 @@ MATCH implicitConvTo(Expression e, Type t) TY toty = t.toBasetype().ty; TY oldty = ty; + // DIP1015 - Stage 1 - Deprecation. Remove this code when feature is removed. + if (m == MATCH.nomatch && t.ty == Tbool) + e.deprecation("cannot implicitly convert expression `%s` of type `%s` to `%s`", + e.toChars(), e.type.toChars(), t.toChars()); + + // https://issues.dlang.org/show_bug.cgi?id=9999 + // DIP1015 - Stage 2 - Removal - Uncomment when feature is removed, and uncomment + // code in test/runnable/test10560.d + // @@@DEPRECATED_[version]@@@ + // if (m == MATCH.nomatch && t.ty == Tbool) + // return; + if (m == MATCH.nomatch && t.ty == Tenum) return; diff --git a/src/dmd/dinterpret.d b/src/dmd/dinterpret.d index db58b768de8a..df466676b116 100644 --- a/src/dmd/dinterpret.d +++ b/src/dmd/dinterpret.d @@ -384,7 +384,7 @@ struct CompiledCtfeFunction // Suppress the check in this case. if (global.gag && ccf.func) { - stop = 1; + stop = true; return; } .error(e.loc, "CTFE internal error: ErrorExp in `%s`\n", ccf.func ? ccf.func.loc.toChars() : ccf.callingloc.toChars()); diff --git a/src/dmd/doc.d b/src/dmd/doc.d index 0a7df87eddfa..b22caf4af175 100644 --- a/src/dmd/doc.d +++ b/src/dmd/doc.d @@ -2642,7 +2642,7 @@ private void highlightCode3(Scope* sc, OutBuffer* buf, const(char)* p, const(cha private void highlightCode2(Scope* sc, Dsymbols* a, OutBuffer* buf, size_t offset) { uint errorsave = global.errors; - scope Lexer lex = new Lexer(null, cast(char*)buf.data, 0, buf.offset - 1, 0, 1); + scope Lexer lex = new Lexer(null, cast(char*)buf.data, 0, buf.offset - 1, false, true); OutBuffer res; const(char)* lastp = cast(char*)buf.data; //printf("highlightCode2('%.*s')\n", buf.offset - 1, buf.data); diff --git a/src/dmd/dsymbolsem.d b/src/dmd/dsymbolsem.d index 09345310fa7c..d66616c138b4 100644 --- a/src/dmd/dsymbolsem.d +++ b/src/dmd/dsymbolsem.d @@ -1200,7 +1200,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor } else { - ne.onstack = 1; + ne.onstack = true; dsym.onstack = true; } } @@ -3264,7 +3264,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor else { //printf("\tintroducing function %s\n", toChars()); - funcdecl.introducing = 1; + funcdecl.introducing = true; if (cd.classKind == ClassKind.cpp && Target.reverseCppOverloads) { // with dmc, overloaded functions are grouped and in reverse order diff --git a/src/dmd/dtemplate.d b/src/dmd/dtemplate.d index 613737f62866..a6d39cca29b0 100644 --- a/src/dmd/dtemplate.d +++ b/src/dmd/dtemplate.d @@ -2177,7 +2177,7 @@ extern (C++) final class TemplateDeclaration : ScopeDsymbol } tf.next = tret; if (ad && ad.isStructDeclaration()) - tf.isref = 1; + tf.isref = true; //printf("tf = %s\n", tf.toChars()); } else @@ -6908,7 +6908,7 @@ extern (C++) class TemplateInstance : ScopeDsymbol if (semanticTiargs(loc, sc, tiargs, 0)) { // cache the result iff semantic analysis succeeded entirely - semantictiargsdone = 1; + semantictiargsdone = true; return true; } return false; diff --git a/src/dmd/errors.d b/src/dmd/errors.d index 1c9dd8ddae39..c018ef7a2bae 100644 --- a/src/dmd/errors.d +++ b/src/dmd/errors.d @@ -492,7 +492,7 @@ private void colorHighlightCode(OutBuffer* buf) ++nested; auto gaggedErrorsSave = global.startGagging(); - scope Lexer lex = new Lexer(null, cast(char*)buf.data, 0, buf.offset - 1, 0, 1); + scope Lexer lex = new Lexer(null, cast(char*)buf.data, 0, buf.offset - 1, false, true); OutBuffer res; const(char)* lastp = cast(char*)buf.data; //printf("colorHighlightCode('%.*s')\n", buf.offset - 1, buf.data); diff --git a/src/dmd/glue.d b/src/dmd/glue.d index 56d7bb78d8ca..74b4197f66eb 100644 --- a/src/dmd/glue.d +++ b/src/dmd/glue.d @@ -942,7 +942,7 @@ void FuncDeclaration_toObjFile(FuncDeclaration fd, bool multiobj) // Register return style cannot make nrvo. // Auto functions keep the nrvo_can flag up to here, // so we should eliminate it before entering backend. - fd.nrvo_can = 0; + fd.nrvo_can = false; } if (fd.vthis) diff --git a/src/dmd/hdrgen.d b/src/dmd/hdrgen.d index ef0fef36b18c..e28d8dd90337 100644 --- a/src/dmd/hdrgen.d +++ b/src/dmd/hdrgen.d @@ -68,7 +68,7 @@ enum TEST_EMIT_ALL = 0; extern (C++) void genhdrfile(Module m) { OutBuffer buf; - buf.doindent = 1; + buf.doindent = true; buf.printf("// D import file generated from '%s'", m.srcfile.toChars()); buf.writenl(); HdrGenState hgs; diff --git a/src/dmd/lexer.d b/src/dmd/lexer.d index cea93c999697..921647daff4c 100644 --- a/src/dmd/lexer.d +++ b/src/dmd/lexer.d @@ -146,7 +146,7 @@ unittest /* Not much here, just trying things out. */ string text = "int"; // We rely on the implicit null-terminator - scope Lexer lex1 = new Lexer(null, text.ptr, 0, text.length, 0, 0); + scope Lexer lex1 = new Lexer(null, text.ptr, 0, text.length, false, false); TOK tok; tok = lex1.nextToken(); //printf("tok == %s, %d, %d\n", Token::toChars(tok), tok, TOK.int32); @@ -181,7 +181,7 @@ unittest foreach (testcase; testcases) { - scope Lexer lex2 = new Lexer(null, testcase.ptr, 0, testcase.length-1, 0, 0); + scope Lexer lex2 = new Lexer(null, testcase.ptr, 0, testcase.length-1, false, false); TOK tok = lex2.nextToken(); size_t iterations = 1; while ((tok != TOK.endOfFile) && (iterations++ < testcase.length)) @@ -497,7 +497,7 @@ class Lexer : ErrorHandler Identifier id = Identifier.idPool(cast(char*)t.ptr, cast(uint)(p - t.ptr)); t.ident = id; t.value = cast(TOK)id.getValue(); - anyToken = 1; + anyToken = true; if (*t.ptr == '_') // if special identifier token { __gshared bool initdone = false; diff --git a/src/dmd/mars.d b/src/dmd/mars.d index fbbe363e3e49..04e99a829f2b 100644 --- a/src/dmd/mars.d +++ b/src/dmd/mars.d @@ -789,9 +789,9 @@ private int tryMain(size_t argc, const(char)** argv) foreach (mod; modules) { auto buf = OutBuffer(); - buf.doindent = 1; + buf.doindent = true; scope HdrGenState hgs; - hgs.fullDump = 1; + hgs.fullDump = true; scope PrettyPrintVisitor ppv = new PrettyPrintVisitor(&buf, &hgs); mod.accept(ppv); @@ -1555,7 +1555,7 @@ private bool parseCommandLine(const ref Strings arguments, const size_t argc, re { static if (TARGET.Linux || TARGET.OSX || TARGET.FreeBSD || TARGET.OpenBSD || TARGET.Solaris || TARGET.DragonFlyBSD) { - params.pic = 1; + params.pic = true; } else { diff --git a/src/dmd/mtype.d b/src/dmd/mtype.d index ac9655ff80cf..6f6e94a1a22d 100644 --- a/src/dmd/mtype.d +++ b/src/dmd/mtype.d @@ -2191,7 +2191,7 @@ extern (C++) abstract class Type : RootObject bool isBaseOf(Type t, int* poffset) { - return 0; // assume not + return false; // assume not } /******************************** diff --git a/src/dmd/objc.d b/src/dmd/objc.d index a812697ef941..74f8c7e83efa 100644 --- a/src/dmd/objc.d +++ b/src/dmd/objc.d @@ -418,7 +418,7 @@ extern(C++) private final class Supported : Objc { auto members = new Dsymbols(); members.push(classDeclaration); - return new ClassDeclaration(loc, Id.Class, metaBases, members, 0); + return new ClassDeclaration(loc, Id.Class, metaBases, members, false); } .setMetaclass!newMetaclass(classDeclaration); diff --git a/src/dmd/parse.d b/src/dmd/parse.d index 76936616d9b3..c8ed9bb7e3d1 100644 --- a/src/dmd/parse.d +++ b/src/dmd/parse.d @@ -1188,7 +1188,7 @@ final class Parser(AST) : Lexer { auto a2 = new AST.Dsymbols(); a2.push(v); - auto tempdecl = new AST.TemplateDeclaration(loc, ident, tpl, null, a2, 0); + auto tempdecl = new AST.TemplateDeclaration(loc, ident, tpl, null, a2, false); s = tempdecl; } a.push(s); @@ -4696,7 +4696,7 @@ final class Parser(AST) : Lexer { auto a2 = new AST.Dsymbols(); a2.push(s); - auto tempdecl = new AST.TemplateDeclaration(loc, ident, tpl, null, a2, 0); + auto tempdecl = new AST.TemplateDeclaration(loc, ident, tpl, null, a2, false); s = tempdecl; } if (setAlignment) diff --git a/src/dmd/semantic3.d b/src/dmd/semantic3.d index 06caddbb2714..33d64030da8c 100644 --- a/src/dmd/semantic3.d +++ b/src/dmd/semantic3.d @@ -559,12 +559,12 @@ private extern(C++) final class Semantic3Visitor : Visitor sc2.ctorflow.allocFieldinit(ad2.fields.dim); foreach (v; ad2.fields) { - v.ctorinit = 0; + v.ctorinit = false; } } if (!funcdecl.inferRetType && !Target.isReturnOnStack(f, funcdecl.needThis())) - funcdecl.nrvo_can = 0; + funcdecl.nrvo_can = false; bool inferRef = (f.isref && (funcdecl.storage_class & STC.auto_)); @@ -618,7 +618,7 @@ private extern(C++) final class Semantic3Visitor : Visitor funcdecl.storage_class &= ~STC.auto_; } if (!Target.isReturnOnStack(f, funcdecl.needThis())) - funcdecl.nrvo_can = 0; + funcdecl.nrvo_can = false; if (funcdecl.fbody.isErrorStatement()) { diff --git a/src/dmd/statementsem.d b/src/dmd/statementsem.d index 25c1b25588f6..eef325a03a42 100644 --- a/src/dmd/statementsem.d +++ b/src/dmd/statementsem.d @@ -3177,10 +3177,10 @@ else { // Function returns a reference if (!inferRef) - fd.nrvo_can = 0; + fd.nrvo_can = false; } else if (!v || v.isOut() || v.isRef()) - fd.nrvo_can = 0; + fd.nrvo_can = false; else if (fd.nrvo_var is null) { if (!v.isDataseg() && !v.isParameter() && v.toParent2() == fd) @@ -3189,18 +3189,18 @@ else fd.nrvo_var = v; } else - fd.nrvo_can = 0; + fd.nrvo_can = false; } else if (fd.nrvo_var != v) - fd.nrvo_can = 0; + fd.nrvo_can = false; } else //if (!exp.isLvalue()) // keep NRVO-ability - fd.nrvo_can = 0; + fd.nrvo_can = false; } else { // handle NRVO - fd.nrvo_can = 0; + fd.nrvo_can = false; // infer return type if (fd.inferRetType) diff --git a/test/compilable/test9999.d b/test/compilable/test9999.d new file mode 100644 index 000000000000..2ce866ffc95a --- /dev/null +++ b/test/compilable/test9999.d @@ -0,0 +1,14 @@ +// The purpose of this test is to ensure that the implementation of +// DIP1015 does not break the following conditionals + +void main() +{ + if(1) { } + if(0) { } + assert(1); + assert(0); + static assert(1); + while(0) { } + while(1) { } + for(;1;) { } +} diff --git a/test/fail_compilation/test9999.d b/test/fail_compilation/test9999.d new file mode 100644 index 000000000000..74233faede24 --- /dev/null +++ b/test/fail_compilation/test9999.d @@ -0,0 +1,44 @@ +/* +REQUIRED_ARGS: -de + +TEST_OUTPUT: +--- +fail_compilation/test9999.d(27): Deprecation: cannot implicitly convert expression `'\x00'` of type `char` to `bool` +fail_compilation/test9999.d(28): Deprecation: cannot implicitly convert expression `'\x01'` of type `char` to `bool` +fail_compilation/test9999.d(30): Deprecation: cannot implicitly convert expression `'\x00'` of type `wchar` to `bool` +fail_compilation/test9999.d(31): Deprecation: cannot implicitly convert expression `'\x01'` of type `wchar` to `bool` +fail_compilation/test9999.d(33): Deprecation: cannot implicitly convert expression `0` of type `int` to `bool` +fail_compilation/test9999.d(34): Deprecation: cannot implicitly convert expression `1` of type `int` to `bool` +fail_compilation/test9999.d(36): Deprecation: cannot implicitly convert expression `0u` of type `uint` to `bool` +fail_compilation/test9999.d(37): Deprecation: cannot implicitly convert expression `1u` of type `uint` to `bool` +fail_compilation/test9999.d(39): Deprecation: cannot implicitly convert expression `0L` of type `long` to `bool` +fail_compilation/test9999.d(40): Deprecation: cannot implicitly convert expression `1L` of type `long` to `bool` +fail_compilation/test9999.d(42): Deprecation: cannot implicitly convert expression `0LU` of type `ulong` to `bool` +fail_compilation/test9999.d(43): Deprecation: cannot implicitly convert expression `1LU` of type `ulong` to `bool` +--- +*/ + +// https://issues.dlang.org/show_bug.cgi?id=9999 + +void main() +{ + bool boolValue; + + boolValue = '\0'; + boolValue = '\1'; + + boolValue = '\u0000'; + boolValue = '\u0001'; + + boolValue = 0; + boolValue = 1; + + boolValue = 0u; + boolValue = 1u; + + boolValue = 0L; + boolValue = 1L; + + boolValue = 0UL; + boolValue = 1UL; +} diff --git a/test/fail_compilation/warn7444.d b/test/fail_compilation/warn7444.d index ec7d49c150b5..5afe89326b56 100644 --- a/test/fail_compilation/warn7444.d +++ b/test/fail_compilation/warn7444.d @@ -57,7 +57,7 @@ No warning void test10214() { bool[1] arr; - arr = 0; + arr = false; pragma(msg, "No warning"); } diff --git a/test/runnable/test10560.d b/test/runnable/test10560.d new file mode 100644 index 000000000000..7a75af10ce8a --- /dev/null +++ b/test/runnable/test10560.d @@ -0,0 +1,21 @@ +// https://issues.dlang.org/show_bug.cgi?id=10560 + +// After the deprecation period for DIP 1015 has expired, +// uncomment everything below. + +// int f(bool b) { return 1; } +// int f(int i) { return 2; } + +// enum E : int +// { +// a = 0, +// b = 1, +// c = 2, +// } + +void main() +{ + // assert(f(E.a) == 2); + // assert(f(E.b) == 2); + // assert(f(E.c) == 2); +}